Published on , Aurélien Vandaële

How to set the command timeout in Claude Code: the defaults, and my tests that never finished

In Claude Code, a command run by the Bash tool gets 2 minutes by default. Claude can ask for more on a given command, up to 10 minutes. Both values are changed with BASH_DEFAULT_TIMEOUT_MS and BASH_MAX_TIMEOUT_MS, in milliseconds, in the env block of settings.json. The surprising part: when the timeout hits, the command is not killed, it moves to the background. For my tests, I don't rely on that timeout: my check script has its own, and it names what is stuck.

The default timeouts, and where to change them

Every Bash command runs under a timeout. When Claude expects a command to be long, it passes a timeout parameter with the call itself. Without that parameter, the default applies. The documentation sets two bounds:

  • BASH_DEFAULT_TIMEOUT_MS: the timeout when Claude asks for none. 120,000, or 2 minutes.
  • BASH_MAX_TIMEOUT_MS: the ceiling on what Claude can ask for. 600,000, or 10 minutes. The effective ceiling is the larger of the two values.

To change them, the documentation suggests the env block of a settings file. In ~/.claude/settings.json, the rule applies to all your sessions:

{
  "env": {
    "BASH_DEFAULT_TIMEOUT_MS": "300000",
    "BASH_MAX_TIMEOUT_MS": "1200000"
  }
}

Two other timeouts share the name but not the units. A hook's timeout is in seconds, 600 by default for a command hook; I still write it on my end-of-session hook, covered in the article on hooks. For MCP servers, MCP_TIMEOUT sets startup (30 seconds by default) and MCP_TOOL_TIMEOUT sets tool execution.

When the timeout hits, the command moves to the background

This is the part nobody guesses. When a command reaches its timeout without finishing, Claude Code doesn't stop it: it moves it to the background and says so in the result, with a message like Command did not complete within its 120s timeout and was moved to the background, followed by the task ID and the file its output keeps being written to. Exception: a command that starts with sleep.

To make a command really stop at its timeout, turn off automatic backgrounding with CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1. To see and stop what is running, /tasks lists background tasks, and Ctrl+B lets you send a running command to the background yourself.

In the main session, it's handy: Claude keeps working while a long build finishes. In a subagent, it's a trap. The documentation states that a command started by a foreground subagent stops when that subagent finishes, and that in an interactive session, a background subagent's command can move after 3 minutes, even before its timeout.

I paid for that trap in August: four agents started a command in the background, then ended their turn announcing they were waiting for the result. For a subagent, ending its turn means being done. Nothing had been produced, about 600,000 tokens lost. Since then, every agent file in my chain opens with the same rule: everything in the foreground, never wait for a notification, and the last message is the whole answer.

My own timeout: naming what is stuck

A timeout that cuts a command doesn't say why it wasn't finishing. For me, it is almost always tests. So my agents never run the suite directly: they go through a small script that reads the command and its deadline from .claude/pipeline.json, one per repository.

{
  "check": "scripts/pipeline-check.sh",
  "checkFast": "scripts/pipeline-check.sh --fast",
  "deadline": 600
}

The script starts the command in its own process group. At the deadline, it kills the whole group, otherwise Jest or Vitest workers stay alive behind it, then prints a line that leaves no doubt, with the last lines of output, and exits with code 124:

HUNG: 'scripts/pipeline-check.sh' gave no result after 600s. Last lines:

This script exists because of a suite that ran forever: a mocked value recreated on every call re-ran an effect on every render, and the hang was taken for a slow machine for five minutes. The full story is in the React Native article.

One rule came out of it, written into the command that sets a repository up: the outer deadline must exceed the sum of the inner ones. My React Native script gives Jest 300 seconds, so the pipeline.json deadline is 600. The other way round, the outer deadline cuts first, and the inner script's HUNG: line, the one that names the guilty suite, is never printed.

What went wrong, and what is still to fix

  • A test too close to its timeout. Vitest gives each test 5 seconds. A pure computation test passed alone but failed at 5,000 ms during the full check, because other sessions were loading the machine (load average around 9). It wasn't a regression. Since then, the agent that writes tests sets an explicit timeout on CPU-heavy cases, and a failure of that kind is rerun once before being treated as blocking.
  • Four full suites at once. Four agents in parallel each ran about 1,000 tests. Load average around 7, and every timeout became meaningless. The rule became: one agent at a time. That is also what lets that agent run the full check before each commit.
  • The outermost level forgotten. My rule on nested deadlines stops at the script. Above it sits Claude Code's own timeout. My eight repositories set up with the chain have a deadline of 600 seconds or more, up to 1,500 for the slowest: at the 10-minute ceiling, or above it. If Claude doesn't ask for more time, the command moves to the background after 2 minutes, before my script can print HUNG:, and the agent receives a backgrounding notice that its rules tell it not to wait for. Nothing in my ledgers shows it has happened yet, but nothing prevents it. The fix isn't done yet: raise both variables in my global settings, above the longest deadline, so that my script always decides first.

How to get started

  • Time your full check. If it takes more than 2 minutes, Claude has to remember to ask for more; if it takes more than 10, raise BASH_MAX_TIMEOUT_MS in the env block.
  • Give your tests their own deadline, shorter than Claude Code's, and make it print what didn't answer. A timeout that cuts silently leaves you searching in the wrong place.
  • In every subagent file, write the foreground rule: no background command, no waiting, the last message is the answer. It's the rule that saved me the most.
  • Read the message when a command moves. moved to the background means the command is still running, not that it failed.

The same principle of third-party checking applies to what an agent returns: a “done” report is not proof. I explain it in the article on verifying a subagent's work.

Article written with the help of AI, from my daily practice and my projects.

The whole notebook