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.

CommandWhatWhen
claude installMigrate from the npm package to the native binaryYou installed via npm and want the faster, standalone version
claude doctorVerify that your installation and system config are healthySomething feels off — wrong model, missing tools, auth errors
claude auth loginAuthenticate or switch to a different Anthropic accountFirst-time setup, or switching between personal and work accounts
claude auth statusShow which account is currently activeConfirming you’re logged into the right account before billing-sensitive work
claude auth logoutClear stored credentialsHanding off a machine or revoking access
claude updateManually pull the latest Claude Code versionAuto-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.

CommandWhatWhen
claudeOpen an interactive REPL in the current directoryDay-to-day coding help, exploration, or conversation
claude -p "prompt"Run a single query and exit without opening a REPLScripting, CI pipelines, or one-off answers from the terminal
claude -cResume the most recent sessionPicking up exactly where you left off after closing the terminal
claude -r SESSION_IDResume a specific session by its IDReturning to a session that isn’t the most recent one
claude --resume NAMEResume a session by its nameYou named sessions deliberately and want to jump to the right one
claude -n "name"Start a new session with a given nameOrganising parallel work streams so sessions are easy to find later
claude --from-pr #123Link a new session to a GitHub, GitLab, or Bitbucket PRReviewing 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.

CommandWhatWhen
/statusShow the current model, account tier, and active settingsYou’re unsure which model you’re on or what’s loaded
/costDisplay token usage and estimated cost for this sessionChecking spend before a long agentic task, or after an expensive run
/model MODELSwitch the model mid-sessionThe task changed — swap to Haiku for speed or Opus for hard reasoning
/effort LEVELAdjust reasoning depth: low, medium, high, xhigh, maxDial up for architecture decisions, dial down for formatting fixes
/compactSummarize prior context and free up tokensThe session is getting long and responses are slowing down
/rename NAMERename the current sessionYou started without a name and want to file it properly for later resumption
/exitEnd the session cleanlyDone 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.

CommandWhatWhen
/plan [DESCRIPTION]Enter read-only planning mode — Claude analyzes but does not modify filesYou want Claude to think through an approach before touching anything
/code-reviewReview the current branch diff for bugs and inefficienciesBefore opening a PR or merging to main
/code-review --fixReview the diff and automatically apply the suggested fixesYou trust the review and want changes applied immediately
/simplifyCleanup-only review — no bug hunting, just reduce complexityThe code works but feels sprawling; you want it tightened up
/security-reviewAnalyze the current branch for security issuesBefore shipping auth changes, API endpoints, or anything that touches user data
/recapSummarize what happened in a prior session contextYou resumed an old session and need to re-orient quickly
/rewindStep back in the conversationClaude went down the wrong path — undo and try a different approach
/cd DIRECTORYMove the session’s working directoryYou 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.

