Skip to content
Mastering Claude

Home / When things go wrong

When things go wrong7 minApplication

A stuck command

A shell command that stops responding is cut off with Ctrl+C without closing the session, and the delay that switches it to a background task is already fixed by Claude itself, not by a prefix you add by hand.

A shell command launched from Claude Code can stay frozen: no output, no end. The first move is Ctrl+C, which attempts to interrupt the operation in progress without closing the session. If that is not enough, closing the terminal and relaunching with claude --resume in the same folder recovers the entire conversation, only the stuck command itself is lost.

The delay is not a habit to add yourself

A common habit is to wrap every risky command in a timeout prefix typed by hand. That is not how the Bash tool built into Claude Code actually works. It already carries a timeout parameter that Claude itself chooses to add when it anticipates a long running command, with no action on your part. Two environment variables bound this behaviour: BASH_DEFAULT_TIMEOUT_MS sets the default delay applied to each command, BASH_MAX_TIMEOUT_MS sets the cap that Claude cannot exceed even if it asks for more.

# Two environment variables read by Claude Code
BASH_DEFAULT_TIMEOUT_MS=120000   # 2 minutes, default value
BASH_MAX_TIMEOUT_MS=600000       # 10 minutes, cap

The automatic switch to a background task

When a command reaches its delay without finishing, Claude Code does not stop it: it switches it to a background task on its own and carries on working while it runs. Three families of commands escape this automatic switch and remain blocking to the end: those that start with sleep, those that contain git, and compound commands the security parser cannot analyse, such as an expansion of the type ${PIPESTATUS[0]}. For a process you already know will be long, a development server or a build left running, it is better to explicitly request the run_in_background parameter rather than wait for the timeout to trigger.

# Simulates a long command, without changing anything on this machine
node -e "setTimeout(() => console.log('travail termine'), 5000)"
# Launched with run_in_background, it hands control back immediately
# and its output can be read later, without having blocked the conversation thread

The difference between the two situations rests on a single fact: the timeout protects against a command that will never finish, switching to a background task frees up the conversation while a command that will finish takes its time. Confusing the two makes a chat wait for nothing, or cuts off a command that was about to succeed.

This same recover-without-losing-anything logic reappears when it is the whole session that stalls rather than a single command, see loops, polluted context and restarting.

Figure 1

From a frozen command to resuming work

01
Command launched
Claude runs a shell command in the Bash tool, with a timeout already chosen for that call.
02
No more output
Nothing is displayed, the command looks frozen even though the delay has not yet been reached.
03
Ctrl+C
The user interrupts the operation in progress without leaving the Claude Code session.
04
Delay reached
If no one interrupts it, Claude Code switches the command to a background task as soon as BASH_DEFAULT_TIMEOUT_MS or BASH_MAX_TIMEOUT_MS is reached, except for sleep, git and unreadable compound commands.
05
Work resumed
The conversation carries on, the command's output can be read later without having blocked the thread.
The sequence shows the two possible outcomes for a command that stops responding: manual interruption with Ctrl+C, or the automatic switch to a background task once the Bash tool's delay is reached.
Figure 2

The two bounds on the Bash tool's timeout

2minutes
default delay applied to a command, variable BASH_DEFAULT_TIMEOUT_MS
code.claude.com/docs/en/tools-reference, 2026-09-02
10minutes
cap on the delay a command can reach, variable BASH_MAX_TIMEOUT_MS
code.claude.com/docs/en/tools-reference, 2026-09-02
These two values are read directly by Claude Code at startup and bound every call to the Bash tool, whether the default delay or the cap that Claude cannot exceed.
Calibrate it yourself

A developer launches a command from Claude Code that installs dependencies. After a minute, the screen still shows the same line, unmoved since it started. He presses Ctrl+C, the command line returns, and he relaunches the same command with the run_in_background parameter.

Write, in one sentence, what this situation establishes, and in one sentence what it does not establish.

What to remember
  • Ctrl+C interrupts a stuck command without closing the session, and claude --resume in the same folder recovers the conversation if the terminal has to be closed.
  • The timeout parameter of the Bash tool is chosen by Claude itself for each command, it is not a prefix the user types by hand.
  • BASH_DEFAULT_TIMEOUT_MS sets the default delay at two minutes, BASH_MAX_TIMEOUT_MS caps that delay at ten minutes.
  • Once the delay is exceeded, Claude Code switches the command to a background task instead of stopping it, except for sleep, git, and compound commands it cannot analyse.
  • run_in_background is requested before launching a process already known to be long, not after it has already blocked the conversation.
Do this now

Launch a command you already know will be long by explicitly asking Claude to switch it to a background task before it blocks the chat, rather than waiting until it looks frozen to step in.

Check the source

Every datable claim in this lesson links here to the public text behind it. A source that does not open proves nothing.