Claude Code “Command Timed Out After 2m”: How to Raise the Bash Timeout

Claude Code “Command Timed Out After 2m”: How to Raise the Bash Timeout

If Claude Code shows Command timed out after 2m 0s, the command hit the default Claude Code Bash timeout of two minutes and was stopped. To raise it, set BASH_DEFAULT_TIMEOUT_MS (in milliseconds) in the env block of .claude/settings.json, for example "300000" for five minutes, and start a new session.

If your command needs more than ten minutes, raise BASH_MAX_TIMEOUT_MS too, because that is the ceiling for any single foreground command. For dev servers, watchers and very long builds, the better fix is to run the command in the background so Claude keeps working while it runs.

In recent versions you usually only see the hard timeout error when background tasks are turned off, because Claude Code normally moves a slow command to the background at the two-minute mark instead of killing it. Below we reproduce both behaviors for real, then fix the error and show the test finishing.

Browse all our Claude Code tutorials for more fixes and how-tos.

Tested with Claude Code v2.1.332 on macOS on November 27, 2026. Every run used a throwaway demo folder called test-runner with one script, slow-test.sh, that prints a line, sleeps for 150 seconds and then prints “All 12 tests passed”.

Quick Summary

What you seeWhat it meansFix
Command timed out after 2m 0s with Exit code 143The command was killed at the default timeoutRaise BASH_DEFAULT_TIMEOUT_MS
Running in the background after two minutesThe command was moved, not killedNothing to fix; Claude gets the result later
Blocked: sleep 150 followed by: ...A long foreground sleep is refusedLet Claude run it in the background
Still timing out at ten minutesYou hit the foreground ceilingRaise BASH_MAX_TIMEOUT_MS as well
Background job stopped in claude -p or CIThe background time limit for unattended runsRaise the same two variables above 30 minutes or 2 hours

Why Claude Code Has a Bash Timeout

Every command Claude runs through its Bash tool runs under a timer. Without one, a command that waits for input, a server that never exits or a stuck network call would freeze the whole session. The timer keeps Claude moving and tells it when something took too long.

According to Anthropic’s tools reference, Claude manages the timeout itself. When it expects a command to be slow, it passes a longer timeout with that one call. You never type a per-command timeout yourself; instead, you control the defaults with two environment variables.

VariableWhat it controlsDefault
BASH_DEFAULT_TIMEOUT_MSThe timeout when Claude passes none120000 (2 minutes)
BASH_MAX_TIMEOUT_MSThe highest timeout Claude may ask for600000 (10 minutes)

The effective ceiling is the larger of the two values, so setting only the default above ten minutes also lifts the ceiling. Both variables apply to the PowerShell tool on Windows too, so the fix is the same there. We tested on macOS; the Windows and Linux steps follow Anthropic’s official instructions.

Claude Code environment variables docs with BASH_DEFAULT_TIMEOUT_MS and BASH_MAX_TIMEOUT_MS rows highlighted
The two timeout variables in Anthropic’s environment variables reference.

What Happens When a Command Hits Two Minutes

The error in the title is not what most people see today. Since Claude Code learned to move slow commands to the background, a foreground command that reaches its timeout keeps running as a background task instead of being killed. Claude is told when it finishes and reads the output then.

There are two exceptions in the docs. If background tasks are turned off, with CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1 or by running in bare mode (claude --bare), the command stops at the timeout and you get the error. A command that starts with sleep is also stopped rather than moved.

Flow diagram of what Claude Code does when a Bash command reaches its two-minute timeout
Our diagram of the three outcomes when a Bash command reaches its timeout.
Claude Code tools reference section explaining that foreground commands move to the background at their timeout
The docs section on foreground commands that move to the background.

Reproducing the Default Behavior

We started with no timeout settings at all. We asked Claude to run ./slow-test.sh in the foreground and not to pass a timeout, so the two-minute default applied.

At 120 seconds the command was not killed. The screen switched to “Running in the background”, and Claude explained that the harness moved it after the default timeout. About 30 seconds later a notice said the background command completed with exit code 0, and Claude reported that all 12 tests passed.

Claude Code moving slow-test.sh to the background after the 120 second timeout and reporting it finished later
With default settings, the slow script moved to the background at 120 seconds and finished on its own.

So if you see “moved to the background”, nothing is broken. You can list or stop the job with /tasks, and our guide on how to stop background tasks covers that part in detail.

