← All guides

Claude Code CLI Commands: Full Reference (2026)

Every Claude Code CLI flag, slash command, and keyboard shortcut — with usage examples and when to use each.

Claude Code CLI Commands: Full Reference (2026)

Claude Code is primarily a conversational tool, but it has a rich set of CLI flags, in-session slash commands, and keyboard shortcuts that change how it behaves. This is the complete reference.

CLI flags (when launching claude)

These flags are passed when you start Claude Code from the terminal.

Basic flags

Flag Description Example
--help, -h Show help text claude --help
--version, -v Show installed version claude --version
--print, -p Print response and exit (non-interactive) claude -p "Explain this file" < main.ts
--output-format Set output format for -p mode claude -p "..." --output-format json

Model and configuration

Flag Description Example
--model Override the model for this session claude --model claude-sonnet-4-6
--config Path to a custom settings file claude --config ./team-settings.json
--system-prompt Inject a one-off system prompt claude --system-prompt "You are a security auditor"

Context and files

Flag Description Example
--context Add extra context text claude --context "$(cat NOTES.md)"
--allowed-tools Restrict which tools Claude can use claude --allowed-tools Read,Grep
--disallowed-tools Block specific tools claude --disallowed-tools Bash,Write

Permissions and safety

Flag Description Example
--dangerously-skip-permissions Skip all tool-use permission prompts claude --dangerously-skip-permissions
--permission-mode Set permission level (default/bypassPermissions) claude --permission-mode bypassPermissions

Warning: --dangerously-skip-permissions and bypassPermissions disable all confirmation prompts. Use only in trusted automated environments where you have reviewed the task in advance.

Session control

Flag Description Example
--resume Resume a previous session by ID claude --resume abc123def
--continue, -c Continue the most recent session claude -c
--max-turns Limit the number of agentic turns claude --max-turns 5

Non-interactive (pipe) mode

Claude Code can be used in scripts and CI pipelines without an interactive terminal. Use -p with stdin:

# Read a file and ask a question about it
cat main.ts | claude -p "What does this file do? List the exported functions."

# Pipe multiple files
cat src/auth.ts src/middleware.ts | claude -p "Find any security issues in these files."

# Save output to a variable
REVIEW=$(git diff HEAD~1 | claude -p "Review this diff for bugs.")
echo "$REVIEW"

# JSON output for programmatic use
git diff | claude -p "List any breaking changes as JSON" --output-format json

In-session slash commands

Once Claude Code is running, these commands are typed in the conversation input.

Session management

Command Description
/help Show help and available commands
/quit, /exit Exit Claude Code
/clear Clear conversation history (new context)
/compact Compact conversation to reduce token usage
/status Show session info: model, token count, settings
/cost Show token usage and estimated cost for this session

Model switching

Command Description
/model <name> Switch to a different Claude model mid-session
/model claude-haiku-4-5 Switch to Haiku (cheaper, faster)
/model claude-opus-4-7 Switch to Opus (more capable)

Example use case: start a session with Sonnet for planning, switch to Opus with /model claude-opus-4-7 for the complex implementation, then switch back.

Permissions

Command Description
/permissions Show current tool permissions

Memory and context

Command Description
/memory View and manage CLAUDE.md memory files

Custom slash commands

If you have .md files in .claude/commands/ (project-level) or ~/.claude/commands/ (user-level), they appear as slash commands. Example:

~/.claude/commands/ship.md  →  /ship
.claude/commands/qa.md     →  /qa

Run them by typing the command name. Arguments are passed as $ARGUMENTS in the command template.


Keyboard shortcuts (interactive mode)

Shortcut Action
Enter Submit message
Shift+Enter New line without submitting
Up arrow Navigate previous messages
Down arrow Navigate to newer messages
Ctrl+C Interrupt current tool execution
Ctrl+C (twice) Exit Claude Code
Tab Autocomplete slash commands and file paths
Ctrl+R Search command history (in bash-like prompts)

Output format options (--output-format)

Used with -p (non-interactive) mode.

Format Description
text Plain text output (default)
json JSON object with result, cost_usd, session_id, is_error
stream-json JSON Lines stream of events as they arrive

JSON output example:

claude -p "List all TODO comments in this file" --output-format json < main.ts

Returns:

{
  "result": "Found 3 TODO comments:\n1. Line 42: TODO: handle edge case\n2. ...",
  "cost_usd": 0.0023,
  "session_id": "abc123",
  "is_error": false
}

stream-json example:

claude -p "Explain this module" --output-format stream-json < module.ts

Each line is a JSON event:

{"type": "system", "subtype": "init", "session_id": "..."}
{"type": "assistant", "message": {"content": [{"type": "text", "text": "..."}]}}
{"type": "result", "cost_usd": 0.004}

Environment variables

These environment variables control Claude Code's behavior without CLI flags.

Variable Description Example
ANTHROPIC_API_KEY API key (required for API usage) export ANTHROPIC_API_KEY=sk-ant-...
CLAUDE_CODE_MODEL Default model export CLAUDE_CODE_MODEL=claude-sonnet-4-6
CLAUDE_CODE_SUBAGENT_MODEL Model for spawned subagents export CLAUDE_CODE_SUBAGENT_MODEL=claude-haiku-4-5
CLAUDE_CODE_MAX_OUTPUT_TOKENS Cap output tokens export CLAUDE_CODE_MAX_OUTPUT_TOKENS=4096
ANTHROPIC_BASE_URL Override API endpoint For proxies or local LLM servers
NO_COLOR Disable color output export NO_COLOR=1
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC Turn off telemetry and analytics export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1

Common usage patterns

Start a session in a project with context

cd my-project
claude  # Claude Code reads CLAUDE.md and .claude/settings.json automatically

Run a quick task without entering interactive mode

# Summarize the last 10 commits
git log --oneline -10 | claude -p "Summarize these commits as release notes."

# Find security issues in a directory
claude -p "Scan for SQL injection vulnerabilities" --allowed-tools Read,Grep

Resume a specific session

# Get the session ID from /status or --output-format json
claude --resume abc123def456

CI/CD integration

#!/bin/bash
# In your CI pipeline — review PR diff for bugs
DIFF=$(git diff origin/main...HEAD)
REVIEW=$(echo "$DIFF" | claude -p "Review this PR diff. List any bugs or security issues as JSON." --output-format json --dangerously-skip-permissions)
echo "$REVIEW" | jq '.result'

Restrict Claude to read-only mode

# Claude can only read and search — no writes, no bash
claude --allowed-tools Read,Grep,Glob

FAQ

Can I use Claude Code without a terminal? Yes — via the VS Code extension (adds a sidebar panel) or the JetBrains plugin. The slash commands and keyboard shortcuts work the same way. The CLI flags apply when launching via the terminal.

What is the difference between /clear and /compact? /clear starts a completely fresh context — Claude forgets everything from the current session. /compact summarizes the conversation into a shorter form, reducing token usage while preserving key context. Use /compact for long sessions where you want to continue working without losing the thread.

How do I see what tools Claude is using? All tool calls are shown in the conversation output. Use claude --debug to see raw tool input/output for debugging.

Can I disable specific tools permanently? Yes — add disabledTools to your ~/.claude/settings.json:

{
  "disabledTools": ["WebFetch", "WebSearch"]
}

What is the max-turns flag for? --max-turns N limits how many agentic back-and-forth turns Claude takes before stopping. Use it to prevent runaway loops in automated scripts.

Sources

  1. Claude Code CLI documentation — Anthropic, April 2026
  2. Claude Code configuration — April 2026
AI Disclosure: Drafted with Claude Code; verified against Claude Code documentation April 2026.