BashTool
Execute shell commands on macOS, Linux, and WSL
PowerShellTool
Execute PowerShell cmdlets and scripts on Windows
BashTool
Executes a bash command and captures its stdout and stderr. The working directory persists between commands within a session, but the shell environment (variables, functions, aliases) does not — each invocation starts a fresh shell initialized from the user’s profile. Tool name:BashRead-only: no
Concurrency-safe: no (commands execute serially)
Destructive: yes (can modify or delete files and system state)
Parameters
The shell command to execute. Use
&& to chain dependent commands and | for pipelines. Avoid newlines as command separators — use ; or && instead.Optional timeout in milliseconds. Defaults to the session-configured bash timeout (typically 120 000 ms / 2 minutes). Maximum value is also configurable per-session. When the timeout is reached, the command is killed and a timeout error is returned.
A short, active-voice description of what this command does (shown in the UI while the command runs). Examples:
"Install package dependencies", "Run unit tests", "Build Docker image".When
true, the command is started as a background task. The tool returns immediately with a backgroundTaskId. Claude Code sends a notification when the task completes. Use Read to inspect the output file at the path returned in backgroundTaskId.Omitted entirely when the CLAUDE_CODE_DISABLE_BACKGROUND_TASKS environment variable is truthy.Override sandbox restrictions for this single invocation. Only applies when sandboxing is enabled and
allowUnsandboxedCommands is permitted by policy. Prompts the user for explicit confirmation before the command runs.Return value
Standard output produced by the command.
Standard error output produced by the command.
true if the command was interrupted (user pressed Ctrl+C or the session was aborted).Task ID returned when
run_in_background is true. Use this to reference the background task.true if the user manually sent the command to the background via Ctrl+B.true if Claude Code automatically moved a long-running blocking command to the background in assistant mode (after ~15 seconds).Human-readable interpretation of a non-zero exit code when the tool can identify its meaning (e.g.
"grep found no matches").true for commands that conventionally produce no stdout on success (e.g. mv, mkdir, chmod). The UI shows “Done” instead of “(No output)”.Path to the full output on disk when stdout/stderr exceeded the inline size limit.
Total size in bytes of the persisted output.
Background tasks
Setrun_in_background: true for long-running processes such as dev servers, build watchers, or test suites where you do not need to block on the result.
Set
CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1 in the environment to disable the run_in_background parameter entirely. When this variable is set, the parameter is omitted from the tool’s schema.Sandbox mode
When sandboxing is enabled (viasettings.json or the /sandbox command), all commands run inside an OS-level sandbox that enforces:
- Filesystem read restrictions — deny-only or allow-only path lists
- Filesystem write restrictions — allow-only path list with optional deny-within-allow
- Network restrictions — allowed/denied host lists and Unix socket policy
$TMPDIR for temporary files inside the sandbox — it is automatically set to a writable directory. Do not use /tmp directly.
To bypass sandboxing for a single command, set dangerouslyDisableSandbox: true. This requires user confirmation and should be used only when a specific command fails due to sandbox restrictions (look for “Operation not permitted” or “Access denied” errors).
Interrupt behavior
When the user presses Ctrl+C or the session is aborted, BashTool sendsSIGTERM to the running process and sets interrupted: true in the result. The model should treat an interrupted result as incomplete and handle it accordingly.
Security considerations
- Prefer dedicated tools for file operations: use
Read,Edit,Write,Glob, andSearchinstead ofcat,sed,grep,find. Dedicated tools provide better permission granularity, richer progress UI, and protection against prompt-injection via file contents. - Quote paths that contain spaces:
cd "path with spaces". - Avoid
git add -A— prefer staging specific files to prevent accidentally committing.envor credential files. - Never skip hooks (
--no-verify,--no-gpg-sign) unless the user explicitly requests it. - Never force-push to
main/masterwithout explicit user instruction.
Usage examples
Run tests:PowerShellTool
The Windows equivalent of BashTool. Executes PowerShell cmdlets and scripts via thepwsh (PowerShell Core) binary, with the same permission model, sandbox enforcement, and background-task support as BashTool.
Tool name: PowerShellRead-only: no
Concurrency-safe: no
Destructive: yes
Platform: Windows only (disabled on macOS/Linux)
Parameters
The PowerShell command or script block to execute.
Optional timeout in milliseconds. Behaviour is identical to BashTool’s
timeout.Active-voice description shown in the UI while the cmdlet runs.
Run the command as a background task. Same semantics as BashTool’s
run_in_background.Override sandbox restrictions for this invocation. Same semantics as BashTool’s
dangerouslyDisableSandbox.Return value
Identical shape to BashTool:stdout, stderr, interrupted, backgroundTaskId, backgroundedByUser, assistantAutoBackgrounded, noOutputExpected, persistedOutputPath, persistedOutputSize.
PowerShell-specific notes
- Cmdlet names are canonicalized to lowercase before matching against read-only / search heuristics.
- Common read-only cmdlets include
Get-Content,Get-Item,Get-ChildItem,Test-Path,Resolve-Path. - Common search cmdlets include
Select-String(grep equivalent) andGet-ChildItem -Recurse(find equivalent). - The tool requires
pwsh(PowerShell Core 6+) to be installed. It will not fall back topowershell.exe(Windows PowerShell 5.x).