The sleep case

We also asked Claude to run sleep 150 && echo done in the foreground. In our session, Claude Code blocked it right away with a message saying a long foreground sleep isn’t allowed and pointing to run_in_background or the Monitor tool instead. Claude then ran the same command in the background, and it completed normally.

Claude Code blocking a foreground sleep 150 command and suggesting run_in_background
A long foreground sleep was blocked, and Claude switched to a background run.

That matters if you are trying to test timeouts yourself. A bare sleep is a poor test command; wrap the wait inside a script, as we did, to see the real timeout behavior.

Reproducing the “Command Timed Out After 2m” Error

To get the hard error, we turned off background tasks for the demo project. We added this to .claude/settings.json in the demo folder:

{
  "env": {
    "CLAUDE_CODE_DISABLE_BACKGROUND_TASKS": "1"
  }
}

Then we started a fresh session and sent the same request: run ./slow-test.sh in one foreground call with no timeout. The command ran normally for the first minute.

Project settings turning off background tasks, with slow-test.sh still running after one minute
Background tasks turned off in project settings, and the test still running at one minute.

At exactly two minutes the tool call failed with Error: Exit code 143 and Command timed out after 2m 0s. Exit code 143 means the process was ended with SIGTERM, which is how the timeout stops it. Only the first line of output, “Running 12 tests…”, made it back.

Claude Code showing Error Exit code 143 Command timed out after 2m 0s for slow-test.sh
The real error: the script was killed at the two-minute default.

Claude’s reply was helpful here. It offered to rerun with a longer timeout (up to ten minutes in the foreground), to run it in the background, or to read the script first to see why it was slow.

How to Raise the Claude Code Bash Timeout

There are four fixes. Pick the one that matches how long your command really runs.

Fix 1: Raise the default in project settings

This is the fix we tested. Add BASH_DEFAULT_TIMEOUT_MS to the env block of .claude/settings.json in your project. Values are strings in milliseconds. We used five minutes for the default and twenty minutes for the ceiling:

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

We kept background tasks turned off, started a new session and sent the exact same request. This time the script ran for its full 150 seconds in the foreground and printed “All 12 tests passed”, with no error and no move to the background.

Claude Code settings with BASH_DEFAULT_TIMEOUT_MS 300000 and slow-test.sh finishing in the foreground
With the default raised to five minutes, the same script finished in the foreground.

Use .claude/settings.json when the whole team runs the same slow suite, since it can be committed. Use .claude/settings.local.json for a personal value in one project, or ~/.claude/settings.json to apply it to every project. Our settings guide explains how these scopes stack.

Fix 2: Set it in your shell for one session

The environment variables docs also let you set the variables in your shell before you start Claude Code. That suits a one-off long job:

export BASH_DEFAULT_TIMEOUT_MS=300000
claude

On Windows PowerShell, the same idea is $env:BASH_DEFAULT_TIMEOUT_MS = "300000" before running claude. The value only lasts for that shell window. For the full list of variables, see our environment variables guide.

Fix 3: Ask Claude for a longer timeout on one run

If a command is slow only now and then, you don’t need to change any settings. Tell Claude something like “run the test suite with an 8-minute timeout”. Per the docs, Claude passes that timeout with the call, as long as it stays under the ceiling, which is ten minutes unless you raised BASH_MAX_TIMEOUT_MS.

Fix 4: Run it in the background

For dev servers, file watchers and builds that take a long time, a bigger timeout is the wrong tool. Ask Claude to “run it in the background”, or press Ctrl+B while a command is running to move it there. Claude keeps working and is told when the job finishes, and /tasks lists or stops running jobs.

Diagram showing which Claude Code timeout fix to use based on how long a command takes
Our quick guide to picking a timeout fix.

Timeouts in claude -p, CI and Cloud Sessions

Unattended runs add one more limit. In claude -p, Agent SDK apps, CI jobs and cloud sessions, background commands also have a time limit. Local sessions in a terminal, the desktop app or VS Code have none.

A command Claude starts in the background gets 30 minutes by default and at most 2 hours. In a -p run whose prompt you pass as plain text, the default drops to 10 minutes.

When the limit hits, you see Background command "<description>" was stopped after reaching its background time limit.

