Claude Code — AI Coding Agent for the Terminal
Anthropic's official AI coding agent: interactive or scripted sessions, MCP servers, subagents, plugins, worktrees and IDE integration.
Claude Code is Anthropic's official agentic coding tool: it reads, writes and runs code right in your terminal, driven by the claude command. By default it opens an interactive session in the current directory; with -p/--print it turns into a scriptable, pipe-friendly one-shot tool. Beyond the CLI it also runs as a desktop and web app and as an IDE extension, and it taps the latest Claude models — Fable 5 and the Claude 4.x family (Opus 4.8, Sonnet 4.6, Haiku 4.5). This cheat sheet collects the flags, subcommands and slash commands you reach for every day, from session management and permission modes to MCP servers, subagents, plugins and git worktrees.
Basic Usage
claude — Start an interactive Claude Code session in the current directory.
claudeclaude "<prompt>" — Start an interactive session with an initial prompt.
claude "Explain the architecture of this project"claude --version — Show the installed Claude Code version.
claude --versionclaude --help — Show all available options and commands.
claude --helpclaude update — Check for updates and install the latest version if available.
claude updateclaude doctor — Check the health of the Claude Code installation and auto-updater.
claude doctorclaude install <target> — Install a specific Claude Code native build (stable, latest, or version number).
claude install stableclaude project — Manage Claude Code project state.
claude projectclaude ultrareview [target] — Run a cloud-hosted multi-agent code review of the current branch (or a PR number / base branch) and print the findings.
claude ultrareview 42Session Management
claude -c — Continue the most recent conversation in the current directory. Long: --continue
claude -cclaude -r — Open an interactive picker to resume a previous conversation. Long: --resume
claude -rclaude -r <session-id> — Resume a specific conversation directly by its session ID.
claude -r a1b2c3d4-...claude -n <name> — Set a display name for this session (shown in /resume and terminal title).
claude -n "refactor auth module"claude --fork-session — When resuming, create a new session ID instead of continuing the original.
claude -c --fork-sessionclaude --session-id <uuid> — Use a specific UUID as the session ID.
claude --session-id 00000000-0000-0000-0000-000000000001claude --from-pr <number> — Resume a session linked to a pull request by number or URL.
claude --from-pr 42Non-Interactive Mode (--print)
claude -p "<prompt>" — Print the response and exit. Non-interactive for scripting and pipes.
claude -p "What does this function do?" < src/utils.jsecho "<prompt>" | claude -p — Pipe a prompt into Claude and get a single printed response.
echo "Summarize this" | claude -pcat <file> | claude -p "<prompt>" — Pipe file contents as context into a non-interactive prompt.
cat app.py | claude -p "Find security issues"claude -p --output-format json "<prompt>" — Output the response as a single JSON object. Formats: text, json, stream-json.
claude -p --output-format json "List 3 refactoring tips"claude -p --output-format stream-json "<prompt>" — Stream the response as newline-delimited JSON chunks in real-time.
claude -p --output-format stream-json "Explain async/await"claude -p --json-schema '<schema>' "<prompt>" — Validate output against a JSON Schema for structured, machine-readable responses.
claude -p --json-schema '{"type":"object","properties":{"name":{"type":"string"}}}' "Extract info"claude -p --max-budget-usd <amount> "<prompt>" — Set a maximum spend limit in USD for this call.
claude -p --max-budget-usd 0.10 "Summarize these logs"claude -p --no-session-persistence "<prompt>" — Don't save the session to disk (cannot be resumed).
claude -p --no-session-persistence "Quick question"claude -p --fallback-model sonnet "<prompt>" — Automatically fall back to specified model if default is overloaded.
claude -p --fallback-model sonnet "Generate unit tests"claude -p --input-format stream-json --output-format stream-json — Bidirectional streaming JSON for integration with custom tools or orchestrators.
claude -p --input-format stream-json --output-format stream-jsonclaude -p --include-partial-messages ... — Emit partial message chunks as they arrive (requires --output-format stream-json).
claude -p --output-format stream-json --include-partial-messages "Explain this"claude -p --include-hook-events ... — Include all hook lifecycle events in the output stream (requires --output-format stream-json).
claude -p --output-format stream-json --include-hook-events "Run the build"claude -p --replay-user-messages ... — Re-emit user messages from stdin back on stdout for acknowledgment (stream-json in+out only).
claude -p --input-format stream-json --output-format stream-json --replay-user-messagesclaude -p --prompt-suggestions "<prompt>" — Emit a prompt_suggestion message after each turn predicting the next user prompt.
claude -p --prompt-suggestions "Refactor this module"Model & Effort
claude --model opus — Use Claude Opus (most capable). Accepts aliases: opus, sonnet, haiku.
claude --model opusclaude --model sonnet — Use Claude Sonnet (balanced speed and capability).
claude --model sonnetclaude --model haiku — Use Claude Haiku (fastest, most cost-efficient).
claude --model haikuclaude --model <full-model-id> — Use a specific model by its full ID.
claude --model claude-opus-4-8claude --effort <level> — Set effort level: low, medium, high, xhigh, max. Higher = more thorough but slower.
claude --effort high "Perform a full security audit"Permission Modes & Tool Access
claude --permission-mode default — Normal mode: prompts for approval on potentially dangerous actions.
claude --permission-mode defaultclaude --permission-mode acceptEdits — Auto-accept all file edits without prompting.
claude --permission-mode acceptEditsclaude --permission-mode plan — Plan mode: propose changes but don't execute until approved.
claude --permission-mode planclaude --permission-mode auto — Auto mode: classifies actions and auto-approves safe ones.
claude --permission-mode autoclaude --permission-mode dontAsk — Don't prompt for permissions; silently skip actions that would require approval instead of running them.
claude --permission-mode dontAskclaude --permission-mode bypassPermissions — Bypass all permission checks. Only for isolated sandboxes.
claude --permission-mode bypassPermissionsclaude --dangerously-skip-permissions — Bypass all permission checks (equivalent to bypassPermissions mode). Only for sandboxes with no internet access.
claude --dangerously-skip-permissionsclaude --allow-dangerously-skip-permissions — Make 'bypass permissions' available as an opt-in mode without enabling it by default.
claude --allow-dangerously-skip-permissionsclaude --allowed-tools "<tools>" — Restrict Claude to specific tools. Supports subcommand patterns.
claude --allowed-tools "Bash(git:*) Edit Read"claude --disallowed-tools "<tools>" — Block specific tools while allowing all others.
claude --disallowed-tools "Bash Write"claude --tools "<tools>" — Specify available built-in tools. Use "" to disable all, "default" for all.
claude --tools "Read,Glob,Grep"claude --add-dir <path> — Grant tool access to additional directories beyond the current working directory.
claude --add-dir ~/shared-libs --add-dir /etc/nginxSystem Prompts & Agents
claude --system-prompt "<prompt>" — Override the default system prompt for this session.
claude --system-prompt "Reply only in German."claude --append-system-prompt "<prompt>" — Append instructions to the default system prompt without replacing it.
claude --append-system-prompt "Always use Bootstrap 5."claude --system-prompt-file <path> — Load the system prompt override from a file instead of an inline string.
claude --system-prompt-file ./prompts/reviewer.mdclaude --append-system-prompt-file <path> — Append a system prompt loaded from a file to the default system prompt.
claude --append-system-prompt-file ./prompts/house-rules.mdclaude --brief — Enable the SendUserMessage tool so an agent can send messages back to the user.
claude --briefclaude --agent <agent-name> — Use a named agent configured in settings.
claude --agent reviewerclaude agents — List all configured agents from user, project, and local settings.
claude agentsclaude --agents '<json>' — Define inline agents as JSON for the current session.
claude --agents '{"tester":{"description":"Writes tests","prompt":"Write unit tests only"}}'claude --bare — Minimal mode: skip hooks, LSP, plugins, auto-memory, CLAUDE.md discovery.
claude --bare -p "Quick question"Interactive Slash Commands: Session
/help — Show help and available commands.
/help/clear — Clear conversation history and free up context. Aliases: /reset, /new
/clear/compact [instructions] — Compact conversation to save context, with optional focus instructions.
/compact focus on the auth module changes/context — Visualize current context usage as a colored grid.
/context/resume [session] — Resume a conversation by ID or name. Alias: /continue
/resume/branch [name] — Create a branch of the current conversation at this point. Alias: /fork
/branch experiment-1/rename [name] — Rename the current session.
/rename auth-refactor/export [filename] — Export the current conversation as plain text.
/export conversation.txt/exit — Exit the CLI. Alias: /quit
/exitInteractive Slash Commands: Model & Tools
/model [model] — Select or change the AI model mid-session.
/model opus/effort [level] — Set effort level: low, medium, high, xhigh, max, auto.
/effort high/fast [on|off] — Toggle fast mode (same model, faster output).
/fast on/cost — Show token usage statistics for the current session.
/cost/usage — Show plan usage limits and rate limit status.
/usage/permissions — View or update permissions. Alias: /allowed-tools
/permissions/tasks — List and manage background tasks.
/tasksInteractive Slash Commands: Code & Git
/diff — Open interactive diff viewer showing uncommitted changes.
/diff/rewind — Rewind conversation and code to a previous point. Alias: /checkpoint
/rewind/pr-comments [PR] — Fetch and display comments from a GitHub pull request.
/pr-comments 42/security-review — Analyze pending changes on current branch for security vulnerabilities.
/security-review/copy [N] — Copy the last (or Nth-latest) assistant response to clipboard.
/copy/btw <question> — Ask a quick side question without adding to conversation context.
/btw what's the syntax for a ternary in PHP?Interactive Slash Commands: Configuration
/config — Open settings interface (theme, model, output style). Alias: /settings
/config/status — Show version, model, account, and connectivity status.
/status/theme — Change color theme (light/dark, colorblind-accessible, ANSI).
/theme/color [color] — Set the prompt bar color (red, blue, green, yellow, purple, etc.).
/color blue/vim — Toggle between Vim and Normal editing modes.
/vim/voice — Toggle push-to-talk voice dictation.
/voice/keybindings — Open or create keybindings configuration file.
/keybindings/terminal-setup — Configure terminal keybindings for Shift+Enter and other shortcuts.
/terminal-setup/statusline — Configure Claude Code's status line (or auto-configure from shell prompt).
/statusline/memory — Edit CLAUDE.md, enable/disable auto-memory, view auto-memory entries.
/memory/init — Initialize project with CLAUDE.md guide.
/init/hooks — View hook configurations for tool events.
/hooks/add-dir <path> — Add a new working directory to the current session.
/add-dir ~/other-projectInteractive Slash Commands: Integrations
/mcp — Manage MCP server connections and OAuth authentication.
/mcp/ide — Manage IDE integrations (VS Code, JetBrains) and show status.
/ide/chrome — Configure Claude in Chrome integration.
/chrome/plugin — Manage Claude Code plugins.
/plugin/skills — List available skills (custom slash commands).
/skills/agents — Manage agent configurations.
/agents/plan [description] — Enter plan mode directly from the prompt.
/plan refactor the authentication module/schedule [description] — Create, update, list, or run cloud scheduled tasks (triggers).
/scheduleInteractive Slash Commands: Account & Info
/login — Sign in to your Anthropic account.
/login/logout — Sign out from your Anthropic account.
/logout/doctor — Diagnose and verify Claude Code installation and settings.
/doctor/stats — Visualize daily usage, session history, streaks, and model preferences.
/stats/insights — Generate a report analyzing your Claude Code sessions.
/insights/release-notes — View the full changelog with recent versions first.
/release-notes/feedback [report] — Submit feedback about Claude Code. Alias: /bug
/feedback/desktop — Continue current session in Claude Code Desktop app. Alias: /app
/desktop/mobile — Show QR code to download Claude mobile app. Aliases: /ios, /android
/mobile/remote-control — Make session available for remote control from claude.ai. Alias: /rc
/remote-control/install-github-app — Set up Claude GitHub Actions app for a repository.
/install-github-app/extra-usage — Configure extra usage to keep working when rate limits hit.
/extra-usageMCP Servers
claude mcp list — List all configured MCP (Model Context Protocol) servers.
claude mcp listclaude mcp add <name> -- <command> [args...] — Add a stdio MCP server as a subprocess.
claude mcp add my-server -- npx my-mcp-server --port 3000claude mcp add --transport http <name> <url> — Add an HTTP/SSE MCP server by URL.
claude mcp add --transport http sentry https://mcp.sentry.dev/mcpclaude mcp add -e <KEY>=<val> <name> -- <command> — Add a stdio MCP server with environment variables.
claude mcp add -e GITHUB_TOKEN=ghp_xxx github -- npx @modelcontextprotocol/server-githubclaude mcp add --transport http <name> <url> --header "Authorization: Bearer <token>" — Add an HTTP MCP server with a custom auth header.
claude mcp add --transport http api https://api.example.com/mcp --header "Authorization: Bearer xxx"claude mcp add-json <name> '<json>' — Add an MCP server with a full JSON config string.
claude mcp add-json myserver '{"type":"stdio","command":"npx","args":["my-server"]}'claude mcp get <name> — Show full configuration details of a specific MCP server.
claude mcp get sentryclaude mcp remove <name> — Remove a configured MCP server.
claude mcp remove my-serverclaude mcp add-from-claude-desktop — Import MCP servers from the Claude Desktop app (Mac and WSL only).
claude mcp add-from-claude-desktopclaude mcp serve — Start Claude Code itself as an MCP server (for integration with other tools).
claude mcp serveclaude --mcp-config <path> — Load additional MCP servers from a JSON config file for this session.
claude --mcp-config ~/.config/mcp-servers.jsonclaude --strict-mcp-config --mcp-config <path> — Only use MCP servers from the specified config, ignore all others.
claude --strict-mcp-config --mcp-config config.jsonclaude mcp reset-project-choices — Reset all approved/rejected project-scoped MCP server choices.
claude mcp reset-project-choicesAuthentication
claude auth login — Sign in to your Anthropic account (opens browser for OAuth).
claude auth loginclaude auth logout — Log out from the current Anthropic account.
claude auth logoutclaude auth status — Show the current authentication status and active account.
claude auth statusclaude setup-token — Set up a long-lived authentication token (requires Claude subscription).
claude setup-tokenWorktrees & IDE
claude -w — Create a new git worktree for this session (isolated branch). Long: --worktree
claude -wclaude -w <name> — Create a named git worktree.
claude -w feature-refactorclaude -w --tmux — Create a worktree and open it in a new tmux session (iTerm2 native panes when available; --tmux=classic forces traditional tmux).
claude -w --tmuxclaude --ide — Auto-connect to an open IDE (VS Code, JetBrains) on startup.
claude --ideclaude --remote-control [name] — Start an interactive session with Remote Control enabled (optionally named) for control from claude.ai.
claude --remote-control "laptop session"Plugins
claude plugin list — List all installed plugins.
claude plugin listclaude plugin install <plugin> — Install a plugin from the marketplace.
claude plugin install my-pluginclaude plugin enable <plugin> — Enable a previously disabled plugin.
claude plugin enable my-pluginclaude plugin disable <plugin> — Disable an installed plugin without removing it.
claude plugin disable my-pluginclaude plugin update <plugin> — Update a plugin to the latest version (restart required).
claude plugin update my-pluginclaude plugin uninstall <plugin> — Uninstall a plugin completely.
claude plugin uninstall my-pluginclaude plugin validate <path> — Validate a local plugin or marketplace manifest.
claude plugin validate ./my-plugin/claude --plugin-dir <path> — Load a local plugin directory or .zip for this session only (repeatable).
claude --plugin-dir ./my-plugin/ --plugin-dir ./other.zipclaude --plugin-url <url> — Fetch a plugin .zip from a URL for this session only (repeatable).
claude --plugin-url https://example.com/my-plugin.zipAuto Mode
claude auto-mode config — Print the effective auto mode config as JSON.
claude auto-mode configclaude auto-mode defaults — Print the default auto mode allow/deny rules as JSON.
claude auto-mode defaultsclaude auto-mode critique — Get AI feedback on your custom auto mode rules.
claude auto-mode critiqueDebugging & Diagnostics
claude --debug — Enable debug mode: verbose logs, tool calls, API requests.
claude --debugclaude --debug <filter> — Filter debug output by category. Prefix with ! to exclude.
claude --debug api,hooksclaude --debug-file <path> — Write debug logs to a file (implicitly enables debug mode).
claude --debug-file /tmp/claude-debug.logclaude --verbose — Enable verbose output mode.
claude --verboseScripting & Automation
git diff HEAD~1 | claude -p "Summarize these changes" — Pipe git diff into Claude to generate a commit message.
git diff HEAD~1 | claude -p "Write a conventional commit message"claude -p --output-format json "<prompt>" | jq '.result' — Pipe JSON output to jq for processing in shell scripts.
claude -p --output-format json "Extract function names" | jq '.result'claude --settings '<json>' — Load settings from a JSON file path or inline JSON string.
claude --settings '{"model":"sonnet","verbose":true}'claude --setting-sources <sources> — Control which setting sources are loaded: user, project, local.
claude --setting-sources user,projectclaude -p --betas <feature> "<prompt>" — Enable a beta feature via header (API key users only).
claude -p --betas interleaved-thinking-2025-05-14 "Think step by step"claude --disable-slash-commands — Disable all slash command skills for this session.
claude --disable-slash-commandsclaude --chrome — Enable Claude in Chrome integration for this session.
claude --chromeclaude --no-chrome — Disable the Claude in Chrome integration for this session.
claude --no-chromeclaude --file <file_id:path> — Download file resources at startup. Format: file_id:relative_path (repeatable).
claude --file file_abc:doc.txt --file file_def:img.pngclaude --exclude-dynamic-system-prompt-sections — Move per-machine sections (cwd, env, memory paths, git status) into the first user message for better cross-user prompt-cache reuse.
claude --exclude-dynamic-system-prompt-sections -p "Review"Environment Variables
CLAUDE_CONFIG_DIR=<path> claude — Use a custom config directory instead of the default ~/.claude. Enables separate configs for different projects or contexts.
CLAUDE_CONFIG_DIR=~/.claude-work claudealias claude-<name>="CLAUDE_CONFIG_DIR=~/.<dir> claude" — Create shell aliases for different Claude configurations (add to .bashrc/.zshrc).
alias claude-private="CLAUDE_CONFIG_DIR=~/.claude-private claude"
alias claude-work="CLAUDE_CONFIG_DIR=~/.claude-work claude"ANTHROPIC_API_KEY=<key> claude — Set the API key directly instead of using OAuth login.
ANTHROPIC_API_KEY=sk-ant-xxx claude -p "Hello"CLAUDE_MODEL=<model> claude — Set the default model without using --model flag.
CLAUDE_MODEL=claude-sonnet-4-6 claudeCLAUDE_CODE_SIMPLE=1 claude — Simplified mode (same as --bare): skip hooks, LSP, plugins, auto-memory.
CLAUDE_CODE_SIMPLE=1 claude -p "Quick question"ANTHROPIC_BASE_URL=<url> claude — Use a custom API endpoint (proxy or compatible provider).
ANTHROPIC_BASE_URL=https://my-proxy.example.com claudeDISABLE_AUTOUPDATE=1 claude — Disable the automatic update check on startup.
DISABLE_AUTOUPDATE=1 claudeCLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1 — Always reset the Bash tool's working directory to the project root between commands.
CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1 claudeUseful Aliases & Tips
alias claude-private="CLAUDE_CONFIG_DIR=~/.claude-private claude" — Separate config for creative/personal projects — own settings, memory, and MCP servers.
# In ~/.bashrc or ~/.zshrc:
alias claude-private="CLAUDE_CONFIG_DIR=~/.claude-private claude"alias claude-work="CLAUDE_CONFIG_DIR=~/.claude-work claude" — Separate config for work projects — own API key, permissions, and agents.
# In ~/.bashrc or ~/.zshrc:
alias claude-work="CLAUDE_CONFIG_DIR=~/.claude-work claude"alias cq='claude -p' — Quick alias for non-interactive one-shot queries.
cq "What's the regex for an email address?"alias cr='claude -c' — Quick alias to continue the last conversation.
cralias claude-review='claude -p --model opus "Review this code for bugs and security issues"' — Predefined alias for code review with a specific model.
cat src/auth.py | claude-reviewccommit() { git diff --cached | claude -p "Write a conventional commit message for these staged changes"; } — Shell function to generate commit messages from staged changes.
git add -p && ccommitcexplain() { cat "$1" | claude -p "Explain this file concisely"; } — Shell function to quickly explain any file.
cexplain src/config.tsKeyboard Shortcuts (interactive session)
Enter — Submit the current prompt (configurable in /keybindings).
Type your prompt and press Enter to sendShift+Enter — Insert a newline without submitting (requires /terminal-setup).
Write multi-line prompts with Shift+EnterCtrl+C — Cancel the current operation or generation.
Press Ctrl+C to stop a long responseEscape — Cancel or go back in menus and pickers.
Press Escape to close the session pickerUp / Down Arrow — Navigate through prompt history.
Press Up to recall previous prompts/ — Open slash command autocomplete. Type to filter.
Type / to see all available commands Conclusion
Claude Code rewards a deliberate setup: pin sensitive operations behind permission modes, reserve --dangerously-skip-permissions for throwaway sandboxes only, and lean on -p plus --output-format json when you wire it into scripts and CI. Once you have a feel for sessions, agents and MCP servers, the same binary scales from a quick one-off question to a long-running, multi-step refactor. Treat the flags here as a starting point and check the official docs for new commands between releases.
Further Reading
- Claude Code documentation – Anthropic's official guide to installation, configuration, slash commands, hooks and MCP
- anthropics/claude-code on GitHub – issue tracker, release notes and reference material