Back to Skills

claude-code-bash-patterns

verified

Claude Code Bash tool patterns with hooks, automation, git workflows. Use for PreToolUse hooks, command chaining, CLI orchestration, custom commands, or encountering bash permissions, command failures, security guards, hook configurations.

View on GitHub

Marketplace

claude-skills

secondsky/claude-skills

Plugin

claude-code-bash-patterns

tooling

Repository

secondsky/claude-skills
28stars

plugins/claude-code-bash-patterns/skills/claude-code-bash-patterns/SKILL.md

Last Verified

January 24, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/secondsky/claude-skills/blob/main/plugins/claude-code-bash-patterns/skills/claude-code-bash-patterns/SKILL.md -a claude-code --skill claude-code-bash-patterns

Installation paths:

Claude
.claude/skills/claude-code-bash-patterns/
Powered by add-skill CLI

Instructions

# Claude Code Bash Patterns

**Status**: Production Ready ✅ | **Last Verified**: 2025-11-18

---

## Quick Start

### Basic Command

```bash
ls -la
```

### Command Chaining

```bash
bun install && bun run build && bun test
```

### Hooks

Create `.claude-hook-pretooluse.sh`:

```bash
#!/usr/bin/env bash
# PreToolUse hook - runs before every Bash command

echo "Running: $1"
```

**Load `references/hooks-examples.md` for complete hook patterns.**

---

## The Five Core Patterns

### 1. Sequential Operations (&&)

**Use when**: Each command depends on previous success

```bash
git add . && git commit -m "message" && git push
```

**Why**: Stops chain if any command fails

---

### 2. Parallel Operations (Multiple tool calls)

**Use when**: Commands are independent

```
Message with multiple Bash tool calls in parallel
```

**Load `references/cli-tool-integration.md` for parallel patterns.**

---

### 3. Session Persistence

**Use when**: Need to maintain state across commands

```bash
# Set environment variable
export API_KEY="sk-..."

# Use in later commands (same session)
curl -H "Authorization: Bearer $API_KEY" api.example.com
```

---

### 4. Background Processes

**Use when**: Long-running tasks

```bash
npm run dev &
# Get PID with $!
```

---

### 5. Hooks for Automation

**Use when**: Need pre/post command logic

**Load `references/hooks-examples.md` for all hook types.**

---

## Critical Rules

### Always Do ✅

1. **Use && for sequential dependencies** (not semicolons)
2. **Quote paths with spaces** (`cd "path with spaces"`)
3. **Check environment before destructive ops** (rm, git push --force)
4. **Use specialized tools first** (Read, Grep, Glob before Bash)
5. **Set timeouts for long operations** (up to 10 minutes)
6. **Validate inputs** before passing to shell commands
7. **Use hooks for repeated patterns** (logging, validation)
8. **Maintain session state** (export variables once)
9. **Handle errors explicitly** (check exit codes)
10. **Document custom c

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
7935 chars