| name | bash-patterns |
| description | Universal Bash command best practices for Claude Code. Use when encountering Bash approval prompts, writing temp scripts, working with .cache/scripts/, handling complex Bash commands, or optimizing tool selection (Read/Grep/Glob vs Bash). |
Bash Patterns Skill
Purpose: Optimize Bash tool usage in Claude Code workflows
Token efficiency: ~25 tokens metadata (always loaded), ~200-600 tokens on-demand (SKILL.md + resources)
Type: Type 6 Guidance-Only (no scripts, patterns only)
Quick Reference
Temp Script Pattern
When to use: Complex logic (loops, conditionals), reusable operations, multi-step validation
Pattern:
- Write complex logic to
.cache/scripts/{name}.sh - Make executable:
chmod +x .cache/scripts/{name}.sh - Execute:
Bash(.cache/scripts/{name}.sh) - Result: Single approval (execute only, not each line)
Benefits:
- Single approval instead of 5-10 prompts
- Reusable across multiple runs
- Debuggable (inspect/modify script independently)
- Readable (multi-line clearer than one-liners)
See: resources/temp-scripts.md for complete pattern and examples
Tool Selection Matrix
| Operation | Prefer | Avoid | Why |
|---|---|---|---|
| Read file | Read tool | cat/head/tail | Dedicated tool, no approval |
| Search content | Grep tool | grep/rg via Bash | Regex support, context, no approval |
| Find files | Glob tool | find via Bash | Fast, pattern matching, no approval |
| Complex logic | Temp script | Bash one-liner | Single approval, readable |
See: resources/approval-optimization.md for complete matrix and trade-offs
Parallel Execution
Pattern: Multiple independent Bash calls in SINGLE message
Benefits:
- 2 operations: ~2x faster
- 4 operations: ~3-4x faster
- 8 operations: ~6-8x faster
Example:
# Sequential (slow)
Bash("git status && git diff && git log")
# Parallel (fast)
Bash("git status")
Bash("git diff")
Bash("git log")
See: resources/parallel-execution.md for batching guidelines and examples
Capabilities
1. Temp Script Pattern
Eliminates approval prompts: Write complex Bash logic to .cache/scripts/ → single approval on execute
Use cases:
- Loops over files (
for FILE in *.md; do ... done) - Conditionals (
if [[ -f file ]]; then ... fi) - Multi-step validation (check → transform → verify)
- Reusable operations (run multiple times)
Anti-patterns:
- Complex one-liners forcing approval per line
- Inline loops in Bash tool calls
- Non-reusable validation logic
Details: resources/temp-scripts.md (~80-120 lines)
2. Approval Optimization
Minimizes approval friction: Choose dedicated tools over Bash when possible
Tool selection principles:
- Read > cat/head/tail: Dedicated tool, line ranges, no approval
- Grep > grep/rg: Regex support, context lines, output modes, no approval
- Glob > find: Fast, pattern matching, mtime sorting, no approval
- Temp script > one-liner: Single approval for complex logic
Approval triggers:
- Pipes (
|) - Loops (
for,while) - Conditionals (
if,case) - Redirects (
>,>>,2>&1)
Trade-offs:
- Tool overhead (
50ms) vs approval friction (5-10s per prompt) - Sequential tool calls vs single Bash command
- Readability vs brevity
Details: resources/approval-optimization.md (~100-150 lines)
3. Parallel Execution
Speeds up workflows: Multiple independent Bash calls in single message
Performance metrics (measured):
- 2 operations: ~2x speedup
- 4 operations: ~3-4x speedup
- 8 operations: ~6-8x speedup
Batching guidelines:
DO batch (independent operations):
- Status checks (
git status,git diff,git log) - File searches (
find,ls,stat) - Independent reads (
cat file1,cat file2)
DON'T batch (dependencies):
- Read → Edit (must verify content first)
- Write → Read (verify write succeeded)
- Git add → commit (staging must precede commit)
Sequential dependencies: Use && chaining
Bash("mkdir dir && cd dir && touch file")
Details: resources/parallel-execution.md (~80-120 lines)
4. Command Readability
Makes Bash commands maintainable: Patterns for quoting, heredocs, error handling
Patterns:
Git commit patterns:
# File-based commits (preferred when message in file)
git commit -F path/to/message.txt
# Inline commits (constructing on-the-fly)
git commit -m "$(cat <<'EOF'
Fix authentication bug
- Add token validation
- Handle expired tokens
- Update tests
EOF
)"
Comparison:
-F: Cleaner (no subshell), safer escaping, direct file read- Heredoc: Flexible (variable interpolation), inline construction
Quoting paths with spaces:
cd "/Users/name/My Documents" # Correct
python "/path/with spaces/script.py" # Correct
Error handling:
#!/bin/bash
set -e # Exit on error
set -u # Error on undefined variable
set -o pipefail # Pipeline fails if any command fails
Debugging:
#!/bin/bash
set -x # Print commands as executed
PS4='+ ${BASH_SOURCE}:${LINENO}: ' # Show file:line in trace
Resources
Detailed Patterns
temp-scripts.md (~80-120 lines)
- Complete temp script workflow
- 3+ concrete before/after examples
- Anti-patterns and gotchas
- .cache/scripts/ structure
approval-optimization.md (~100-150 lines)
- Complete tool selection matrix
- Approval trigger identification
- When Bash necessary vs when to avoid
- 6+ concrete examples with trade-offs
parallel-execution.md (~80-120 lines)
- Parallel vs sequential patterns
- Batching guidelines (DO/DON'T)
- Performance metrics
- 4+ examples from codebase
Integration
Complementary Skills
cli-dev: Documents what CLI tools do (fd, fzf, trash capabilities) bash-patterns: Documents how to use Bash tool in Claude Code framework: References bash-patterns for Bash optimization workflows
Quick Access
From project CLAUDE.md: Tool selection → delegates to this skill Auto-loading: Triggers on "Bash approval", "temp script", ".cache/scripts", "complex Bash"
Progressive Disclosure Strategy
Metadata (25 tokens): Always loaded (frontmatter only)
SKILL.md (400-500 lines): Loaded on skill invocation (this file)
Resources (~50-150 lines each): Loaded on-demand (specific pattern needed)
Typical usage:
- 70% sessions: Metadata only (~25 tokens) - Bash mentioned, no deep dive
- 20% sessions: Metadata + 1 resource (~200 tokens) - Specific pattern needed
- 10% sessions: Metadata + multiple resources (~600 tokens) - Complex Bash work
Target savings: 86%+ vs loading all patterns upfront
Success Metrics
Approval Reduction
- Before: Complex Bash → 5-10 approval prompts
- After: Temp script pattern → 1 approval (execute only)
- Savings: 80-90% approval reduction
Performance Improvement
- Before: Sequential Bash commands
- After: Parallel Bash calls in single message
- Speedup: 2-4x for common operations (status, diff, log)
Token Efficiency
- Baseline: ~500 tokens if all patterns loaded
- With progressive disclosure: ~25-200 tokens typical session
- Target: 86%+ savings
When to Use
Use bash-patterns skill when:
- Encountering Bash approval prompts repeatedly
- Writing complex Bash commands (loops, conditionals)
- Working with .cache/scripts/ directory
- Choosing between Bash and dedicated tools (Read/Grep/Glob)
- Optimizing workflow performance (parallel execution)
Manual invocation:
"Show me the temp script pattern"
"How do I avoid Bash approval prompts?"
"What's the tool selection matrix for Bash vs Read/Grep/Glob?"
"How do I parallelize Bash operations?"