claude-code-automation
Run Claude Code programmatically in headless mode or via bidirectional stream-json protocol. Use when building agents, automating Claude, running headless Claude, implementing multi-turn conversations, or integrating Claude CLI into applications.
npx skills add majiayu000/claude-skill-registry --skill claude-code-automation --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 Code Automation This skill covers running Claude Code programmatically - either one-shot with `--print` or multi-turn with the bidirectional stream-json protocol. ## Quick Reference | Mode | Use Case | Key Flags | |------|----------|-----------| | Headless (`--print`) | One-shot tasks, background agents | `--print --verbose --output-format stream-json` | | Bidirectional | Multi-turn conversations, persistent sessions | `--input-format stream-json --output-format stream-json --verbose` | ## Headless Mode (`--print`) For one-shot execution without interactive prompts. ### Essential Flags ```bash claude --print \ --verbose \ # REQUIRED with stream-json --output-format stream-json \ --model sonnet \ --permission-mode bypassPermissions \ # Enable file writes --append-system-prompt "context here" # Inject dynamic context ``` ### Critical Gotchas 1. **`--verbose` is required** with `stream-json` output - without it, Claude exits silently with status 1 2. **File writes silently fail** without `--permission-mode bypassPermissions` 3. **Session hooks don't run** in `--print` mode - no SessionStart/SessionEnd 4. **`--append-system-prompt` is ephemeral** - NOT re-applied on `--resume`
- Quick Reference
- Headless Mode (--print)
- Essential Flags
- Critical Gotchas
- Rust Implementation
- Bidirectional Protocol
- Starting a Session
- Message Types
- Critical Gotcha: controlresponse
- Rust Session Pattern
- Reading JSONL Transcripts
- When to Use Which
claude --print \
claude --input-format stream-json --output-format stream-json --verbose
Extract specific fields with jq
jq -r 'select(.type == "user") | .message.content' file.jsonl | head -20
Python for complex extraction
python3 -c "
import json
for line in open('file.jsonl'):
obj = json.loads(line)
if obj.get('type') == 'user':What does the claude-code-automation skill do?
Run Claude Code programmatically in headless mode or via bidirectional stream-json protocol. Use when building agents, automating Claude, running headless Claude, implementing multi-turn conversations, or integrating Claude CLI into applications.
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill claude-code-automation --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.
