Claude Code CLI: Commands, Flags & Terminal Guide

The complete reference for the Claude Code command-line interface. Covers interactive mode, one-shot commands, piping, output formats, all flags, and advanced terminal configuration.

Updated Feb 2026 8 min read Intermediate

Usage Modes

Interactive Mode

Start a conversation with Claude in your terminal:

$ claude
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:

$ claude "what does the main function do?"
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:

$ git diff | claude "review these changes"
$ 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 # Resume most recent session
$ claude --resume abc123 # Resume specific session ID

CLI Flags Reference

FlagDescription
--model <id>Model to use: claude-sonnet-4-6 (default), claude-opus-4-6, claude-haiku-4-5
--planPlan mode: Claude proposes changes, you approve before execution
--accept-editsAuto-approve file edits without prompting
--dangerously-skip-permissionsSkip 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)
--versionPrint version number and exit
--helpShow help message
--verboseEnable verbose logging for debugging
--no-colorDisable colored output (useful for log files)

Piping & Input

Claude Code supports standard Unix piping patterns:

Input Piping (stdin)

# Pipe file contents
$ 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)

# Save Claude's response to a file
$ 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)

$ claude "explain this function"
This function takes a user ID and returns...

JSON

$ claude --output-format json "list the files in src/"
{"text":"The src/ directory contains...","cost":{"input":1234,"output":567}}

Stream JSON

Newline-delimited JSON events for real-time processing:

$ claude --output-format stream-json "refactor this module"
{"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..."}
Use JSON output for scripts

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:

CommandDescription
/helpShow available commands
/compactCompress conversation to free context window
/clearClear conversation history
/doctorCheck Claude Code configuration and health
/model <id>Switch model mid-conversation
/costShow token usage and cost for this session
/fastToggle fast output mode (same model, faster output)

You can also create custom slash commands for your project.

Keyboard Shortcuts

ShortcutAction
Ctrl+CCancel current operation / exit
Ctrl+LClear the screen
Up/DownNavigate prompt history
EscCancel current input / interrupt Claude
TabAccept autocomplete suggestion

Environment Variables

VariableDescription
ANTHROPIC_API_KEYYour Anthropic API key (required for API pricing)
ANTHROPIC_BASE_URLCustom API endpoint (for proxies, enterprise)
ANTHROPIC_MAX_SPENDMonthly spending cap in USD
CLAUDE_CODE_MODELDefault model (overridden by --model flag)
CLAUDE_CODE_MAX_TURNSDefault max turns
NO_COLORDisable colored output when set

Scripting & Automation

Shell Script Example

#!/bin/bash
# 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

# Process multiple files
$ 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

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.

Related Guides