claude-code-master
Teaches agents to use Claude Code CLI in headless print mode — code generation, file editing, codebase Q&A, git workflows, and multi-turn coding tasks
Claude Code Master
Use Claude Code CLI (claude) as a sub-agent for coding tasks — code generation, refactoring, codebase analysis, git workflows, and file editing. Always use print mode (-p) for non-interactive execution.
When this applies
- Agent needs to write, edit, or refactor code
- Agent needs to analyze or answer questions about a codebase
- Agent needs to perform git operations (commits, PRs, reviews)
- Agent needs a second AI opinion on code quality or architecture
Self-Help
Run claude --help for the full command list.
Run claude -p --help for print mode flags.
Use --verbose to debug issues.
Process
- Set
ANTHROPIC_API_KEYin env before first use - Use
claude -p "prompt"for single-shot tasks - Pipe file content when context is needed:
cat file.py | claude -p "review this" - Use
--output-format jsonwhen parsing results programmatically - Use
--max-turnsand--max-budget-usdto bound cost and runtime - Chain with other tools:
claude -p "write tests for auth.py" > tests/test_auth.py
Essential Commands
Single-shot (print mode)
claude -p "explain what this project does"
claude -p "add error handling to src/api.py"
claude -p --model sonnet "quick question about this code"
claude -p --model opus "complex refactoring task"
With input piping
cat src/main.py | claude -p "find bugs in this code"
git diff HEAD~3 | claude -p "summarize these changes"
cat error.log | claude -p "diagnose this error"
Structured output
claude -p --output-format json "list all API endpoints in this project"
claude -p --json-schema '{"type":"object","properties":{"files":{"type":"array","items":{"type":"string"}}}}' "which files need updating"
Cost control
claude -p --max-turns 3 "quick fix for the typo in README"
claude -p --max-budget-usd 0.50 "refactor the auth module"
Custom system prompt
claude -p --system-prompt "You are a security auditor" "review this codebase for vulnerabilities"
claude -p --append-system-prompt "Always use TypeScript strict mode" "add types to utils.js"
Scoped tools
claude -p --tools "Read" "explain the architecture"
claude -p --tools "Bash,Read,Edit" "fix the failing test"
Decision Rules
- Quick question or small fix →
claude -p "prompt"(single shot) - Need specific model → add
--model sonnetor--model opus - Parsing output in script → add
--output-format json - Expensive task → set
--max-budget-usdand--max-turns - Security-sensitive code → add
--system-prompt "You are a security auditor" - Only reading, no edits → use
--tools "Read"to restrict capabilities - Multiple related tasks → pipe output between calls, don't try to do everything in one prompt
Do
- Always use
-p(print mode) — interactive mode blocks the agent - Set
--max-budget-usdfor open-ended tasks to prevent runaway costs - Pipe relevant context in rather than relying on codebase discovery for speed
- Use
--model sonnetfor simple tasks to save cost,opusfor complex reasoning - Use
--output-format jsonwhen downstream processing is needed - Restrict tools with
--toolswhen the task only needs reading or specific capabilities
Don't
- Never run
claudewithout-pflag (blocks on interactive input) - Never skip
--max-budget-usdon open-ended tasks (unbounded API spend) - Never pipe secrets or credentials into claude (they appear in logs)
- Never use
--dangerously-skip-permissions(bypasses safety checks) - Never assume claude modified files — verify with
catorgit diffafter