Overview
The Bash tool executes shell commands in a Bash-compatible environment. It includes automatic background job conversion for long-running tasks, security restrictions on dangerous commands, and cross-platform compatibility.Parameters
The shell command to execute. Can include pipes, redirects, and other shell features.
A brief description of what the command does (aim for under 30 characters). Used for permission prompts and job tracking.
The directory to execute the command in. Defaults to the current working directory. Use this instead of
cd commands.Set to
true to explicitly run the command as a background job. Defaults to false.Features
Cross-Platform Compatibility
Crush uses the mvdan/sh interpreter, which provides Bash-compatible shell execution on all platforms including Windows. This means:- Common shell builtins work everywhere (
cd,echo,export, etc.) - Core utilities are available on Windows
- Use forward slashes for paths:
ls C:/foo/barnotls C:\\foo\\bar
Automatic Background Jobs
Commands that take longer than 1 minute are automatically converted to background jobs:- Command starts and begins executing
- After 1 minute if still running, Crush moves it to the background
- Shell ID returned for tracking the job
- Use
job_outputtool to view current output - Use
job_killtool to terminate the job
Explicit Background Execution
You can explicitly run commands in the background withrun_in_background: true:
- Long-running servers (
npm start,python -m http.server) - Watch/monitoring tasks (
npm run watch,tail -f logfile) - Continuous processes that don’t exit on their own
- Build commands (
npm run build,go build) - Test suites (
npm test,pytest) - Git operations
- File operations
- Short-lived scripts
Security Restrictions
The Bash tool blocks dangerous commands to protect your system:Banned Commands
Network/Download tools:curl,wget,ssh,scp,nc,telnet- Browsers:
chrome,firefox,safari
sudo,su,doas
- System:
apt,yum,dnf,pacman,brew - Language-specific global installs:
npm install -g,pip install --user
mount,umount,fdisk,systemctlcrontab,firewall-cmd,iptables
Command-Specific Restrictions
Some commands are allowed but with restrictions:go test -execis blocked (can run arbitrary commands)npm install --globalis blockedpip install --useris blocked
Safe Read-Only Commands
These commands execute without permission prompts:git status,git log,git diffls,pwd,whichcat,head,tail(though View tool is preferred)grep(though Grep tool is preferred)
Output Handling
Truncation
Output is truncated if it exceeds 30,000 characters:- First 15,000 characters are shown
- Middle section is truncated with a note
- Last 15,000 characters are shown
Working Directory
The current working directory is included in the output:Usage Examples
Basic Command Execution
Using Working Directory
working_dir parameter
cd command
Background Job
Command Chaining
&&- Run next command only if previous succeeds;- Run next command regardless of previous result||- Run next command only if previous fails
Git Operations
The Bash tool has special handling for Git operations:Creating Commits
When creating commits, follow this workflow:-
Check status in parallel:
-
Stage files:
-
Create commit with HEREDOC:
Creating Pull Requests
Use thegh CLI for GitHub operations:
Best Practices
Command Design
- Use absolute paths when possible
- Quote paths with spaces using double quotes
- Provide descriptive descriptions for permission prompts
- Chain related operations with
&& - Avoid interactive commands (they won’t work)
Tool Selection
-
Prefer specialized tools:
- Use View instead of
cat - Use Grep instead of
greporrg - Use Glob instead of
find - Use LS instead of
ls
- Use View instead of
-
Use Bash for:
- Build commands (
npm run build,go build) - Test execution (
pytest,npm test) - Git operations
- Package management within project (
npm install, notnpm install -g)
- Build commands (
Error Handling
Commands return:- Exit code for non-zero exits
- stderr output if present
- Interrupted status if cancelled
Permissions
The Bash tool requires permission for:- All commands except safe read-only ones
- Commands outside the working directory
- Potentially destructive operations
Platform-Specific Notes
Windows
- Use forward slashes:
C:/Users/name/file.txt - Core utilities available via mvdan/sh
- PowerShell-specific commands not available
- Use
cmd /cprefix for Windows-specific commands if needed
Unix/Linux/macOS
- Standard Bash behavior
- All common utilities available
- Shell builtins work as expected
Troubleshooting
Command Not Found
If a command is not found:- Check if it’s in your PATH
- Use absolute path to the executable
- Verify the command is installed
Command Blocked
If a command is blocked:- Check the banned commands list
- Consider if there’s an alternative approach
- Use a specialized tool if available
- For package management, use project-local installs
Background Job Issues
If a background job isn’t working:- Don’t use
&at the end - userun_in_background: true - Check job output with
job_outputtool - Terminate with
job_killif needed
Permission Denied
If permission is denied:- Approve the permission prompt
- Add to allow list if it’s a trusted operation
- Check if the command is trying to write outside allowed areas