Skip to main content

Claude Code Command Reference

A practical reference for Claude Code CLI commands — from installation and session management to slash commands, keyboard shortcuts, permission modes, and advanced automation patterns.

Installation & Authentication

Start here. Before you can do anything else, you need Claude Code installed and your Anthropic account authenticated.

Command What When
claude install Migrate from the npm package to the native binary You installed via npm and want the faster, standalone version
claude doctor Verify that your installation and system config are healthy Something feels off — wrong model, missing tools, auth errors
claude auth login Authenticate or switch to a different Anthropic account First-time setup, or switching between personal and work accounts
claude auth status Show which account is currently active Confirming you’re logged into the right account before billing-sensitive work
claude auth logout Clear stored credentials Handing off a machine or revoking access
claude update Manually pull the latest Claude Code version Auto-updater is disabled, or you want a specific release right now
# First-time setup on a new machine
claude auth login
claude doctor
# ✓ Authentication: OK
# ✓ Model access: claude-sonnet-4-6
# ✓ Bash tool: available

# Check who you're logged in as
claude auth status
# Logged in as: you@example.com (Pro plan)

# Switch accounts
claude auth logout
claude auth login

Launching Sessions

Authenticated? Now open a session. The launch command determines the context Claude starts with — whether it’s a fresh REPL, a resumed conversation, or a session linked to a pull request.

Command What When
claude Open an interactive REPL in the current directory Day-to-day coding help, exploration, or conversation
claude -p "prompt" Run a single query and exit without opening a REPL Scripting, CI pipelines, or one-off answers from the terminal
claude -c Resume the most recent session Picking up exactly where you left off after closing the terminal
claude -r SESSION_ID Resume a specific session by its ID Returning to a session that isn’t the most recent one
claude --resume NAME Resume a session by its name You named sessions deliberately and want to jump to the right one
claude -n "name" Start a new session with a given name Organising parallel work streams so sessions are easy to find later
claude --from-pr #123 Link a new session to a GitHub, GitLab, or Bitbucket PR Reviewing or iterating on a pull request with full PR context loaded
# Open a session in your current project
cd ~/projects/my-app
claude

# Ask a question and return to the shell immediately
claude -p "What does the -u flag do in useEffect?"

# Resume your last session (great after a terminal restart)
claude -c

# Start a named session for a long-running feature
claude -n "auth-refactor"

# Link to a PR for context-aware review
claude --from-pr #84

Slash Commands — Basic

Inside a running session, slash commands control Claude’s behavior in real time. These are the ones you’ll reach for in every session — checking status, managing cost, and switching models or effort levels.

Command What When
/status Show the current model, account tier, and active settings You’re unsure which model you’re on or what’s loaded
/cost Display token usage and estimated cost for this session Checking spend before a long agentic task, or after an expensive run
/model MODEL Switch the model mid-session The task changed — swap to Haiku for speed or Opus for hard reasoning
/effort LEVEL Adjust reasoning depth: low, medium, high, xhigh, max Dial up for architecture decisions, dial down for formatting fixes
/compact Summarize prior context and free up tokens The session is getting long and responses are slowing down
/rename NAME Rename the current session You started without a name and want to file it properly for later resumption
/exit End the session cleanly Done for now — cleaner than Ctrl-D when you want to confirm nothing is running
# Check what you're running on
/status
# Model: claude-sonnet-4-6 | Plan: Pro | Session: auth-refactor

# See cost before approving a big agentic sweep
/cost
# Input: 42,310 tokens | Output: 8,204 tokens | ~$0.14

# Switch to the strongest model for a hard debugging session
/model opus

# Switch back to a fast model for a quick search
/model haiku

# Crank up reasoning for a system design question
/effort max

# Compress context when the session grows large
/compact

Slash Commands — Intermediate

Once you’re comfortable with the basics, these commands give you more control over the session flow — entering planning mode before Claude touches anything, running code reviews, and rewinding when it goes off-track.