Set BASH_DEFAULT_TIMEOUT_MS above 1800000 to replace the 30-minute default, and set BASH_MAX_TIMEOUT_MS above 7200000 to lift the 2-hour maximum.

Lower values never shorten a limit. Our headless mode guide covers -p runs in more depth.

Two minutes is the default, not a hard wall. Raise it for slow tests, and use the background for anything that never really ends.

Try It Yourself

Make a new empty folder, add a script that prints a line, waits 150 seconds and prints “done”, and make it executable. Start Claude Code there and paste this prompt:

Run ./slow-test.sh in one foreground Bash call with no timeout parameter,
and tell me what happened.

With default settings you should see it move to the background at two minutes. Then add the env block from Fix 1 to .claude/settings.json, start a new session, send the same prompt, and watch it finish in the foreground.

Common Mistakes

  • Writing seconds instead of milliseconds. 300 is a third of a second, not five minutes; use 300000.
  • Raising only BASH_MAX_TIMEOUT_MS. That changes the ceiling Claude may ask for, not the timeout it uses when it passes none.
  • Putting the variables at the top level of settings.json instead of inside "env": { }.
  • Editing the file and testing in the same old session. We started a fresh session after each change, and that is the safe way to check it.
  • Testing with a bare sleep command, which is blocked or stopped instead of showing the normal timeout path.
  • Raising the timeout to an hour for a dev server. A server never exits, so it belongs in the background.

Pro Tips

  • Commit the timeout in .claude/settings.json when your test suite is slow for everyone, so teammates never meet the error.
  • Pick a timeout a little above your slowest real run. A huge value hides commands that are truly stuck.
  • If a command keeps timing out, ask Claude to read it first. Our test showed Claude offering exactly that, and the real cause is often a prompt waiting for input.
  • Long output is a separate limit. BASH_MAX_OUTPUT_LENGTH and the bashOutputMaxChars setting control how much output Claude reads back, not how long a command runs.
  • Want a ping when a long job ends? See how to get a finish notification.

Cheat Sheet

Claude Code Bash timeout cheat sheet with variables, where to set them, background commands and error messages
Everything from this guide on one card.

Similar-looking errors have different fixes. “Request timed out” comes from the API connection, which our guide to API_TIMEOUT_MS covers, and slow MCP servers have their own MCP timeout fix. For other messages, see our list of common Claude Code errors, and if Claude seems to stop for other reasons, read why Claude Code keeps stopping.

Frequently Asked Questions

What is the default Bash timeout in Claude Code?

Two minutes (120000 milliseconds) when Claude passes no timeout. The most Claude can ask for on one foreground command is ten minutes (600000) by default.

What is the maximum Bash timeout I can set?

The docs give no fixed upper value for BASH_MAX_TIMEOUT_MS. We tested 20 minutes as the ceiling. For anything that long, a background run is usually the better choice.

Why does my command move to the background instead of timing out?

That is the normal behavior in current versions. At its timeout, a foreground command moves to the background and keeps running, unless background tasks are off or the command starts with sleep.

What does exit code 143 mean?

The process got SIGTERM. In our test it appeared together with “Command timed out after 2m 0s”, which means the timeout stopped it.

Does this work on Windows?

Yes. Per the docs, the PowerShell tool follows the same timeout rules and reads the same two variables. We tested on macOS only.

Conclusion

The Claude Code Bash timeout is two minutes by default, and when a command is killed you see “Command timed out after 2m 0s” with exit code 143. In our tests, raising BASH_DEFAULT_TIMEOUT_MS to five minutes in .claude/settings.json let the same slow script finish in the foreground, while default settings simply moved it to the background. Raise BASH_MAX_TIMEOUT_MS for anything past ten minutes, keep servers and watchers in the background, and check Anthropic’s settings docs for where each file lives. For more on Claude itself, visit our Claude AI page.

Newsletter

New AI tools in your inbox

The best new tools and the AI news that matters, in one short email. Unsubscribe any time.

Free · No spam · Unsubscribe any time

✓ Looks like you’re subscribed

Loading Google’s sign-up form…

Looks like you’re already subscribed

Thanks for reading! New AI tools and the AI news that matters will land in your inbox.

Not subscribed yet? Refresh the page to load the sign-up form.

The sign-up form couldn’t load. If you use an ad or content blocker, allow news.google.com and reload the page.

Free instant check before you pay. Takes a few seconds.

Scroll to Top