aiskillstore/marketplace / skills/0xdarkmatter/claude-code-headless
claude-code-headless
VerifiedRun Claude Code programmatically without interactive UI. Triggers on: headless, CLI automation, --print, output-format, stream-json, CI/CD, scripting.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 3.2 KB |
| references/cli-options.md | markdown | 4.2 KB |
| references/integration-patterns.md | markdown | 8.3 KB |
| references/output-formats.md | markdown | 4.6 KB |
| skill-report.json | config | 102.5 KB |
references/cli-options.md
View on GitHub# CLI Options Reference
Complete reference for Claude Code CLI flags.
## Core Options
### Input/Output
| Flag | Short | Description |
|------|-------|-------------|
| `--print` | `-p` | Non-interactive mode (required for headless) |
| `--output-format` | | Output format: text, json, stream-json |
| `--verbose` | `-v` | Enable verbose/debug logging |
| `--quiet` | `-q` | Suppress non-essential output |
### Session Management
| Flag | Short | Description |
|------|-------|-------------|
| `--resume` | `-r` | Resume conversation by session ID |
| `--continue` | `-c` | Continue most recent conversation |
| `--session-id` | | Specify session ID for new session |
### Prompt Configuration
| Flag | Description |
|------|-------------|
| `--append-system-prompt` | Append text to system prompt |
| `--prepend-system-prompt` | Prepend text to system prompt |
| `--system-prompt` | Replace entire system prompt |
### Tool Control
| Flag | Description |
|------|-------------|
| `--allowedTools` | Comma-separated list of allowed tools |
| `--disallowedTools` | Comma-separated list of denied tools |
| `--mcp-config` | Path to MCP server configuration JSON |
### Permission Control
| Flag | Description |
|------|-------------|
| `--permission-mode` | Permission handling mode |
Permission modes:
- `default` - Ask for permission (blocks in headless)
- `acceptEdits` - Auto-accept file modifications
- `bypassPermissions` - Skip all permission prompts
### Model Selection
| Flag | Description |
|------|-------------|
| `--model` | Model to use: sonnet, opus, haiku |
## Usage Examples
### Basic Headless
```bash
# Simple query
claude -p "What is 2+2?"
# With file context
cat file.py | claude -p "Explain this code"
# From file
claude -p "$(cat prompt.txt)"
```
### Tool Restrictions
```bash
# Read-only mode
claude -p "Analyze codebase" \
--allowedTools "Read,Grep,Glob,WebFetch,WebSearch" \
--disallowedTools "Write,Edit,Bash,Task"
# Specific tools only
claude -p "Search for bugs" \
--allowedTools "Read,Grep"
```
### Session Continuation
```bash
# Start session, capture ID
result=$(claude -p "Start analysis" --output-format json)
session_id=$(echo "$result" | jq -r '.session_id')
# Continue with context
claude -r "$session_id" "What did you find?"
# Continue most recent
claude -c "Add more details"
```
### System Prompt Modification
```bash
# Add context
claude -p "Review code" \
--append-system-prompt "Focus on security vulnerabilities. Output findings as markdown."
# Full replacement
claude -p "Hello" \
--system-prompt "You are a helpful assistant that only speaks in haiku."
```
### MCP Integration
```bash
# Use MCP servers from config
claude -p "Query the database" \
--mcp-config ./mcp-servers.json
# With specific tools
claude -p "Fetch from GitHub" \
--mcp-config ./mcp-servers.json \
--allowedTools "mcp__github__*"
```
### Debugging
```bash
# Verbose output
claude -p "Debug this" --verbose
# Debug mode (shows internal operations)
claude --debug -p "Analyze"
```
## Input Methods
### Stdin Piping
```bash
# Pipe file content
cat error.log | claude -p "Explain these errors"
# Pipe command output
git diff | claude -p "Review this diff"
# Heredoc
claude -p "$(cat <<EOF
Analyze this data:
- Item 1
- Item 2
EOF
)"
```
### File Input
```bash
# Read prompt from file
claude -p "$(cat prompt.md)"
# With context files
claude -p "Review: $(cat src/main.ts)"
```
## Exit Codes
| Code | Meaning |
|------|---------|
| 0 | Success |
| 1 | General error |
| 2 | Invalid arguments |
## Environment Variables
| Variable | Description |
|----------|-------------|
| `ANTHROPIC_API_KEY` | API key for Claude |
| `CLAUDE_PROJECT_DIR` | Override project directory |
| `NO_COLOR` | Disable colored output |
## Flag Combinations
### CI/CD Pipeline
```bash
claude -p "Run tests and report" \
--permission-mode acceptEdits \
--output-format json \
--allowedTools "Bash,Read,Write"
```
### Security Audit
```bash
claude -p "Security review" \
--allowedTools "Read,Grep,WebSearch" \
--disallowedTools "Write,Edit,Bash" \
--append-system-prompt "Report vulnerabilities in JSON format"
```
### Documentation Generation
```bash
claude -p "Generate API docs" \
--permission-mode acceptEdits \
--allowedTools "Read,Write,Glob" \
--output-format json
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |