diff --git a/CLAUDE.md b/CLAUDE.md index 423c1ac400..06a5c3521d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -255,6 +255,79 @@ npx claude-flow@v3alpha security scan --depth full npx claude-flow@v3alpha performance benchmark --suite all ``` +## Headless Background Instances (claude -p) + +Use `claude -p` (print/pipe mode) to spawn headless Claude instances for parallel background work. These run non-interactively and return results to stdout. + +### Basic Usage + +```bash +# Single headless task +claude -p "Analyze the authentication module for security issues" + +# With model selection +claude -p --model haiku "Format this config file" +claude -p --model opus "Design the database schema for user management" + +# With output format +claude -p --output-format json "List all TODO comments in src/" +claude -p --output-format stream-json "Refactor the error handling in api.ts" + +# With budget limits +claude -p --max-budget-usd 0.50 "Run comprehensive security audit" + +# With specific tools allowed +claude -p --allowedTools "Read,Grep,Glob" "Find all files that import the auth module" + +# Skip permissions (sandboxed environments only) +claude -p --dangerously-skip-permissions "Fix all lint errors in src/" +``` + +### Parallel Background Execution + +```bash +# Spawn multiple headless instances in parallel +claude -p "Analyze src/auth/ for vulnerabilities" & +claude -p "Write tests for src/api/endpoints.ts" & +claude -p "Review src/models/ for performance issues" & +wait # Wait for all to complete + +# With results captured +SECURITY=$(claude -p "Security audit of auth module" &) +TESTS=$(claude -p "Generate test coverage report" &) +PERF=$(claude -p "Profile memory usage in workers" &) +wait +echo "$SECURITY" "$TESTS" "$PERF" +``` + +### Session Continuation + +```bash +# Start a task, resume later +claude -p --session-id "abc-123" "Start analyzing the codebase" +claude -p --resume "abc-123" "Continue with the test files" + +# Fork a session for parallel exploration +claude -p --resume "abc-123" --fork-session "Try approach A: event sourcing" +claude -p --resume "abc-123" --fork-session "Try approach B: CQRS pattern" +``` + +### Key Flags + +| Flag | Purpose | +|------|---------| +| `-p, --print` | Non-interactive mode, print and exit | +| `--model ` | Select model (haiku, sonnet, opus) | +| `--output-format ` | Output: text, json, stream-json | +| `--max-budget-usd ` | Spending cap per invocation | +| `--allowedTools ` | Restrict available tools | +| `--append-system-prompt` | Add custom instructions | +| `--resume ` | Continue a previous session | +| `--fork-session` | Branch from resumed session | +| `--fallback-model ` | Auto-fallback if primary overloaded | +| `--permission-mode ` | acceptEdits, bypassPermissions, plan, etc. | +| `--mcp-config ` | Load MCP servers from JSON | + ## Available Agents (60+ Types) ### Core Development diff --git a/agents/architect.yaml b/agents/architect.yaml index 4b7bf4af0a..14005dfa90 100644 --- a/agents/architect.yaml +++ b/agents/architect.yaml @@ -8,4 +8,4 @@ capabilities: optimizations: - context-caching - memory-persistence -createdAt: "2026-02-02T04:24:59.852Z" +createdAt: "2026-02-02T04:35:20.324Z" diff --git a/agents/coder.yaml b/agents/coder.yaml index 9039a0f96c..bf7072e128 100644 --- a/agents/coder.yaml +++ b/agents/coder.yaml @@ -8,4 +8,4 @@ capabilities: optimizations: - flash-attention - token-reduction -createdAt: "2026-02-02T04:24:59.851Z" +createdAt: "2026-02-02T04:35:20.324Z" diff --git a/agents/reviewer.yaml b/agents/reviewer.yaml index 9f9d89e1aa..6aca6a0f40 100644 --- a/agents/reviewer.yaml +++ b/agents/reviewer.yaml @@ -7,4 +7,4 @@ capabilities: - best-practices optimizations: - incremental-analysis -createdAt: "2026-02-02T04:24:59.852Z" +createdAt: "2026-02-02T04:35:20.324Z" diff --git a/agents/security-architect.yaml b/agents/security-architect.yaml index 4aed6963ac..65e98059c6 100644 --- a/agents/security-architect.yaml +++ b/agents/security-architect.yaml @@ -7,4 +7,4 @@ capabilities: - security-review optimizations: - pattern-matching -createdAt: "2026-02-02T04:24:59.852Z" +createdAt: "2026-02-02T04:35:20.324Z" diff --git a/agents/tester.yaml b/agents/tester.yaml index 73679983a0..779fe0cb02 100644 --- a/agents/tester.yaml +++ b/agents/tester.yaml @@ -7,4 +7,4 @@ capabilities: - coverage optimizations: - parallel-execution -createdAt: "2026-02-02T04:24:59.852Z" +createdAt: "2026-02-02T04:35:20.324Z"