Loading...
Loading...
Claude Code CLI usage for automated/headless execution in Daytona sandboxes. Use when running Claude Code commands, configuring authentication, or setting up non-interactive mode.
npx skill4agent add seanchiuai/multishot claude-code-cliSource: Claude Code CLI Reference, Headless Usage
# Native (recommended)
curl -fsSL https://claude.ai/install.sh | bash
# NPM (deprecated)
npm install -g @anthropic-ai/claude-codeclaude --version| Variable | Description | Priority |
|---|---|---|
| API key from console.anthropic.com | High (overrides OAuth) |
| OAuth token for subscription auth | Normal |
ANTHROPIC_API_KEYexport ANTHROPIC_API_KEY="sk-ant-..."
claude -p "your prompt"# On local machine: authenticate normally, then copy token
# Location: ~/.config/claude-code/auth.json
# Transfer to sandbox via environment variable
export CLAUDE_CODE_OAUTH_TOKEN="token-from-auth-json"/status-pclaude -p "your prompt here"| Flag | Description | Example |
|---|---|---|
| Non-interactive mode, exit after response | |
| Continue most recent conversation | |
| Resume specific session | |
| Set model ( | |
| Flag | Description |
|---|---|
| Skip ALL permission prompts (use with caution) |
| Auto-approve specific tools without prompting |
| Block specific tools entirely |
| Start in specific mode (e.g., |
# Allow specific tools (comma-separated)
claude -p "fix the bug" --allowedTools "Read,Edit,Bash"
# Allow with prefix matching (e.g., any git command)
claude -p "commit changes" --allowedTools "Bash(git:*)"
# Disable all tools
claude -p "explain this" --tools ""
# Use only specific tools
claude -p "review code" --tools "Read,Grep,Glob"| Flag | Value | Description |
|---|---|---|
| | Plain text (default) |
| JSON with metadata | |
| Newline-delimited JSON streaming |
# Get JSON output
claude -p "summarize" --output-format json
# Parse with jq
claude -p "summarize" --output-format json | jq -r '.result'
# Structured output with schema
claude -p "list functions" --output-format json \
--json-schema '{"type":"object","properties":{"functions":{"type":"array","items":{"type":"string"}}}}'| Flag | Description |
|---|---|
| Replace entire system prompt |
| Add to default prompt (recommended) |
| Load replacement from file |
| Append from file |
# Append custom instructions (keeps defaults)
claude -p "review this" --append-system-prompt "Focus on security vulnerabilities"
# Replace entire prompt
claude -p "task" --system-prompt "You are a Python expert"| Flag | Description |
|---|---|
| Maximum spend (print mode only) |
| Limit agentic turns (print mode only) |
claude -p "refactor this file" --max-budget-usd 5.00 --max-turns 10# Get session ID from output
session_id=$(claude -p "start review" --output-format json | jq -r '.session_id')
# Resume later
claude -p "continue" --resume "$session_id"
# Continue most recent
claude -p "what was I doing?" --continue# Full automated execution with tool access
ANTHROPIC_API_KEY="sk-ant-..." claude -p "Create a hello world Python script" \
--dangerously-skip-permissions \
--output-format json \
--max-turns 20
# Or with specific tool allowlist
ANTHROPIC_API_KEY="sk-ant-..." claude -p "Fix the bug in auth.py" \
--allowedTools "Read,Edit,Bash,Grep,Glob" \
--output-format json
# With OAuth token instead
CLAUDE_CODE_OAUTH_TOKEN="token..." claude -p "Explain this codebase" \
--dangerously-skip-permissions| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Error (check stderr) |
# Pipe file content
cat src/main.ts | claude -p "explain this code"
# Pipe command output
git diff | claude -p "review these changes"
# Pipe multiple files
cat src/*.ts | claude -p "find security issues"git diff HEAD~1 | claude -p "Review these changes for bugs and improvements" \
--append-system-prompt "Focus on security and performance" \
--output-format jsonclaude -p "Fix the failing test in tests/auth.test.ts" \
--allowedTools "Read,Edit,Bash(npm test:*)" \
--max-turns 15claude -p "Create a REST API endpoint for user registration" \
--dangerously-skip-permissions \
--max-turns 30cat complex-file.ts | claude -p "Explain how this works" --tools """Authentication failed""OAuth token has expired""Invalid API key""Rate limit exceeded""Context length exceeded"/commit-p-p--continue--dangerously-skip-permissions