Claude Code is Anthropic's AI coding assistant for the terminal. This reference covers sessions, commands, flags, and configuration.

Getting started

Introduction

Claude Code is Anthropic's AI coding assistant for the terminal. This reference covers the most commonly used commands, flags, and settings.

Install

curl -fsSL https://claude.ai/install.sh | bash  # native
brew install --cask claude-code                 # Homebrew
npm install -g @anthropic-ai/claude-code        # npm, Node 22+
claude install stable                           # stable channel

On Windows: irm https://claude.ai/install.ps1 | iex in PowerShell, or winget install Anthropic.ClaudeCode.

See: Setup

Sign in

claude                       # first run opens a browser
claude auth login            # sign in again
claude auth login --console  # bill to a Console account
claude auth status           # JSON status; --text for plain

See: Authentication

Sessions

claude                        # start interactive session
claude "explain this repo"    # start with a prompt
claude -p "summarize README"  # print mode: answer and exit
git diff | claude -p "review this diff"

Use claude -c to continue the last conversation, or claude -r "auth-refactor" to resume one by name. See: Quickstart

CLI reference

Commands

Sessions

CommandDescription
claudeStart interactive session
claude "query"Start with an initial prompt
claude -p "query"Print response and exit
claude -cContinue most recent conversation
claude -r <session>Resume a session by ID or name
claude --bg "task"Start a background agent

Setup

CommandDescription
claude updateUpdate to latest version
claude installInstall or pin a version
claude doctorCheck install and settings
claude mcpConfigure MCP servers
claude pluginInstall and manage plugins
claude auth statusShow authentication status
claude setup-tokenGenerate a token for CI

See: CLI reference

Flags

FlagDescription
-c, --continueContinue most recent conversation
-r, --resumeResume a session by ID or name
--model sonnetChoose the model
--effort highSet reasoning effort
--fallback-model sonnetFall back when overloaded
--permission-mode planStart in a permission mode
--add-dir ../libAdd extra working directories
--verboseShow full turn-by-turn output

See: CLI reference

Other flags

FlagDescription
--debugEnable debug mode
--settings file.jsonLoad settings for this session
--ideAuto-connect to your IDE
-w, --worktreeStart in an isolated git worktree
--dangerously-skip-permissionsSkip all permission prompts

See: CLI reference

Headless mode

FlagDescription
-p, --printPrint the response and exit
--output-format jsontext, json, or stream-json
--json-schema schemaConstrain output to a schema
--max-turns 3Limit agentic turns
--max-budget-usd 5Stop the run at a spend cap
--bareSkip hooks, plugins, and memory

See: Headless mode

Slash commands

Session

Conversation

CommandDescription
/helpShow available commands
/clearStart a new conversation
/compactSummarize to free up context
/contextShow context window usage

Planning

CommandDescription
/planEnter plan mode
/goal <condition>Keep working until it is met
/btw <question>Ask a side question

History

CommandDescription
/resumeResume a previous conversation
/rewindRestore code and conversation
/branchBranch the conversation here
/exportExport the conversation as text

Usage

CommandDescription
/statusShow version, model, and account
/usageShow cost and plan limits

See: Commands

Setup

Settings

CommandDescription
/configOpen settings or set a value
/modelSwitch the AI model
/effortSet reasoning effort
/memoryEdit memory files

Project

CommandDescription
/initGenerate a starter CLAUDE.md
/permissionsAllow, ask, and deny rules
/mcpManage MCP connections
/hooksView hook configurations
/doctorRun a setup checkup

Account

CommandDescription
/loginSign in to your account
/logoutSign out
/exitExit the CLI (/quit)

See: Commands

Review and background work

Review

Changes

CommandDescription
/diffReview working-tree changes
/code-reviewReview the diff, a PR, or a path
/security-reviewScan changes for vulnerabilities

/review is an alias of /code-review, which takes an effort level, --fix, and a PR number.

See: Review locally with /code-review

Background work

