Claude CLI Skill
Run Claude Code CLI to leverage Anthropic's models via OAuth authentication (no API tokens required).
When to Use
- Complex coding tasks that benefit from extended context
- Multi-file code generation or refactoring
- Research and analysis requiring deep reasoning
- Tasks that would benefit from Claude's thinking mode
- Delegating substantial work to a sub-process
Quick Start
One-shot query (non-interactive)
echo "Your prompt here" | claude -p
With specific model
echo "Complex task requiring Opus" | claude -p --model opus
echo "Standard task with Sonnet" | claude -p --model sonnet
Note: Piping the prompt via stdin is more reliable than passing it as an argument.
With thinking/extended reasoning
claude -p --model opus "Analyze this complex problem"
JSON output (for parsing)
claude -p --output-format json "Your prompt"
Stream JSON (real-time)
claude -p --output-format stream-json "Your prompt"
Key Options
| Option | Description |
|---|---|
-p, --print | Non-interactive mode, print and exit |
--model <model> | Model alias: sonnet, opus, or full name |
--output-format <fmt> | text (default), json, stream-json |
--system-prompt <prompt> | Custom system prompt |
--max-budget-usd <amount> | Spending limit for the call |
--allowedTools <tools> | Restrict available tools |
--dangerously-skip-permissions | Skip permission checks (sandboxed use only) |
Working with Files
Claude CLI can read and write files in its working directory:
# Analyze a file
claude -p "Review this code for bugs" < myfile.py
# Work in a specific directory
cd /path/to/project && claude -p "Summarize this codebase"
# Give access to additional directories
claude -p --add-dir /other/path "Work with files in both locations"
For Sub-Agent Delegation
When spawning Claude CLI for background work:
# Run with timeout protection
timeout 300 claude -p --model sonnet "Complete this task..." 2>&1
# Capture structured output
claude -p --output-format json "Generate a report" > result.json
Script: Run Claude Task
Use the bundled script for reliable sub-agent execution:
node {baseDir}/scripts/run-claude-task.cjs "Your task prompt" [--model sonnet|opus] [--timeout 300]
The script handles:
- Timeout protection
- Error capture and formatting
- Clean output for parsing
- Exit code propagation
Authentication
Claude CLI uses OAuth by default (linked to your Anthropic account). No API key configuration needed.
To check auth status:
claude --version
If not authenticated, run interactively once:
claude
Follow the OAuth prompts to link your account.
Model Selection
| Alias | Best For |
|---|---|
sonnet | Fast, capable, cost-effective. Default choice. |
opus | Complex reasoning, nuanced tasks, extended thinking. |
Tips
- Always use
-pfor non-interactive/scripted use - Set timeouts for long-running tasks to prevent hangs
- Use
--output-format jsonwhen you need to parse results - Pipe input for file analysis:
cat file.py | claude -p "Review this" - Working directory matters — Claude sees files relative to cwd
Limitations
- OAuth requires initial interactive setup
- Rate limits apply based on your Anthropic account tier
- Some operations may timeout on very complex tasks
- Interactive features (like file editing confirmations) don't work with
-p