claude-headless-mode
Guide for using claude CLI in headless mode with --print, output formats, and JSON schema
npx skills add majiayu000/claude-skill-registry --skill claude-headless-mode --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# Claude Headless Mode Use `claude -p` (or `--print`) for non-interactive execution in scripts, CI, and automation. ## Basic Usage ```bash # Simple prompt claude -p "Summarize this repo" # With file input claude -p "Review this code" < file.py # Pipe output claude -p "List all functions" | grep "def " ``` ## Output Formats | Format | Flag | Use Case | |--------|------|----------| | Text | `--output-format text` | Human-readable (default) | | JSON | `--output-format json` | Single JSON result | | Stream JSON | `--output-format stream-json --verbose` | Real-time streaming | ### Text Output (Default) ```bash claude -p "What is 2+2?" # Output: 4 ``` ### JSON Output ```bash claude -p "What is 2+2?" --output-format json ``` Returns wrapper with metadata: ```json { "type": "result", "subtype": "success", "result": "4", "duration_ms": 1234, "total_cost_usd": 0.01, "session_id": "...", "structured_output": null } ``` Extract just the result: ```bash claude -p "What is 2+2?" --output-format json | jq -r '.result' ``` ### Stream JSON Output ```bash claude -p "Long analysis" --output-format stream-json --verbose ``` - Streams newline-delimited JSON as execution progresses - Shows tool calls, m
- Basic Usage
- Output Formats
- Text Output (Default)
- JSON Output
- Stream JSON Output
- Structured Output with JSON Schema
- Schema Examples
- Common Options
- Permission Modes
- Examples
- CI/CD Integration
- Batch Processing
- Fresh Context Task Execution
- Notes
Simple prompt claude -p "Summarize this repo" With file input claude -p "Review this code" < file.py Pipe output claude -p "List all functions" | grep "def " claude -p "What is 2+2?" claude -p "What is 2+2?" --output-format json claude -p "What is 2+2?" --output-format json | jq -r '.result' claude -p "Long analysis" --output-format stream-json --verbose
What does the claude-headless-mode skill do?
Guide for using claude CLI in headless mode with --print, output formats, and JSON schema
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill claude-headless-mode --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
