CLI Playbook
Find the recipe. Copy the command. Ship it.
Your First CLI Call
Run Claude in headless mode and get a plain text response
Parse JSON Output
Get the full metadata envelope with cost, tokens, and session ID
Stream Responses (NDJSON)
Get real-time events as NDJSON for building UIs and pipelines
Set a Budget Cap
Limit spending per invocation with --max-budget-usd
Disable Tools for Pure Text
Run Claude with zero tool access for text generation, classification, or summarization
Append System Prompt
Add custom rules while keeping the default system prompt intact
Use Structured Output (JSON Schema)
Force Claude to return data matching an exact JSON schema via constrained decoding
Replace System Prompt
Override the entire default system prompt for a custom persona
Pipe File to Claude
Feed file contents via stdin pipe for quick code review or analysis
Continue Most Recent Session
Resume the last session in the current working directory without knowing the session ID
Ephemeral Session (No Persistence)
Run a one-off query without saving session data to disk
Handle Resume Failures
Gracefully fall back to a new session when --resume fails with an expired or corrupted ID
Deterministic Session IDs
Use a custom UUID for mapping sessions to database records or ticket IDs
Fork a Session
Branch a conversation to explore alternatives without losing the main thread
Create and Resume a Session
Start a conversation, capture the session ID, and continue it later
Plan → Review → Execute
Three-phase workflow: generate a plan, review it, then execute with full permissions
Multi-Turn Cost Tracking
Track cumulative cost across session turns by extracting total_cost_usd from each response
Daily Scheduled Tasks
Run recurring prompts on a schedule using /loop or CronCreate within a session
Fallback Model on Overload
Automatically switch to a cheaper model when the primary model is rate-limited
GitHub Action PR Review
Auto-review pull requests using the official Claude Code GitHub Action
Custom CLI Pipeline
Build a CI/CD pipeline using Claude CLI directly in GitHub Actions
Cost-Capped PR Review
Review a PR with a strict budget limit and machine-parseable output
Plan Mode in CI
Generate a plan in CI, post for human review, then execute on approval
Batch File Processing
Process multiple files independently with per-file budget caps and cost tracking
Retry with Backoff
Handle transient API failures (network errors, timeouts, 500s) with exponential retry logic
Audit Logging with Hooks
Log every tool call to a file using PostToolUse hooks for compliance and debugging
Multi-Repo Batch Operations
Run Claude across multiple repositories in a single automated sweep
@claude GitHub Trigger
Trigger Claude Code reviews by mentioning @claude in PR comments via GitHub Actions
Pipe Git Diff for Review
Send staged or unstaged changes to Claude for automated code review
Allowlist Specific Tools
Restrict Claude to only specific tools using --allowedTools and --disallowedTools
Sandboxed Execution
Run Claude with OS-level filesystem sandbox and extended directory access via --add-dir
Network-Isolated Mode
Block all web access while keeping file tools available for air-gapped analysis
Strict MCP Config
Fail fast if any MCP server can't connect instead of silently degrading
Read-Only Agent
Lock Claude to read-only file access — the correct pattern using BOTH allowedTools and disallowedTools
Permission Modes Comparison
Choose the right permission mode for your use case: default, acceptEdits, plan, dontAsk, or bypassPermissions
Block Dangerous Commands (Hooks)
Use PreToolUse hooks to block rm -rf, DROP TABLE, and other destructive commands
AI-Powered Command Validation
Use a prompt-type hook to have a second AI model validate commands before execution
Connect an MCP Server
Add an MCP server inline to extend Claude with external tools (filesystem, database, browser)
MCP with stdio Transport
Connect a local MCP server using stdio — the most common transport for local tools
MCP with SSE Transport
Connect to a remote MCP server using Server-Sent Events over HTTP
Debug MCP Connections
Diagnose and fix MCP server connection failures using init events and manual testing
Install a Plugin
Install and use a plugin from the marketplace or load from a local directory
Create a Plugin
Build a reusable plugin with skills, agents, hooks, and MCP servers
Plugin Hooks
Add lifecycle hooks to a plugin — restricted to http and prompt types for security
MAX_THINKING_TOKENS Tuning
Cap extended thinking token budget for predictable CI costs
Multi-Agent with Worktrees
Run parallel Claude sessions in isolated git worktrees to avoid file conflicts
Create a Custom Agent
Define a specialized agent with custom system prompt, tools, model, and permissions
Agent with Hooks
Attach lifecycle hooks to a custom agent for quality gates and validation
Parallel File Processing
Process files concurrently using subagents that work in their own context windows
Pipeline Orchestration
Build an HTTP API → Queue → Worker pipeline with Claude CLI as the agent runtime
Context Management (Compaction)
Manage the 200K token context window with manual and auto compaction
Proactive Compaction
Compact at ~60% utilization with focus instructions to control what details are preserved
Effort Levels Comparison
Control reasoning depth with --effort: low for speed, max for thoroughness
Budget Cap Behavior
Understand how --max-budget-usd works: checked between turns, not mid-generation
Cap Turns for Safety
Limit agentic conversation turns with --max-turns to prevent runaway loops in automation
Cache Economics Explained
Understand prompt caching tiers and their 90% savings on repeated content
Sonnet vs Opus Decision
Choose the right model: Sonnet is 5x cheaper, Opus is for complex reasoning
Track Cost Per Call
Extract cost and token breakdown from every JSON response for billing and monitoring
Minimize System Prompt Tokens
Reduce MCP overhead and context consumption to maximize the effective 200K window
Batch for Cache Hits
Run similar prompts back-to-back with identical system prompts to maximize cache savings