jackspace/claudeskillz/claude-code-bash-patterns
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
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.
Install
npx vskill@latest install jackspace/claudeskillz/claude-code-bash-patternsSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
Claude Code Bash Patterns
Status: Production Ready ✅ Last Updated: 2025-11-07 Dependencies: Claude Code CLI (latest version) Official Docs: https://docs.claude.com/en/docs/claude-code/tools
Quick Start (10 Minutes)
1. Understanding the Bash Tool
The Bash tool is Claude Code's primary interface for executing command-line operations. Unlike specialized tools (Read, Grep, Glob), the Bash tool provides direct shell access for complex workflows.
Key Characteristics:
- Session Persistence: Commands run in a persistent bash session within a conversation
- Environment Inheritance: Inherits environment variables and working directory
- Output Limit: Truncates output at 30,000 characters
- Default Timeout: 2 minutes (configurable up to 10 minutes)
When to Use Bash Tool:
- ✅ Running CLI tools (git, npm, wrangler, gh, etc.)
- ✅ Command chaining (sequential operations)
- ✅ Process orchestration (build, test, deploy)
- ✅ Environment setup and management
When NOT to Use Bash Tool:
- ❌ Reading files → Use Read tool instead
- ❌ Searching file patterns → Use Glob tool instead
- ❌ Searching content → Use Grep tool instead
- ❌ Editing files → Use Edit tool instead
2. Basic Command Patterns
Golden Rule: Use && when you care about failures, ; when you don't, and parallel calls when operations are independent.
3. Configure Your First Hook
Hooks let you run code before/after tool execution. Here's a simple audit logger:
Save this to ~/.claude/settings.json to log every bash command with timestamp.
The Five Core Patterns
Pattern 1: Command Chaining
When to Use: Sequential operations where each depends on previous success
Syntax: command1 && command2 && command3
Example: Build and deploy workflow
Why It Matters:
- Stops on first failure (prevents cascading errors)
- Maintains clean error messages (know exactly what failed)
- Saves tokens (no need to check status between commands)
Anti-Pattern: Using ; when you care about failures
Advanced: Conditional execution with ||
Pattern 2: Parallel Execution
When to Use: Independent operations that can run simultaneously
How: Make multiple Bash tool calls in a single message
Example: Git workflow pre-commit analysis
Benefits:
- ~40% faster than sequential (no waiting between calls)
- Reduces context usage (all results arrive together)
- Better user experience (appears instant)
Important: Only parallelize truly independent operations. If Call 2 depends on Call 1's output, run sequentially.
Pattern 3: HEREDOC for Multi-Line Content
When to Use: Git commits, file creation, complex strings with newlines
Syntax: cat <<'EOF' ... EOF
Example: Git commit with detailed message
Why Single Quotes: <<'EOF' prevents variable expansion in the content. Use <<"EOF" if you want variables to expand.
Common Mistake: Forgetting quotes around $() wrapper
Pattern 4: Output Capture and Processing
When to Use: Need to process command output before using it
Pattern: Command substitution with $()
Example: Get current branch name
Example: Conditional logic based on output
Limitation: Output truncated at 30,000 characters. For large outputs:
Pattern 5: Conditional Execution
When to Use: Different actions based on conditions
Pattern: Test commands with && / ||
Example: Run tests only if files changed
Example: Different commands based on file existence
Example: Multi-condition logic
Hooks: Advanced Automation
Hooks are shell commands or Claude prompts that run before/after tool execution. They're your security guards, cleanup crew, and automation helpers.
PreToolUse: The Security Guard
Purpose: Runs before tool execution, can block or modify behavior
Exit Codes:
0= Allow execution1= Block with generic error2= Block with custom error message (from stderr)
Use Case 1: Block Dangerous Commands
File: ~/.claude/hooks/dangerous-command-guard.py
Settings Configuration:
Use Case 2: Log All Bash Commands
Result: Every bash command logged with timestamp to ~/.claude/bash-audit.log
Use Case 3: Enforce Package Manager
Check for lockfile and block wrong package manager:
PostToolUse: The Cleanup Crew
Purpose: Runs after successful tool execution (exit code 0 only)
Example: Auto-format after file edits
Example: Run tests after code changes
SessionStart: Environment Setup
Purpose: Runs once at session start, sets up environment
Example: Load project-specific environment
Environment Variables Available in Hooks:
$CLAUDE_TOOL_INPUT- JSON string of tool call$CLAUDE_ENV_FILE- Path to environment file- Standard env vars (
$HOME,$USER,$PWD, etc.)
Git Workflows (Production-Tested)
These patterns are used by Anthropic's engineering team for 90%+ of git interactions.
Pattern: Intelligent Git Commits
Step 1: Gather context (parallel calls)
Why Parallel: Independent operations, faster response, better UX
Step 2: Analyze changes
- Review actual code changes (not just file names!)
- Match commit message style from git log
- Focus on "why" not "what"
- Keep message concise (1-2 sentences)
Step 3: Commit with HEREDOC
Step 4: Verify
Important: If pre-commit hook modifies files:
- Check authorship:
git log -1 --format='%an %ae' - Check not pushed:
git status(should show "ahead of origin") - If both safe:
git add . && git commit --amend --no-edit - If not safe:
git add . && git commit -m "Apply pre-commit hook changes"
Pattern: Pull Request Creation
Step 1: Understand branch state (parallel)
Step 2: Analyze ALL commits (not just latest!)
- What changed since branch diverged from main?
- What's the overall goal of this branch?
- What needs testing?
Step 3: Create PR with gh CLI
Result: Professional PR with clear summary and test plan
CLI Tool Integration
GitHub CLI (gh)
Claude knows gh CLI by default. Common patterns:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/claude-code-bash-patterns/SKILL.md
Popularity
- Repository stars
- 14
- Repository forks
- 6
- 7-day trend score
- 14
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 1 May 2026, 5 months ago.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/jackspace/claudeskillz/claude-code-bash-patterns)