Comprehensive knowledge for using the Bash tool in Claude Code effectively. This skill should be used when orchestrating CLI tools, configuring hooks, setting up automation workflows, managing git operations, handling multi-command patterns, or encountering Bash tool errors. Covers: PreToolUse hooks, command chaining patterns, git workflow automation, CLI tool integration, custom commands (.claude/commands/), security configurations, allowlisting, session persistence, output handling, error prevention, and troubleshooting common issues. Use when: setting up Claude Code hooks, configuring bash permissions, creating custom commands, automating git workflows, orchestrating multiple CLI tools, debugging bash command failures, implementing security guards, logging command execution, or preventing dangerous operations.
Status: Production Ready ✅ Last Updated: 2025-11-07 Production Tested: wordpress-auditor, claude-skills, multiple client projects
Comprehensive knowledge for using Claude Code's Bash tool effectively, including CLI orchestration, hooks automation, security configurations, and error prevention. This is a meta-skill that teaches how to work with command-line tools in Claude Code.
✅ CLI Tool Orchestration: Sequential, parallel, and conditional command patterns ✅ Git Workflow Automation: Intelligent commits, PR creation, branch management ✅ Hooks Configuration: PreToolUse, PostToolUse, SessionStart automation ✅ Security Guards: Dangerous command blocking, audit logging, allowlisting ✅ Custom Commands: Create reusable workflows in .claude/commands/ ✅ Multi-CLI Integration: gh, wrangler, npm, docker, terraform, etc. ✅ Error Prevention: 12 documented issues with sources ✅ Session Management: Environment persistence, output handling
| Issue | Why It Happens | Source | How Skill Fixes It |
|-------|---------------|---------|-------------------|
| cygpath command not found | MSYS/Git Bash lacks Cygwin tools | Issue #9883 | Use WSL or configure CLAUDE_CODE_GIT_BASH_PATH |
| Pipe command failures | Pipe parsing issues | Issue #774 | Use bash -c wrapper or specialized tools |
| Command timeout | Long operations without timeout config | Bash tool docs | Set explicit timeout parameter (up to 10 min) |
| Output truncation | Output exceeds 30k char limit | Bash tool docs | Limit with head or save to file |
| "No suitable shell" | Windows shell detection | Issue #3461 | Set SHELL env var, use WSL |
| Bash access loss | Session state corruption | Issue #1888 | Restart session or use restart: true |
| Interactive prompt hangs | Command expects input | Bash tool docs | Use --yes flags or provide stdin |
| Permission denied | Script not executable | Common pattern | chmod +x before execution |
| Env vars not persisting | Agent thread CWD reset | Claude Code system | Chain commands or use SessionStart hook |
| Pre-commit hook issues | Hook modifies staged files | Git workflow pattern | Check authorship, amend or new commit |
| Wildcard allowlist fails | Syntax mismatch | Issue #462 | Use correct pattern syntax |
| Dangerous commands | No guardrails | Security best practice | Implement PreToolUse guard hook |
# Install hook script
mkdir -p ~/.claude/hooks
# (Copy dangerous-command-guard.py from this skill's scripts/ directory)
chmod +x ~/.claude/hooks/dangerous-command-guard.py
# Configure in ~/.claude/settings.json
cat > ~/.claude/settings.json <<'EOF'
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "python3 ~/.claude/hooks/dangerous-command-guard.py"
}
]
}
]
}
}
EOF
# Create custom command
cat > .claude/commands/deploy.md <<'EOF'
Run full deployment workflow:
1. Run tests (npm test)
2. Build production (npm run build)
3. Deploy to Cloudflare (npx wrangler deploy)
4. Verify deployment health check
EOF
User: /deploy
Claude: [Executes the workflow automatically]
Result: Automated, secure CLI workflows with 100% error prevention
Full instructions: See SKILL.md
| Approach | Tokens Used | Errors Encountered | Time to Setup | |----------|------------|-------------------|---------------| | Manual Setup | ~8,500 | 2-3 | ~15 min | | With This Skill | ~3,800 | 0 ✅ | ~5 min | | Savings | ~55% ⬇️ | 100% ✅ | ~67% ⬇️ |
Evidence:
| Package/Tool | Version | Status | |-------------|---------|--------| | Claude Code CLI | Latest (2025-11-07) | ✅ Current | | bash | 4.0+ | ✅ Required | | jq | 1.6+ | ✅ Recommended | | gh CLI | 2.0+ | ✅ Optional | | Python | 3.7+ | ✅ For hooks | | Git | 2.0+ | ✅ For workflows |
Prerequisites:
Integrates With:
Optional:
jq for JSON processing in hooksgh for GitHub automationdirenv for environment managementclaude-code-bash-patterns/
├── SKILL.md # Complete documentation (~4,500 words)
├── README.md # This file
├── scripts/ # Hook scripts (executable)
│ ├── dangerous-command-guard.py # Block unsafe commands
│ ├── bash-audit-logger.sh # Log all bash commands
│ └── package-manager-enforcer.sh # Enforce lockfile consistency
├── references/ # Deep-dive guides
│ ├── git-workflows.md # Git automation patterns
│ ├── hooks-examples.md # Complete hooks configurations
│ ├── cli-tool-integration.md # Custom tool integration
│ ├── security-best-practices.md # Security hardening
│ └── troubleshooting-guide.md # Detailed issue solutions
└── templates/ # Configuration templates
├── settings.json # Complete settings example
├── dangerous-commands.json # Command block patterns
├── custom-command-template.md # .claude/commands/ template
├── github-workflow.yml # CI/CD integration
└── .envrc.example # Environment setup
cmd1 && cmd2 && cmd3 (stops on failure)cat <<'EOF' ... EOF for multi-line content (git commits, PRs)VAR=$(command) for processing outputcmd1 || cmd2 for fallback logicReal-World Usage:
Measured Impact:
Evidence:
Ready to use! See SKILL.md for complete setup and examples.
npx skills add jackspace/claude-code-bash-模式下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer