Use when user asks to leverage claude or claude code to do something (e.g. implement a feature design or review codes, etc)...
You are operating in Claude Code headless mode - a non-interactive automation mode for hands-off task execution.
Before using this skill, ensure Claude Code CLI is installed and configured:
Installation verification:
claude --version
First-time setup: If not installed, guide the user to install Claude Code CLI with command npm install -g @anthropic-ai/claude-code.
Claude Code uses permission modes to control what operations are permitted. Set via --permission-mode flag:
| Mode | Description |
|---|---|
default |
Standard behavior - prompts for permission on first use of each tool |
acceptEdits |
Automatically accepts file edit permissions for the session (Default for this skill) |
plan |
Plan Mode - Claude can analyze but not modify files or execute commands |
bypassPermissions |
Skips all permission prompts (requires safe environment - see warning below) |
Accept Edits Mode (--permission-mode acceptEdits) - Default
Default Mode (--permission-mode default)
Plan Mode (--permission-mode plan)
Bypass Permissions Mode (--permission-mode bypassPermissions)
--allowedTools to restrict specific tools for safetyNote: The following commands are based on the official Claude Code headless mode documentation.
Use the --print (or -p) flag to run in non-interactive mode:
claude -p "analyze the codebase structure and explain the architecture"
Control which tools Claude can use with --allowedTools and --disallowedTools:
# Allow specific tools
claude -p "stage my changes and write commits" \
--allowedTools "Bash,Read" \
--permission-mode acceptEdits
# Allow multiple tools (space-separated)
claude -p "implement the feature" \
--permission-mode acceptEdits \
--allowedTools Bash Read Write Edit
# Allow tools with restrictions (comma-separated string)
claude -p "run tests" \
--permission-mode acceptEdits \
--allowedTools "Bash(npm test),Read"
# Disallow specific tools
claude -p "analyze the code" \
--disallowedTools "Bash,Write"
Control how permissions are handled:
# Accept file edits automatically (recommended for programming)
claude -p "implement the user authentication feature" \
--permission-mode acceptEdits \
--allowedTools "Bash,Read,Write,Edit"
# Combine with allowed tools for safe automation
claude -p "fix the bug in login flow" \
--permission-mode acceptEdits \
--allowedTools "Read,Write,Edit,Bash(npm test)"
claude -p "explain file src/components/Header.tsx"
# Output: Plain text response
Returns structured data including metadata:
claude -p "how does the data layer work?" --output-format json
Response format:
{
"type": "result",
"subtype": "success",
"total_cost_usd": 0.003,
"is_error": false,
"duration_ms": 1234,
"duration_api_ms": 800,
"num_turns": 6,
"result": "The response text here...",
"session_id": "abc123"
}
Streams each message as it is received:
claude -p "build an application" \
--permission-mode acceptEdits \
--output-format stream-json
Each conversation begins with an initial init system message, followed by user and assistant messages, followed by a final result system message with stats.
For multi-turn conversations, you can resume or continue sessions:
# Continue the most recent conversation
claude --continue --permission-mode acceptEdits "now refactor this for better performance"
# Resume a specific conversation by session ID
claude --resume 550e8400-e29b-41d4-a716-446655440000 \
--permission-mode acceptEdits "update the tests"
# Resume in non-interactive mode
claude --resume 550e8400-e29b-41d4-a716-446655440000 -p \
--permission-mode acceptEdits "fix all linting issues"
# Short flags
claude -c --permission-mode acceptEdits "continue with next step"
claude -r abc123 -p --permission-mode acceptEdits "implement the next feature"
Append custom instructions to the system prompt:
claude -p "review this code" \
--append-system-prompt "Focus on security vulnerabilities and performance issues"
Load MCP servers from a JSON configuration file:
claude -p "analyze the metrics" \
--mcp-config monitoring-tools.json \
--allowedTools "mcp__datadog,mcp__prometheus"
Enable verbose output for debugging:
claude -p "debug this issue" --verbose
Combine multiple flags for complex scenarios:
# Full automation with JSON output
claude -p "implement authentication and output results" \
--permission-mode acceptEdits \
--allowedTools "Bash,Read,Write,Edit" \
--output-format json
# Multi-turn with custom instructions
session_id=$(claude -p "start code review" --output-format json | jq -r '.session_id')
claude -r "$session_id" -p "now check for security issues" \
--permission-mode acceptEdits \
--append-system-prompt "Be thorough with OWASP top 10"
# Streaming with MCP tools
claude -p "deploy the application" \
--permission-mode acceptEdits \
--output-format stream-json \
--mcp-config deploy-tools.json \
--allowedTools "mcp__kubernetes,mcp__docker"
Check exit codes and stderr for errors
Use timeouts for long-running operations:
timeout 300 claude -p "$complex_prompt" --permission-mode acceptEdits || echo "Timed out after 5 minutes"
Respect rate limits when making multiple requests by adding delays between calls
Only pause for user input when encountering:
For all other decisions, proceed autonomously using best judgment.
Always conclude with a structured summary:
✓ Task completed successfully
Changes made:
- [List of files modified/created]
- [Key code changes]
Results:
- [Metrics: lines changed, files affected, tests run]
- [What now works that didn't before]
Verification:
- [Tests run, checks performed]
Next steps (if applicable):
- [Suggestions for follow-up tasks]
User: "Count the lines of code in this project by language" Command:
claude -p "count the total number of lines of code in this project, broken down by language" \
--allowedTools "Read,Bash(find),Bash(wc)"
Action: Search all files, categorize by extension, count lines, report totals
User: "Fix the authentication bug in the login flow" Command:
claude -p "fix the authentication bug in the login flow" \
--permission-mode acceptEdits \
--allowedTools "Bash,Read,Write,Edit"
Action: Find the bug, implement fix, run tests
User: "Implement dark mode support for the UI" Command:
claude -p "add dark mode support to the UI with theme context and style updates" \
--permission-mode acceptEdits \
--allowedTools "Bash,Read,Write,Edit"
Action: Identify components, add theme context, update styles, test in both modes
User: "Update all imports from old-lib to new-lib" Command:
claude -p "update all imports from old-lib to new-lib across the entire codebase" \
--permission-mode acceptEdits \
--allowedTools "Read,Write,Edit,Bash(npm test)"
Action: Find all imports, perform replacements, verify syntax, run tests
User: "Analyze security vulnerabilities and output as JSON" Command:
claude -p "analyze the codebase for security vulnerabilities and provide a detailed report" \
--allowedTools "Read,Grep" \
--output-format json
Action: Scan code, identify issues, output structured JSON with findings
User: "Investigate the payment API errors" Command:
claude -p "Incident: Payment API returning 500 errors (Severity: high)" \
--append-system-prompt "You are an SRE expert. Diagnose the issue, assess impact, and provide immediate action items." \
--output-format json \
--allowedTools "Bash,Read,mcp__datadog" \
--mcp-config monitoring-tools.json
Action: Analyze logs, identify root cause, provide action items
User: "Review the current PR for security issues" Command:
gh pr diff | claude -p \
--append-system-prompt "You are a security engineer. Review this PR for vulnerabilities, insecure patterns, and compliance issues." \
--output-format json \
--allowedTools "Read,Grep"
Action: Analyze diff, identify security issues, output structured report
User: "Review multiple aspects of a contract" Commands:
# Start session and capture ID
session_id=$(claude -p "start legal review session" --output-format json | jq -r '.session_id')
# Review in multiple steps
claude -r "$session_id" -p "review contract.pdf for liability clauses" \
--permission-mode acceptEdits
claude -r "$session_id" -p "check compliance with GDPR requirements" \
--permission-mode acceptEdits
claude -r "$session_id" -p "generate executive summary of risks" \
--permission-mode acceptEdits
Action: Multi-turn analysis with context preservation
When errors occur:
If execution is interrupted:
claude --resume <session_id> -p "continue" --permission-mode acceptEdits