Bash tool runs shell commands and returns their output. It is Claude Code’s primary mechanism for interacting with your system: running tests, invoking build tools, calling CLIs, managing git, and anything else that requires a terminal.
Claude Code prefers dedicated tools (
Read, Edit, Write, Glob, Grep) over equivalent Bash commands. Use Bash for tasks that don’t have a dedicated tool: build systems, package managers, git operations, running tests, starting servers, etc.Parameters
The shell command to execute. The working directory persists between commands, but shell state (environment variables, functions, aliases) does not — each invocation starts from a fresh shell initialized from your profile.
Optional timeout in milliseconds. Maximum is 600,000 ms (10 minutes). Default is 120,000 ms (2 minutes). If the command exceeds the timeout, it is automatically moved to the background.
A short, plain-language description of what the command does. Shown in the UI and used in permission prompts. Keep it concise (5–10 words for simple commands; a sentence for complex pipelines).Examples:
ls→"List files in current directory"git status→"Show working tree status"find . -name "*.tmp" -exec rm {} \;→"Find and delete all .tmp files recursively"
When
true, the command is launched in the background and control returns immediately. Claude Code will notify you when the command completes. The output can be read later using the Read tool with the task output path.Do not use & at the end of the command when using this parameter — they serve the same purpose.When
true, bypasses sandbox restrictions for this command. Only set this when you have confirmed that a sandbox restriction is causing a specific failure. Each sandboxed command is evaluated independently — a previous dangerouslyDisableSandbox: true call does not carry over.Output
Standard output of the command. Stderr is merged into stdout.
Shell reset messages or other out-of-band output. Usually empty.
Whether the command was aborted before completion.
Task ID if the command is running in the background. Use to track or stop the task.
Semantic interpretation of non-zero exit codes that have special meaning for specific commands.
Set to
true for commands that produce no stdout on success (e.g., mv, cp, mkdir).Path to the full output file when output was too large to return inline. Read this file with the
Read tool.Security and sandbox mode
When sandbox mode is enabled (the default in many environments), commands run inside a sandbox that restricts:- Filesystem writes — only allowed directories can be written to
- Filesystem reads — certain paths may be blocked
- Network access — only allowed hosts can be contacted
dangerouslyDisableSandbox: true to confirm, but prefer adjusting your sandbox configuration via /sandbox rather than permanently disabling it.
Temporary files should always use $TMPDIR rather than /tmp directly. In sandbox mode, $TMPDIR is set to a sandbox-writable location automatically.
Using $TMPDIR for temporary files
Background execution
Userun_in_background: true for long-running commands when you don’t need the result immediately:
- Development servers (
npm run dev,python -m http.server) - Build processes that take more than a few seconds
- Commands you want to run in parallel with other work
Start a dev server in the background
If a blocking command runs for more than 15 seconds in assistant mode, Claude Code may automatically move it to the background to keep the session responsive. The command continues running — no state is lost.
Stopping background tasks
Background tasks have abackgroundTaskId. You can stop them using the TaskStop tool with that ID.
Timeout handling
The default timeout is 2 minutes. For long-running operations, set an explicit timeout:Run tests with a 5-minute timeout
run_in_background: true, it is automatically moved to the background (when background tasks are enabled). The output is written to a file that can be read with the Read tool.
Examples
Install dependencies
Run tests
Create a commit
Chain commands with error propagation
Start a background server
Usage guidelines
- Prefer dedicated tools — use
Read,Edit,Write,Glob, andGrepinstead ofcat,sed,find, andgrep. - Use absolute paths in commands when referencing files.
- Quote paths with spaces:
cd "path with spaces". - Chain related commands with
&&rather than running them as separate tool calls when they must run sequentially. - Parallel independent commands should be separate tool calls issued at the same time, not chained with
;. - Avoid
sleepfor polling — userun_in_backgroundand wait for the completion notification instead. - Avoid interactive commands (e.g.,
git rebase -i,git add -i) — Claude Code does not support interactive terminal input.