Fix Claude Code Bash timeouts and truncated output: BASH_DEFAULT_TIMEOUT_MS and bashOutputMaxChars

Claude Code Published:

Why Claude Code's Bash tool stops at 2 minutes or cuts long output, and how to tune it with BASH_DEFAULT_TIMEOUT_MS, BASH_MAX_TIMEOUT_MS, and bashOutputMaxChars.

Verified on Sep 10, 2026 These tools change quickly. Please also check the latest official documentation.
Contents
  1. How timeouts work
  2. The output limit
  3. Putting it in settings.json
  4. When the working directory drifts
  5. Summary

Ask Claude to run the test suite or a build, and after two minutes it reports a timeout without seeing the result. Or a long log gets cut and Claude misses the one error that mattered. Both come from default limits on the Bash tool.

In short: tune timeouts with BASH_DEFAULT_TIMEOUT_MS and BASH_MAX_TIMEOUT_MS, and the output limit with bashOutputMaxChars (or BASH_MAX_OUTPUT_LENGTH). Put them under env in settings.json so you do not have to set them per launch.

KEY POINT

What you will learn

  • The two timeout variables and how they relate
  • The output limit setting and variable, and which one wins
  • Writing them into settings.json, and fixing the working directory drifting after cd

How timeouts work

The Bash tool has a default timeout and a ceiling on what the model may request.

VariableDefaultMeaning
BASH_DEFAULT_TIMEOUT_MS120000 (2 min)used when the model does not specify a timeout
BASH_MAX_TIMEOUT_MS600000 (10 min)the maximum the model may set

The effective ceiling is the larger of BASH_MAX_TIMEOUT_MS and BASH_DEFAULT_TIMEOUT_MS, so raising the default past 10 minutes raises the ceiling with it.

These numeric variables also accept scientific notation such as 2e3 and digit separators such as 64_000.

用語解説

Milliseconds: all of these are in ms. Five minutes is 300000, thirty minutes is 1800000. Getting the unit wrong produces commands that time out instantly.

The output limit

When a command succeeds, Claude reads back at most a fixed number of characters. Past that, Claude Code saves the output to a file and hands Claude a short preview plus the path. Claude can read the file, but it does not automatically read all of it.

SettingDefaultNotes
bashOutputMaxChars (settings.json)30,000 chars when unsetclamped to 4000128000; requires v2.1.261 or later
BASH_MAX_OUTPUT_LENGTH (env var)30000maximum 150000; ignored once bashOutputMaxChars is set

Raise bashOutputMaxChars when verbose builds or full test logs routinely overflow and you want Claude to read them inline.

{
  "bashOutputMaxChars": 100000
}

Putting it in settings.json

Environment variables under the env key apply to every session and its subprocesses no matter how claude was launched, and they override a variable of the same name set in your shell.

{
  "env": {
    "BASH_DEFAULT_TIMEOUT_MS": "300000",
    "BASH_MAX_TIMEOUT_MS": "1800000"
  },
  "bashOutputMaxChars": 100000
}

Use .claude/settings.json for team-wide values and ~/.claude/settings.json or .claude/settings.local.json for your own. The settings layers are described in Designing permissions in settings.json.

Consider background execution before raising timeouts

A dev server or a watcher never finishes, so a longer timeout only delays the failure. Have Claude run such commands in the background and read their logs when needed. Reserve longer timeouts for commands that do finish but take a while, such as tests and builds.

When the working directory drifts

After a command containing cd, later commands may run in the wrong directory and fail. Set CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR to return to the original working directory after each Bash or PowerShell command in the main session.

{
  "env": {
    "CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR": "1"
  }
}

Longer output also costs context. The higher the limit, the more tokens a single command can consume, so from the perspective of Managing context in Claude Code it is best to raise it only when needed.

Summary

  • Default timeout is 2 minutes (BASH_DEFAULT_TIMEOUT_MS); the model may request up to 10 minutes (BASH_MAX_TIMEOUT_MS); the ceiling is the larger of the two
  • Output is capped at 30,000 characters by default, with overflow saved to a file. bashOutputMaxChars (4,000–128,000) adjusts it and overrides BASH_MAX_OUTPUT_LENGTH
  • Values under env in settings.json beat the shell and apply to every session
  • Run never-ending commands in the background instead of extending timeouts
  • Use CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR if cd leaves later commands in the wrong directory

FAQ

What is the default Bash tool timeout?
120000 milliseconds, or 2 minutes. Change it with BASH_DEFAULT_TIMEOUT_MS.
Can the model pick a longer timeout itself?
Yes, up to a ceiling: the larger of BASH_MAX_TIMEOUT_MS (default 10 minutes) and BASH_DEFAULT_TIMEOUT_MS.
Why does long command output get cut off?
Claude receives at most a fixed number of characters inline, 30,000 by default. The rest is saved to a file and Claude gets a preview plus the file path.

Primary sources

This article was drafted by AI from official documentation and reviewed by the site operator before publishing. Found a mistake? Let us know via the contact page.