Bash Tools
Claude Code provides powerful integration with command-line tools through the Bash tool, allowing you to execute shell commands and work with various CLI utilities.
Basic Bash Tool Usage
Simple Commands
Claude can execute basic shell commands:
Run `ls -la` to see all files in the current directoryClaude executes:
ls -laComplex Commands
Check git status and show recent commitsClaude executes:
git status
git log --oneline -5Common Development Workflows
1. Package Management
npm/yarn/pnpm Operations
Install new dependencies and update package.jsonClaude executes:
npm install lodash @types/lodash
npm updateVersion Management
Check current Node.js and npm versionsClaude executes:
node --version
npm --version2. Git Operations
Repository Status
Show current branch, status, and recent changesClaude executes:
git branch
git status
git diff --statBranch Management
Create a new feature branch and switch to itClaude executes:
git checkout -b feature/new-dashboard
git push -u origin feature/new-dashboard3. Build and Test Commands
Running Tests
Run unit tests and generate coverage reportClaude executes:
npm test
npm run test:coverageBuild Operations
Build the project and check for errorsClaude executes:
npm run build
npm run type-checkAdvanced Bash Integration
1. Piped Commands
Find all TypeScript files and search for specific functionClaude executes:
find . -name "*.ts" -type f | xargs grep -l "useEffect"2. Environment Management
Set environment variables and run development serverClaude executes:
export NODE_ENV=development
export DEBUG=true
npm run dev3. File Operations
Create directory structure and initialize filesClaude executes:
mkdir -p src/components/Dashboard/{components,hooks,utils}
touch src/components/Dashboard/index.ts
touch src/components/Dashboard/Dashboard.tsxTool Integration Examples
Docker Operations
Build and run Docker container for the applicationClaude executes:
docker build -t my-app .
docker run -p 3000:3000 my-appDatabase Management
Run database migrations and seed dataClaude executes:
npx prisma migrate dev
npx prisma db seedLinting and Formatting
Fix code formatting and linting issuesClaude executes:
npm run lint -- --fix
npm run formatBest Practices
1. Command Validation
Claude validates commands before execution:
- Checks for potentially dangerous operations
- Confirms file paths exist
- Validates command syntax
2. Error Handling
When commands fail, Claude:
- Analyzes error output
- Suggests alternative approaches
- Provides troubleshooting steps
3. Path Management
Absolute vs Relative Paths
# Claude prefers absolute paths when possible
cd /full/path/to/project
npm install
# Rather than relative navigation
cd ../../../project && npm installSecurity Considerations
Allowed Operations
- File system navigation and inspection
- Package management operations
- Git repository management
- Build and test commands
- Development server operations
Restricted Operations
- System-level modifications
- User account management
- Network configuration changes
- Destructive operations without confirmation
Configuration Options
Tool Permissions
Configure allowed Bash commands in your Claude Code settings:
{
"allowedTools": [
"Bash(npm:*)",
"Bash(git:*)",
"Bash(docker:*)",
"Bash(ls:*)",
"Bash(cd:*)"
]
}Command Timeouts
Set timeout limits for long-running commands:
{
"bashTimeout": 300000,
"buildTimeout": 600000
}Troubleshooting
Common Issues
Command Not Found
- Verify tool is installed
- Check PATH environment variable
- Use absolute path to executable
Permission Denied
- Check file permissions
- Verify write access to directory
- Consider using sudo (if allowed)
Command Timeouts
- Increase timeout settings
- Break down into smaller commands
- Use background processes for long operations
Next: MCP Servers - Learn about Model Context Protocol server integration.