Agent skill · AI & Agents

claude-headless-mode

Guide for using claude CLI in headless mode with --print, output formats, and JSON schema

majiayu000github.com/majiayu000GitHub ↗
claude-codeMIT
Install
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.

Facts
Files in the skill folder: 2
SKILL.md size: 5 KB
Bundled scripts: none
Path: skills/ai-llm/claude-headless-mode/SKILL.md
Open the folder on GitHub →
Where it comes from
Stars: 534
Language: HTML

Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.

From the SKILL.md

# 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

What's inside
Steps it walks through
  1. Basic Usage
  2. Output Formats
  3. Text Output (Default)
  4. JSON Output
  5. Stream JSON Output
  6. Structured Output with JSON Schema
  7. Schema Examples
  8. Common Options
  9. Permission Modes
  10. Examples
  11. CI/CD Integration
  12. Batch Processing
  13. Fresh Context Task Execution
  14. Notes
Ships with 1 file
  • metadata.json
Commands it runs
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
More from claude-skill-registry
All skills →
About this skill
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.

Keep going