CommandWhatWhen
/ultrareview [PR#]Run a deep multi-agent code review in the cloudHigh-stakes PRs where you want maximum coverage — broader than /code-review
/loopEnter continuous improvement mode — Claude iterates until the task is doneDelegating an entire feature or bug fix and walking away
/fastToggle faster output (Opus 4.6 only)You’re on Opus and want quicker streaming without switching models
/workflowsOrchestrate multi-agent workflowsBreaking a large task into parallel sub-agents for efficiency
/focusEnter focus mode to reduce noiseLong sessions where you want Claude to stay on task without tangents
/channelsConfigure permission relay channelsSetting up team-wide permission sharing for agentic tasks
/pluginAccess the plugin marketplaceInstalling or managing integrations like GitHub, Linear, or Slack
/reload-skillsRefresh skill definitions without restartingYou updated a skill file and want the changes live immediately
/less-permission-promptsSuggest an allowlist of safe operations for the current projectTired 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.

ShortcutWhatWhen
Shift+TabCycle permission modes: default → acceptEdits → auto → planYou want to lock Claude into plan-only mode or grant broader trust mid-session
Alt+TToggle extended thinkingStuck on a hard problem — switch on deep reasoning without typing /effort max
Ctrl+CCancel the current responseClaude is going off-track — stop it before it keeps generating
Ctrl+DExit the sessionQuit cleanly from the keyboard
Ctrl+OToggle the verbose transcript viewDebugging what Claude actually sent and received
EscCancel the /loop countdown before the next iteration firesYou started /loop but want to pause after the current iteration
Ctrl+AJump to the start of the current input lineReadline-style editing on a long prompt
Ctrl+EJump to the end of the current input lineReadline-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.

FlagWhatWhen
-p "prompt"Non-interactive: print output and exitScripts, CI checks, piping Claude’s output into another tool
--output-format jsonReturn output as structured JSONParsing Claude’s answer in a shell script with jq
--output-format stream-jsonEmit JSON line-by-line as Claude respondsReal-time processing of a long agentic response
--max-turns NStop autonomous iteration after N turnsLimiting scope when you don’t want Claude to run indefinitely
--permission-mode MODESet permission level at launch: default, acceptEdits, auto, planScripting environments where you want full trust or full read-only
--model MODELSet the model for this sessionOverriding the account default for a specific script or task
--safe-modeDisable all hooks, skills, and pluginsDebugging a project config issue without customizations interfering
--bareSkip hooks, LSP, skill sync on launchFastest possible startup for scripting with no project overhead
--dangerously-skip-permissionsSkip all permission promptsFully automated CI environments where prompts would block execution
--fork-sessionCreate a parallel exploration branch from the current sessionTrying two approaches side-by-side without losing either thread
--fallback-model MODELUse this model if the primary is overloadedHigh-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.

PatternWhatWhen
Bash(git status)Allow exactly this one commandYou know this specific command is always safe
Bash(npm run test:*)Allow any command matching this prefixAll 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__githubAllow all tools from the GitHub MCP serverYou’ve authenticated MCP and trust GitHub operations
Tool(param:value)Allow a tool only when a specific parameter matchesFine-grained control — allow Read only for certain paths

Permission modes explained:

ModeWhat Claude can do
defaultPrompts before each new type of tool use
acceptEditsAuto-approves file edits, prompts for shell commands
autoA safety classifier reviews each action — fewer prompts, still guarded
planRead-only — Claude analyzes and proposes but cannot modify anything
bypassPermissionsNo 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.

FileScopeWhat it controls
~/.claude/settings.jsonUser-widePersonal defaults that apply across every project
.claude/settings.jsonProject (committed)Team-wide settings checked into version control
.claude/settings.local.jsonProject (personal)Personal overrides that stay off git — add to .gitignore
/etc/claude-code/managed-settings.jsonEnterpriseOrg-enforced policies that cannot be overridden by users
~/.claude.jsonRuntime stateOAuth 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.

VariableWhatWhen
ANTHROPIC_API_KEYAPI key for authenticationUsing Claude Code without the interactive login, or in CI
ANTHROPIC_MODELOverride the default model for every sessionPinning a specific model ID across all invocations
CLAUDE_CODE_SAFE_MODELaunch in safe mode (no hooks, plugins, or skills)Debugging project config without any customizations loading
CLAUDE_CODE_SUBAGENT_MODELModel used by sub-agents spawned during agentic tasksRun Haiku for cheap sub-tasks while keeping Opus for the main session
MAX_THINKING_TOKENSCap extended thinking token budget (set to 0 to disable)Controlling cost on tasks where deep reasoning isn’t worth it
DISABLE_AUTOUPDATERPrevent Claude Code from updating itselfPinning a version in CI so builds don’t change unexpectedly
DISABLE_TELEMETRYOpt out of usage trackingPrivacy-sensitive environments or air-gapped systems
BASH_DEFAULT_TIMEOUT_MSOverride the default timeout for shell commandsLong-running build steps that would otherwise time out
CLAUDE_CODE_USE_BEDROCKRoute API calls through AWS BedrockEnterprise setups where traffic must stay within AWS
CLAUDE_CODE_USE_VERTEXRoute API calls through Google Vertex AIEnterprise 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