Usage Modes
Interactive Mode
Start a conversation with Claude in your terminal:
Welcome to Claude Code! Type your message...
> explain the architecture of this project
Interactive mode maintains conversation context. Claude remembers previous messages, can reference earlier work, and builds on context throughout the session.
One-Shot Mode
Pass a prompt as an argument for a single response:
The main function in src/index.ts initializes the Hono web server...
One-shot mode runs the prompt, outputs the response, and exits. No persistent session.
Piped Input Mode
Pipe data into Claude as context:
$ cat error.log | claude "what caused this crash?"
$ curl -s api.example.com/users | claude "generate TypeScript types for this JSON"
Resume Mode
Continue a previous conversation:
$ claude --resume abc123 # Resume specific session ID
CLI Flags Reference
| Flag | Description |
|---|---|
| --model <id> | Model to use: claude-sonnet-4-6 (default), claude-opus-4-6, claude-haiku-4-5 |
| --plan | Plan mode: Claude proposes changes, you approve before execution |
| --accept-edits | Auto-approve file edits without prompting |
| --dangerously-skip-permissions | Skip all permission checks (only use in sandboxed environments) |
| --output-format <fmt> | Output format: text (default), json, stream-json |
| --max-turns <n> | Maximum number of agentic turns before stopping |
| --resume [id] | Resume a previous conversation (latest or by ID) |
| --version | Print version number and exit |
| --help | Show help message |
| --verbose | Enable verbose logging for debugging |
| --no-color | Disable colored output (useful for log files) |
Piping & Input
Claude Code supports standard Unix piping patterns:
Input Piping (stdin)
$ cat src/auth.ts | claude "find security issues"
# Pipe git diff
$ git diff HEAD~3..HEAD | claude "summarize changes"
# Pipe command output
$ npm test 2>&1 | claude "fix the failing tests"
# Pipe multiple files
$ cat src/api/*.ts | claude "generate OpenAPI spec for these endpoints"
Output Piping (stdout)
$ claude "write a README for this project" > README.md
# Chain with other commands
$ claude --output-format json "list all API endpoints" | jq '.endpoints'
# Pipe to clipboard (macOS)
$ claude "write a git commit message for my staged changes" | pbcopy
Output Formats
Text (Default)
This function takes a user ID and returns...
JSON
{"text":"The src/ directory contains...","cost":{"input":1234,"output":567}}
Stream JSON
Newline-delimited JSON events for real-time processing:
{"type":"text","text":"I'll start by..."}
{"type":"tool_use","tool":"Read","input":{"path":"src/module.ts"}}
{"type":"tool_result","tool":"Read","result":"..."}
{"type":"text","text":"Now I'll edit..."}
When building automation around Claude Code, use --output-format json for parseable output you can process with jq or your programming language.
Slash Commands
In interactive mode, use slash commands for quick actions:
| Command | Description |
|---|---|
| /help | Show available commands |
| /compact | Compress conversation to free context window |
| /clear | Clear conversation history |
| /doctor | Check Claude Code configuration and health |
| /model <id> | Switch model mid-conversation |
| /cost | Show token usage and cost for this session |
| /fast | Toggle fast output mode (same model, faster output) |
You can also create custom slash commands for your project.
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
| Ctrl+C | Cancel current operation / exit |
| Ctrl+L | Clear the screen |
| Up/Down | Navigate prompt history |
| Esc | Cancel current input / interrupt Claude |
| Tab | Accept autocomplete suggestion |
Environment Variables
| Variable | Description |
|---|---|
| ANTHROPIC_API_KEY | Your Anthropic API key (required for API pricing) |
| ANTHROPIC_BASE_URL | Custom API endpoint (for proxies, enterprise) |
| ANTHROPIC_MAX_SPEND | Monthly spending cap in USD |
| CLAUDE_CODE_MODEL | Default model (overridden by --model flag) |
| CLAUDE_CODE_MAX_TURNS | Default max turns |
| NO_COLOR | Disable colored output when set |
Scripting & Automation
Shell Script Example
# Auto-review all staged changes before committing
REVIEW=$(git diff --cached | claude --output-format text \
"Review these staged changes. Output LGTM if no issues, or list problems.")
if echo "$REVIEW" | grep -q "LGTM"; then
echo "Review passed! Committing..."
git commit
else
echo "Issues found:"
echo "$REVIEW"
exit 1
fi
Batch Processing
$ for f in src/components/*.tsx; do
claude "add accessibility attributes to $f"
done
# Generate docs for all API routes
$ claude "find all API routes and generate markdown documentation" > docs/api.md
Power User Tips
- Use
/compactregularly in long sessions to free up context window space - Switch models with
/model— use Haiku for quick questions, Opus for complex architecture - Reference files by path — "fix the bug in
src/auth.ts:42" is more efficient than "find the auth bug" - Use one-shot for quick tasks —
claude "what does this error mean?"is faster than starting an interactive session - Pipe diffs for reviews —
git diff | claude "review"is the fastest way to get code review - Set model in env —
export CLAUDE_CODE_MODEL=claude-haiku-4-5for a cheap default, override with--modelwhen needed - Create shell aliases —
alias cr='git diff | claude "review these changes"'
Frequently Asked Questions
How do I check my Claude Code version?
Run claude --version. To update: npm update -g @anthropic-ai/claude-code.
Can I use Claude Code without an interactive terminal?
Yes. Use one-shot mode with --output-format json for scriptable, non-interactive usage. This works in cron jobs, CI/CD, and automated pipelines.
How do I increase the context window?
The context window is determined by the model. Use /compact to compress conversation history. Start new sessions for unrelated tasks. Keep CLAUDE.md concise.
Can I customize the terminal prompt?
Claude Code uses its own prompt inside the interactive session. Your terminal prompt (PS1) is used normally outside Claude Code sessions.