Command What When
/plan [DESCRIPTION] Enter read-only planning mode — Claude analyzes but does not modify files You want Claude to think through an approach before touching anything
/code-review Review the current branch diff for bugs and inefficiencies Before opening a PR or merging to main
/code-review --fix Review the diff and automatically apply the suggested fixes You trust the review and want changes applied immediately
/simplify Cleanup-only review — no bug hunting, just reduce complexity The code works but feels sprawling; you want it tightened up
/security-review Analyze the current branch for security issues Before shipping auth changes, API endpoints, or anything that touches user data
/recap Summarize what happened in a prior session context You resumed an old session and need to re-orient quickly
/rewind Step back in the conversation Claude went down the wrong path — undo and try a different approach
/cd DIRECTORY Move the session’s working directory You opened Claude in the repo root but the relevant code is in a subdirectory
# Design first, code later
/plan "refactor the auth module to use JWTs instead of sessions"
# Claude outlines the approach, lists files to change, flags risks — without touching anything

# Review before raising a PR
/code-review
# Finds: missing null check in UserRepository.swift:42

# Review and auto-fix in one shot
/code-review --fix

# Security check after adding an API endpoint
/security-review

# Step back when Claude misunderstands the requirement
/rewind

Slash Commands — Advanced

For larger tasks: delegate an entire feature with /loop, run cloud-powered reviews with /ultrareview, orchestrate parallel sub-agents, and manage integrations via the plugin marketplace.

