Bash Tool - Claude Code
Execute shell commands with persistent working directory in project bounds.
The Bash tool runs shell commands. It's the most capable and most-permissioned tool in Claude Code, which is why every session has at least one rule about it.
What it does
Bash runs a command in a persistent shell whose working directory sticks within the project. Output comes back as combined stdout+stderr, truncated if huge. You can run it in the background for long processes, pipe, use heredocs, and chain commands. Permission rules gate which commands are allowed.
When to use it
- Running tests, builds, linters, and formatters.
- Git operations, file system changes, and installs.
- Anything that's faster as a one-liner than a tool sequence.
- Invoking project-specific CLIs.
Gotchas
- Interactive prompts hang the tool. Pass flags or pipe input instead of waiting for TTY.
- Shell state (exported vars,
cdin subshells) doesn't persist beyond a single call unless you chain with&&. - Newlines are blocked in command strings on some setups. Use quoted strings or here-docs for multi-line payloads.
Official docs: https://code.claude.com/docs/en/tools-reference.md#bash-tool-behavior
Technical content at the intersection of AI and development. Building with AI agents, Claude Code, and modern dev tools - then showing you exactly how it works.
Get the weekly deep dive
Tutorials on Claude Code, AI agents, and dev tools - delivered free every week.
Was this helpful?




