claude-code-headless
Run Claude Code programmatically without interactive UI. Triggers on: headless, CLI automation, --print, output-format, stream-json, CI/CD, scripting.
Best use case
claude-code-headless is best used when you need a repeatable AI agent workflow instead of a one-off prompt. It is especially useful for teams working in multi. Run Claude Code programmatically without interactive UI. Triggers on: headless, CLI automation, --print, output-format, stream-json, CI/CD, scripting.
Run Claude Code programmatically without interactive UI. Triggers on: headless, CLI automation, --print, output-format, stream-json, CI/CD, scripting.
Users should expect a more consistent workflow output, faster repeated execution, and less time spent rewriting prompts from scratch.
Practical example
Example input
Use the "claude-code-headless" skill to help with this workflow task. Context: Run Claude Code programmatically without interactive UI. Triggers on: headless, CLI automation, --print, output-format, stream-json, CI/CD, scripting.
Example output
A structured workflow result with clearer steps, more consistent formatting, and an output that is easier to reuse in the next run.
When to use this skill
- Use this skill when you want a reusable workflow rather than writing the same prompt again and again.
When not to use this skill
- Do not use this when you only need a one-off answer and do not need a reusable workflow.
- Do not use it if you cannot install or maintain the related files, repository context, or supporting tools.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/claude-code-headless/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How claude-code-headless Compares
| Feature / Agent | claude-code-headless | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Run Claude Code programmatically without interactive UI. Triggers on: headless, CLI automation, --print, output-format, stream-json, CI/CD, scripting.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
ChatGPT vs Claude for Agent Skills
Compare ChatGPT and Claude for AI agent skills across coding, writing, research, and reusable workflow execution.
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
SKILL.md Source
# Claude Code Headless Mode
Run Claude Code from scripts without interactive UI.
## Quick Start
```bash
# Basic headless execution
claude -p "Explain this code" --allowedTools "Read,Grep"
# JSON output for parsing
claude -p "List files" --output-format json
# Continue conversation
claude -p "Start analysis" --output-format json > result.json
session=$(jq -r '.session_id' result.json)
claude --resume "$session" "Now fix the issues"
```
## Essential CLI Options
| Flag | Description |
|------|-------------|
| `-p`, `--print` | Non-interactive (headless) mode |
| `--output-format` | text, json, stream-json |
| `-r`, `--resume` | Resume by session ID |
| `-c`, `--continue` | Continue most recent session |
| `--allowedTools` | Comma-separated allowed tools |
| `--disallowedTools` | Comma-separated denied tools |
| `--mcp-config` | Path to MCP server config JSON |
| `--verbose` | Enable verbose logging |
| `--append-system-prompt` | Add to system prompt |
## Permission Modes
| Mode | Flag | Effect |
|------|------|--------|
| Default | (none) | Prompt for permissions |
| Accept edits | `--permission-mode acceptEdits` | Auto-accept file changes |
| Bypass | `--permission-mode bypassPermissions` | Skip all prompts |
## Output Formats
### Text (default)
```bash
claude -p "Hello"
# Outputs: Human-readable response
```
### JSON
```bash
claude -p "Hello" --output-format json
```
```json
{
"type": "result",
"subtype": "success",
"result": "Hello! How can I help?",
"session_id": "abc123",
"total_cost_usd": 0.001,
"duration_ms": 1234,
"num_turns": 1
}
```
### Stream-JSON
```bash
claude -p "Hello" --output-format stream-json
# Real-time JSONL output for each message
```
## Common Patterns
### Script with tool restrictions
```bash
claude -p "Analyze the codebase" \
--allowedTools "Read,Grep,Glob" \
--disallowedTools "Write,Edit,Bash"
```
### CI/CD integration
```bash
claude -p "Review this PR diff" \
--permission-mode acceptEdits \
--output-format json \
--append-system-prompt "Focus on security issues"
```
### Multi-turn automation
```bash
session=$(claude -p "Start task" --output-format json | jq -r '.session_id')
claude --resume "$session" "Continue with step 2"
claude --resume "$session" "Finalize and report"
```
## Error Handling
```bash
result=$(claude -p "Task" --output-format json)
if [[ $(echo "$result" | jq -r '.is_error') == "true" ]]; then
echo "Error: $(echo "$result" | jq -r '.result')" >&2
exit 1
fi
```
## Official Documentation
- https://code.claude.com/docs/en/headless - Headless mode reference
- https://code.claude.com/docs/en/settings - Settings and permissions
## Additional Resources
- `./references/cli-options.md` - Complete CLI flag reference
- `./references/output-formats.md` - Output format schemas
- `./references/integration-patterns.md` - CI/CD and scripting examples
---
**See Also:** `claude-code-hooks` for automation events, `claude-code-debug` for troubleshootingRelated Skills
running-claude-code-via-litellm-copilot
Use when routing Claude Code through a local LiteLLM proxy to GitHub Copilot, reducing direct Anthropic spend, configuring ANTHROPIC_BASE_URL or ANTHROPIC_MODEL overrides, or troubleshooting Copilot proxy setup failures such as model-not-found, no localhost traffic, or GitHub 401/403 auth errors.
varlock-claude-skill
Secure environment variable management ensuring secrets are never exposed in Claude sessions, terminals, logs, or git commits
linear-claude-skill
Manage Linear issues, projects, and teams
ffuf-claude-skill
Web fuzzing with ffuf
claude-win11-speckit-update-skill
Windows 11 system management
claude-speed-reader
-Speed read Claude's responses at 600+ WPM using RSVP with Spritz-style ORP highlighting
claude-scientific-skills
Scientific research and analysis skills
claude-d3js-skill
Creating interactive data visualisations using d3.js. This skill should be used when creating custom charts, graphs, network diagrams, geographic visualisations, or any complex SVG-based data visua...
claude-ally-health
A health assistant skill for medical information analysis, symptom tracking, and wellness guidance.
claude-settings-audit
Analyze a repository to generate recommended Claude Code settings.json permissions. Use when setting up a new project, auditing existing settings, or determining which read-only bash commands to allow. Detects tech stack, build tools, and monorepo structure.
claude-chrome
Claude in Chrome - browser automation via the official Anthropic extension. Control your logged-in Chrome browser, automate workflows, fill forms, extract data, and run scheduled tasks.
how-to-create-claude-code-skill
A guide to creating Claude Code Skills.