Implement a default timeout and provide feedback for shell commands
What feature would you like to see?
I would like to request the implementation of a default timeout for all shell commands executed by the agent. When a command runs longer than this timeout, it should be terminated, and both the user and the agent should receive feedback that a timeout occurred.
Currently, if the agent runs a shell command that hangs, crashes in a weird way, or is simply long-running without the model specifying a timeout_ms, the CLI appears to freeze. The user is left with a "Working..." spinner indefinitely, with no indication of what's happening or a clear way to proceed besides killing the entire process.
A default timeout (e.g., 60 or 120 seconds) would act as a crucial safety net, ensuring that the agent can recover from stuck processes and the user is always kept in the loop.
When a timeout is hit:
- The child process should be terminated.
- A history event should be displayed in the TUI, indicating that the command timed out (e.g.,
• Ran command [timed out after 60s]). - An error/timeout result should be sent back to the model so it can attempt to recover, try a different approach, or inform the user.
Additional information
This feature is standard in other agentic coding tools. For example, Claude Code has a BASH_DEFAULT_TIMEOUT_MS environment variable that provides this exact safety net. Its absence in Codex CLI is a noticeable gap in user experience and agent robustness.
Current Experience with Codex CLI:
- I ask the agent to perform a task, for example, "install dependencies for this project."
- The agent decides to run
npm install. - The command hangs due to a network issue or a problematic package script.
- The Codex TUI shows the spinner and "Working..." indefinitely. I have no idea if it's making progress or if it's completely stuck. My only recourse is to
Ctrl+Cout of the entire session.
Desired Experience:
- Same prompt as above.
- The agent runs
npm install. - The command hangs.
- After the default timeout (e.g., 120 seconds), the command is killed.
- The TUI displays a message like:
• Ran npm install [timed out after 120s]. - The agent receives an error result for its tool call and can then reason about the failure, perhaps trying
npm install --verboseor notifying me of the issue.
While the shell tool does have a timeout_ms parameter, the model does not and cannot be expected to proactively add a timeout to every single command it runs. A global default timeout would make the agent much more resilient and provide a significantly better user experience by preventing indefinite hangs.
8 Comments
Potential duplicates detected:
Powered by Codex Action
Here is a potential high-level plan for implementing a default timeout for shell commands.
Objective
Introduce a configurable, default timeout for all shell commands executed by the agent to prevent indefinite hangs. If a command exceeds this timeout, it will be terminated, and clear feedback will be provided to both the user (in the TUI) and the agent (as a tool result) to improve agent robustness and enable graceful recovery. The model-specified
timeout_msparameter will always take precedence when provided.---
High-Level Plan
The implementation can be broken down into four main phases: Configuration, Core Execution Logic, TUI Feedback, and Agent Feedback.
Phase 1: Configuration Layer
This phase introduces a new, user-configurable setting for the default timeout.
shell_default_timeout_ms, to the TOML configuration struct (ConfigTomlincodex-rs/core/src/config_types.rs).ConfigStruct: Propagate this new setting into the coreConfigstruct (codex-rs/core/src/config.rs). If the value is not present inconfig.toml, a sensible hardcoded default (e.g., 120,000 ms) will be applied.timeout_msvalue explicitly provided by the model in theshelltool call.shell_default_timeout_msvalue from the user'sconfig.toml.Phase 2: Core Execution Logic
This phase integrates the new configuration into the command execution pipeline.
ShellHandler: The logic will be centralized within theShellHandler(codex-rs/core/src/tools/handlers/shell.rs), which is responsible for converting the model's tool call into theExecParamsstruct used for execution.ExecParams, the handler will check if the model provided atimeout_ms. If it did not, the handler will retrieve theshell_default_timeout_msfrom theConfigand populate thetimeout_msfield inExecParams.ExecParamsalways contains a timeout value, allowing us to leverage the existing robust timeout logic incodex-rs/core/src/exec.rs. This logic already usestokio::time::timeoutfor process monitoring and termination, and it correctly returns aSandboxErr::Timeouterror, which we will propagate.Phase 3: Data Propagation and TUI Feedback
This phase ensures the user receives clear visual feedback when a command times out.
ExecToolCallOutputstruct already contains atimed_out: boolflag. The error handling path forSandboxErr::Timeoutwill be updated to ensure this flag is set totrueon the resultingExecToolCallOutput. The process exit code will also be set to a conventional timeout value (e.g., 124).ExecCellRenderer: The UI component responsible for rendering command history (ExecCellincodex-rs/tui/src/exec_cell/) will be modified to check thetimed_outflag of theCommandOutput.timed_outis true, theExecCellwill display a clear, distinct message in its header, such as[timed out after 120s], instead of the standard success (✓) or failure (✗) indicators. This provides immediate and unambiguous feedback to the user in the TUI.Phase 4: Agent Feedback
This phase ensures the agent is informed of the timeout, enabling it to self-correct.
format_exec_output_apply_patchincodex-rs/core/src/tools/mod.rs) will be updated.timed_outflag is true, the formatter will prepend a clear, natural-language error message to any partialstdout/stderrthat was captured (e.g.,"Command timed out after 120 seconds."). This gives the model explicit context about the failure, allowing it to reason about the next best step, such as retrying with a longer timeout, attempting an alternative command, or notifying the user.---
Testing Strategy
ShellHandler.sleep 5) without a model-specified timeout. Assert that the process is terminated by the new default timeout and that the returnedExecToolCallOutputhastimed_outset totrueand the correct exit code.ExecCellto confirm that the[timed out after ...]message is rendered correctly in the TUI history.Indeed, I am seeing a lot of shell function_call to
rgwheregpt5-codexchooses atimeout_msof1000, which is not enough for some searches.I'd like shell command timeouts to be more visible / configurable too, for opposite reasons. I use Codex CLI with Terraform often which it works well with (provided I watch it carefully) but it often allows Terraform commands to timeout prematurely leaving lingering locks or corrupted/incomplete Terraform state and despite my best efforts to warn against that in the AGENTS.md it doesn't reliably adhere to my instructions.
I'd also suggest for running shell commands a TUI timeout progress bar with some hotkey shortcuts to extend or cancel the command early would also be great. Ultimately making a shell command timeout configurable with optional overrides for specific commands is what I'd like.
As Codex might also be used for build processes, deployments or IO intensive other work we should be able to define the timeout treshold in config.toml and/or env var please.
please I need to configure timeout
Status Update (Feb 2026)
After reviewing the current codebase, this issue is partially resolved. Here's a breakdown:
What's been implemented
DEFAULT_EXEC_COMMAND_TIMEOUT_MSprovides a fallback when the model doesn't specifytimeout_ms. User-initiated shell commands use a 1-hour ceiling (PR #7025).build_content_with_timeout()prepends a clear timeout message to the tool output, enabling the model to reason about and recover from the failure.What's still missing
The core ask from this issue and multiple commenters remains unresolved: user-configurable shell command timeouts.
shell_default_timeout_ms(or equivalent) field inconfig.toml.BASH_DEFAULT_TIMEOUT_MS.ConfigTomlhasbackground_terminal_timeoutfor background terminals andtool_timeout_secfor MCP tools, but nothing for regular agent-initiated shell commands.timeout_msvalues (e.g., 1000ms forrgsearches, as noted by @insilications), and users have no way to set a floor or default.Recommendation
Keep this issue open until a user-facing configuration option is added (e.g.,
shell_default_timeout_msinconfig.tomland/or an env var), with the precedence chain: model-specifiedtimeout_ms> user config > hardcoded default.1000ms for rg might be low if your codebase is huge you can have rg searches going on for 10 minutes