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 install
brew install --cask claude-code                 # Homebrew (macOS)
mise use -g claude                              # mise.jdx.dev
npm install -g @anthropic-ai/claude-code        # npm (deprecated)

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

Sign in

claude              # first run opens a browser login
claude auth login   # sign in again
claude auth status  # show the current account

Claude Code needs a Pro, Max, Team, or Enterprise plan, a Console account, or a cloud provider (Amazon Bedrock, Google Cloud, or Microsoft Foundry). ANTHROPIC_API_KEY also works.

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

Setup

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

Flags

FlagDescription
-p, --printPrint response and exit
-c, --continueContinue most recent conversation
-r, --resumeResume a session by ID or name
--model sonnetChoose the model
--effort highSet reasoning effort
--permission-mode planStart in a permission mode
--add-dir ../libAdd extra working directories
--verboseShow full turn-by-turn output

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

Slash commands

Session

Conversation

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

History

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

Usage

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

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
/permissionsManage permission rules
/mcpManage MCP connections
/doctorRun a setup checkup

Account

CommandDescription
/loginSign in to your account
/logoutSign out

Review

Changes

CommandDescription
/diffReview working-tree changes
/reviewReview changes or a pull request

Security

CommandDescription
/security-reviewScan changes for vulnerabilities

Interactive mode

Keyboard shortcuts

Session

ShortcutDescription
Ctrl+CInterrupt, or clear the input
Ctrl+DExit Claude Code
EscInterrupt Claude, or close dialogs
Esc EscClear the draft, or rewind
Ctrl+BBackground running tasks

Prompt

ShortcutDescription
Shift+TabCycle permission modes
Alt+PSwitch model
Alt+TToggle extended thinking
Ctrl+VPaste an image from the clipboard

Display

ShortcutDescription
Ctrl+LRedraw the screen
Ctrl+RSearch prompt history
Ctrl+OToggle the transcript viewer

On macOS, use Option instead of Alt.

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 without sending, press \ + Enter or Ctrl+J — both work in any terminal. Shift+Enter works in many terminals; run /terminal-setup if it doesn't.

Configuration

Settings files

~/.claude/settings.json      # user settings
.claude/settings.json        # project settings, committed
.claude/settings.local.json  # personal project settings

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 project notes, not committed
~/.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

Common workflows

Reviewing code

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

Inside a session, /review reviews the current diff and /security-review scans it for vulnerabilities.

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"

Also see

0 Comments for this cheatsheet. Write yours!