CommandDescription
/backgroundDetach this session as a background agent
/forkCopy it into a new background session
/subtask <task>Run a task in a forked subagent
/tasksView and manage background work

See: Agent view

Interactive mode

Keyboard shortcuts

Session

ShortcutDescription
Ctrl+CInterrupt, clear input, or exit
Ctrl+DExit Claude Code
EscInterrupt Claude, or close dialogs
Esc EscClear the draft, or rewind
Ctrl+BBackground running tasks
Ctrl+X Ctrl+KStop all background subagents; press twice

Prompt

ShortcutDescription
Shift+TabCycle permission modes
Alt+PSwitch model
Alt+TToggle extended thinking
Alt+OToggle fast mode
Ctrl+VPaste an image from the clipboard
Ctrl+GEdit the prompt in $EDITOR
Ctrl+SStash or restore the prompt

Display

ShortcutDescription
Ctrl+LRedraw the screen
Ctrl+RSearch prompt history
Ctrl+OToggle the transcript viewer
Ctrl+TToggle Claude's task list

On macOS, use Option instead of Alt; some chords need Option mapped to Meta.

See: Interactive mode

Input modes

InputEffect
/Slash commands and skills
!Run a shell command directly
@Mention a file path
:Insert an emoji by shortcode
?Show the shortcut help panel

For a newline, \ + Enter or Ctrl+J works anywhere; Shift+Enter needs /terminal-setup in some terminals.

See: Interactive mode

Configuration

Settings files

~/.claude/settings.json                # user settings
.claude/settings.json                  # project settings, committed
.claude/settings.local.json            # personal project settings
/etc/claude-code/managed-settings.json # managed policy (Linux)

Run /config to edit settings, or pass --settings file.json for one session. See: Settings

Environment variables

VariablePurpose
ANTHROPIC_API_KEYAPI key used instead of a subscription
ANTHROPIC_MODELDefault model name
ANTHROPIC_BASE_URLRoute requests through a gateway
API_TIMEOUT_MSAPI timeout (default 600000)
BASH_DEFAULT_TIMEOUT_MSBash tool timeout (default 120000)
CLAUDE_CODE_DISABLE_AUTO_MEMORYTurn auto memory off
DISABLE_AUTOUPDATERTurn background updates off

Settings files can also set env vars under an env key. See: Environment variables

Memory

CLAUDE.md             # project instructions, committed
CLAUDE.local.md       # personal notes, not committed
.claude/rules/*.md    # topic rules, optionally path-scoped
~/.claude/CLAUDE.md   # instructions for all your projects

/init generates a project CLAUDE.md; /memory edits memory files and auto memory. Import files with @path/to/file.md. See: Memory

Permission modes

ModeWhat runs without asking
defaultReads only (labeled Manual)
acceptEditsReads, file edits, filesystem commands
planReads, until you approve a plan
autoEverything, with safety checks
dontAskPre-approved tools only; rest denied
bypassPermissionsEverything

auto is the built-in starting mode; Shift+Tab cycles modes in a session. A classifier can still block actions, and explicit ask rules still prompt. See: Permission modes

Common workflows

Reviewing code

git diff | claude -p "review this diff for bugs"
claude -p "check src/ for security issues"

In a session, /code-review reviews the diff, /code-review 1234 a pull request, and /security-review scans for vulnerabilities.

See: Review locally with /code-review

Scripting

# One-shot JSON output for scripts
claude -p "list the failing tests" --output-format json

# Pipe logs in
cat build.log | claude -p "explain this failure"

--bare skips hooks, plugins, and auto-discovered config so scripted calls start faster. It ignores OAuth credentials, so set ANTHROPIC_API_KEY.

See: Headless mode

Background and parallel work

claude --bg "migrate the auth tests"  # detach immediately
claude agents                         # monitor and dispatch

Inside a session, /background detaches it and /batch fans work out across worktrees.

See: Agent view

Also see

0 Comments for this cheatsheet. Write yours!