Command What When
/ultrareview [PR#] Run a deep multi-agent code review in the cloud High-stakes PRs where you want maximum coverage — broader than /code-review
/loop Enter continuous improvement mode — Claude iterates until the task is done Delegating an entire feature or bug fix and walking away
/fast Toggle faster output (Opus 4.6 only) You’re on Opus and want quicker streaming without switching models
/workflows Orchestrate multi-agent workflows Breaking a large task into parallel sub-agents for efficiency
/focus Enter focus mode to reduce noise Long sessions where you want Claude to stay on task without tangents
/channels Configure permission relay channels Setting up team-wide permission sharing for agentic tasks
/plugin Access the plugin marketplace Installing or managing integrations like GitHub, Linear, or Slack
/reload-skills Refresh skill definitions without restarting You updated a skill file and want the changes live immediately
/less-permission-prompts Suggest an allowlist of safe operations for the current project Tired of approving git status and ls — let Claude propose what to auto-allow
# Deep review of an open PR (by PR number)
/ultrareview 84

# Hand off a full feature and let Claude iterate
/loop "implement dark mode support across all screens"

# Run a multi-agent workflow for parallel subtasks
/workflows

# Stop approving routine read-only commands
/less-permission-prompts
# Suggests: Bash(git status), Bash(ls), Read(**) → add to .claude/settings.json

Keyboard Shortcuts

Many session controls don’t need a slash command at all. These shortcuts let you toggle modes, cancel responses, and navigate input without breaking your flow.

Shortcut What When
Shift+Tab Cycle permission modes: default → acceptEdits → auto → plan You want to lock Claude into plan-only mode or grant broader trust mid-session
Alt+T Toggle extended thinking Stuck on a hard problem — switch on deep reasoning without typing /effort max
Ctrl+C Cancel the current response Claude is going off-track — stop it before it keeps generating
Ctrl+D Exit the session Quit cleanly from the keyboard
Ctrl+O Toggle the verbose transcript view Debugging what Claude actually sent and received
Esc Cancel the /loop countdown before the next iteration fires You started /loop but want to pause after the current iteration
Ctrl+A Jump to the start of the current input line Readline-style editing on a long prompt
Ctrl+E Jump to the end of the current input line Readline-style editing when you’ve navigated backward
# In session: quickly switch to plan-only (read-only) mode
# Press Shift+Tab twice to reach "plan" mode
# Claude will analyze and propose but not edit any files

# Toggle deep reasoning on the fly
# Press Alt+T
# ✓ Extended thinking: enabled

# Cancel a runaway response
# Press Ctrl+C

# Stop /loop before next iteration fires
# Press Esc
# ✓ Loop paused after current iteration

CLI Flags

When you’re scripting, running in CI, or want precise control at launch time, these flags shape how the session starts — its model, permission level, output format, and autonomy limits.

Flag What When
-p "prompt" Non-interactive: print output and exit Scripts, CI checks, piping Claude’s output into another tool
--output-format json Return output as structured JSON Parsing Claude’s answer in a shell script with jq
--output-format stream-json Emit JSON line-by-line as Claude responds Real-time processing of a long agentic response
--max-turns N Stop autonomous iteration after N turns Limiting scope when you don’t want Claude to run indefinitely
--permission-mode MODE Set permission level at launch: default, acceptEdits, auto, plan Scripting environments where you want full trust or full read-only
--model MODEL Set the model for this session Overriding the account default for a specific script or task
--safe-mode Disable all hooks, skills, and plugins Debugging a project config issue without customizations interfering
--bare Skip hooks, LSP, skill sync on launch Fastest possible startup for scripting with no project overhead
--dangerously-skip-permissions Skip all permission prompts Fully automated CI environments where prompts would block execution
--fork-session Create a parallel exploration branch from the current session Trying two approaches side-by-side without losing either thread
--fallback-model MODEL Use this model if the primary is overloaded High-traffic times when you want resilience instead of an error
# Run a one-off check and capture the result in a script
result=$(claude -p "Does src/auth.ts have any null pointer risks?" --output-format json)
is_error=$(echo "$result" | jq -r '.is_error')
echo "$result" | jq -r '.result'

# Full autonomous CI run with no prompts and a turn limit
claude -p "run tests, fix any failures, commit the result" \
  --permission-mode auto \
  --max-turns 20 \
  --dangerously-skip-permissions

# Stream output line-by-line for real-time monitoring
claude -p "refactor the payment module" --output-format stream-json | \
  while read line; do
    echo "$line" | jq -r 'select(.result) | .result'
  done

# Debug a broken project config cleanly
claude --safe-mode

Permission System

Claude asks before every new operation by default. The permission system lets you define exactly which operations are pre-approved — and how strictly those approvals are enforced — so you get the autonomy you want without blanket trust.

Pattern What When
Bash(git status) Allow exactly this one command You know this specific command is always safe
Bash(npm run test:*) Allow any command matching this prefix All test variants under npm run test: are safe to auto-approve
Edit(src/**) Allow edits to any file under src/ Claude should be free to modify source files but nothing else
mcp__github Allow all tools from the GitHub MCP server You’ve authenticated MCP and trust GitHub operations
Tool(param:value) Allow a tool only when a specific parameter matches Fine-grained control — allow Read only for certain paths

Permission modes explained:

Mode What Claude can do
default Prompts before each new type of tool use
acceptEdits Auto-approves file edits, prompts for shell commands
auto A safety classifier reviews each action — fewer prompts, still guarded
plan Read-only — Claude analyzes and proposes but cannot modify anything
bypassPermissions No prompts at all — use only in fully controlled environments
// .claude/settings.json — project-level allowlist
{
  "permissions": {
    "allow": [
      "Bash(git status)",
      "Bash(git diff*)",
      "Bash(yarn lint)",
      "Bash(yarn test:*)",
      "Read(**)",
      "Edit(src/**)"
    ],
    "deny": [
      "Bash(git push*)",
      "Bash(rm -rf*)"
    ]
  }
}
# Shift+Tab cycles through modes inside a running session:
# default → acceptEdits → auto → plan → default ...

# Launch in plan-only mode from the terminal
claude --permission-mode plan

# Grant full auto-trust for a CI job
claude --permission-mode auto --dangerously-skip-permissions

Configuration Files

Settings come from four locations and layer in a predictable order: enterprise → user → project → local. Understanding the hierarchy lets you set team-wide defaults in one place and personal overrides in another, without conflicts.

Where Claude Code stores settings and how they layer on top of each other.

File Scope What it controls
~/.claude/settings.json User-wide Personal defaults that apply across every project
.claude/settings.json Project (committed) Team-wide settings checked into version control
.claude/settings.local.json Project (personal) Personal overrides that stay off git — add to .gitignore
/etc/claude-code/managed-settings.json Enterprise Org-enforced policies that cannot be overridden by users
~/.claude.json Runtime state OAuth tokens and MCP server configuration

Settings layer in order: managed → user → project → local. Local always wins.

# Project-level settings (commit this to share with the team)
# .claude/settings.json
{
  "model": "claude-sonnet-4-6",
  "permissions": {
    "allow": ["Bash(yarn *)", "Read(**)", "Edit(src/**)"]
  }
}

# Personal overrides (keep this out of git)
# .claude/settings.local.json
{
  "model": "claude-opus-4-8"   # I prefer Opus even though the team default is Sonnet
}

Environment Variables

For headless automation, CI environments, or enterprise routing, environment variables let you override Claude Code’s behavior at the process level — no interactive login, no project file changes needed.

Variable What When
ANTHROPIC_API_KEY API key for authentication Using Claude Code without the interactive login, or in CI
ANTHROPIC_MODEL Override the default model for every session Pinning a specific model ID across all invocations
CLAUDE_CODE_SAFE_MODE Launch in safe mode (no hooks, plugins, or skills) Debugging project config without any customizations loading
CLAUDE_CODE_SUBAGENT_MODEL Model used by sub-agents spawned during agentic tasks Run Haiku for cheap sub-tasks while keeping Opus for the main session
MAX_THINKING_TOKENS Cap extended thinking token budget (set to 0 to disable) Controlling cost on tasks where deep reasoning isn’t worth it
DISABLE_AUTOUPDATER Prevent Claude Code from updating itself Pinning a version in CI so builds don’t change unexpectedly
DISABLE_TELEMETRY Opt out of usage tracking Privacy-sensitive environments or air-gapped systems
BASH_DEFAULT_TIMEOUT_MS Override the default timeout for shell commands Long-running build steps that would otherwise time out
CLAUDE_CODE_USE_BEDROCK Route API calls through AWS Bedrock Enterprise setups where traffic must stay within AWS
CLAUDE_CODE_USE_VERTEX Route API calls through Google Vertex AI Enterprise setups where traffic must stay within GCP
# Use an API key directly (no interactive login needed)
export ANTHROPIC_API_KEY="sk-ant-..."
claude -p "summarize this file" < README.md

# Use Haiku for sub-agents to cut costs on large agentic runs
export CLAUDE_CODE_SUBAGENT_MODEL=claude-haiku-4-5-20251001
claude

# Disable auto-updates in a reproducible CI environment
export DISABLE_AUTOUPDATER=1

# Extend timeout for a slow build command
export BASH_DEFAULT_TIMEOUT_MS=300000   # 5 minutes

Advanced Patterns

Combining flags, environment variables, and output formats for automation and scripting.

CI/CD Integration

# Run a review in CI and fail the build on errors
result=$(claude -p "review src/ for security issues" \
  --output-format json \
  --permission-mode auto \
  --dangerously-skip-permissions)

is_error=$(echo "$result" | jq -r '.is_error')
if [ "$is_error" = "true" ]; then
  echo "Claude returned an error"
  exit 1
fi

echo "$result" | jq -r '.result'

Streaming for Long Tasks

# Watch Claude work through a refactor in real time
claude -p "refactor the database layer to use async/await throughout" \
  --output-format stream-json \
  --permission-mode auto | \
  while read line; do
    echo "$line" | jq -r 'select(.result) | .result' 2>/dev/null
  done

Model Selection by Task

# Fast answer with Haiku
claude -p "fix the typo in README.md" --model haiku

# Deep reasoning with Opus for a hard bug
claude -p "trace why this deadlock only reproduces under high load" --model opus

# Largest context window for a massive codebase sweep
claude -p "audit all API endpoints for missing auth checks" --model "opus[1m]"

Subagent Cost Control

# Main session uses Opus; sub-agents use Haiku to save money
export CLAUDE_CODE_SUBAGENT_MODEL=claude-haiku-4-5-20251001
claude --model opus -p "coordinate a full test suite rewrite across 12 modules"

Session Branching

# Try two approaches to a refactor without losing either
# Inside a session:
/fork-session
# Now you have two parallel sessions from the same checkpoint
# Explore approach A in session 1, approach B in session 2