Claude Code
AI-powered coding agent in the terminal, built by Anthropic. Runs directly in your shell with full access to your codebase.
Install
Migrate off npm
If you installed via npm and want to switch to the self-updating native binary, run claude migrate-installer.
Launch & authenticate
On first launch, Claude Code opens a browser to authenticate via your claude.ai account (Pro or Max plan). Manage the session later with /login and /logout.
Alternatively, set ANTHROPIC_API_KEY to use the API directly (pay-as-you-go):
For CI or scripts that can't open a browser, generate a long-lived token:
Keyboard shortcuts
| Shortcut | Action |
|---|---|
| Esc | Interrupt Claude (stop the current operation) |
| Esc Esc | Rewind: edit a previous message / restore a checkpoint |
| Shift+Tab | Cycle permission mode (normal β auto-accept β plan) |
| Ctrl+B | Move the current task to the background |
| Ctrl+C | Cancel input, or quit when pressed twice |
| Ctrl+D | Exit Claude Code |
| Ctrl+L | Clear terminal |
| Ctrl+R | Search command history |
| Ctrl+O | Toggle verbose output |
| Ctrl+V | Paste an image from the clipboard |
| Up Down | Navigate conversation history |
@ | Reference files / MCP resources, include contents in context |
# | Add a memory to CLAUDE.md |
! | Run a bash command directly; its output is added to context |
/ | Start a slash command |
Slash commands
Session & context
| Command | Description |
|---|---|
/help | Show available commands |
/clear | Clear conversation history (start fresh) |
/compact | Summarize history to reduce context usage |
/context | Visualize the current context window usage |
/rewind | Restore the conversation and/or files to an earlier checkpoint |
/resume | Resume a previous conversation |
/export | Export the current conversation to a file |
/cost Β· /usage | Show token usage, cost and plan limits |
Model & workflow
| Command | Description |
|---|---|
/model | Select the AI model |
/fast | Toggle fast mode (faster Opus output, same model) |
/agents | Manage subagents |
/review | Review a GitHub pull request |
/code-review | Review the current working diff for bugs and cleanups |
/simplify | Cleanup-only review of the current diff |
/security-review | Security review of pending changes |
/verify | Build & run the change to confirm it works |
/run | Launch and drive the project's app |
Config & extend
| Command | Description |
|---|---|
/init | Generate CLAUDE.md for the current project |
/memory | Edit CLAUDE.md memory files |
/config | Open the settings interface |
/permissions | View and edit tool permissions |
/add-dir | Add a directory to the allowed list |
/mcp | Manage MCP servers and view their status |
/hooks | Browse configured hooks |
/plugin | Manage plugins and marketplaces |
/output-style | Switch the response style (default, explanatory, learning) |
/statusline | Configure the status line |
Utilities
| Command | Description |
|---|---|
/doctor | Diagnose and check the health of your install |
/team-onboarding | Generate a teammate ramp-up guide (ONBOARDING.md) from your local usage, shareable via a link |
/bug | Report a bug to Anthropic |
/release-notes | Show what changed in recent versions |
/terminal-setup | Configure Shift+Enter for newlines |
/vim | Toggle vim keybindings in the input |
/quit (or /exit) | Exit Claude Code |
Discover installed commands
/help lists everything available in the current project, including custom commands, bundled skills and anything a plugin adds β so it stays accurate even as the tool evolves.
Extended thinking
Ask Claude to reason harder before acting by including a thinking keyword in your prompt. This allocates a larger reasoning budget β useful for architecture decisions, tricky debugging or multi-step planning.
Roughly ascending budget: think β think hard β think harder β ultrathink. Keep it off for routine edits β it costs tokens and time.
Non-interactive mode
Run a single prompt from the command line (useful for scripts and CI):
Useful flags
| Flag | Description |
|---|---|
-p, --print | Print mode: run once and exit (headless) |
--model | Model for the session (opus, sonnet, haiku, or a full ID) |
--fallback-model | Model to fall back to if the primary is overloaded |
-c, --continue | Continue the most recent conversation |
-r, --resume | Resume a specific session |
--output-format | text, json, or stream-json |
--input-format | text or stream-json (for piping structured input) |
--allowedTools / --disallowedTools | Allow / deny tools without prompting |
--permission-mode | Start in a given mode (plan, acceptEdits, β¦) |
--dangerously-skip-permissions | Skip all permission checks (sandboxes only) |
--append-system-prompt | Append extra instructions to the system prompt |
--add-dir | Grant access to an extra working directory |
--mcp-config | Load MCP servers from a specific file |
--agents | Define subagents inline as JSON |
--session-id | Use a fixed session ID |
--max-turns | Cap the number of agentic turns |
--verbose | Show full tool inputs and outputs |
CLI subcommands
File references
Use @ to include file contents directly in your prompt:
Supports glob patterns, and β when MCP servers expose resources β @server:resource mentions:
Custom instructions (CLAUDE.md)
Claude Code reads instructions from CLAUDE.md files, loaded from your home directory down to the working directory (later files take precedence):
- Enterprise policy β a system-managed file (IT-deployed)
- User β
~/.claude/CLAUDE.md(applies to every project) - Parent directories β walking up from the project
- Project β
./CLAUDE.mdat the repo root (commit it to share) - Local β
./CLAUDE.local.md(personal, gitignore it)
Generate the project file with /init, or let Claude add entries on the fly with #.
@path imports pull another file's contents into the instructions (up to 5 levels deep) β handy for sharing a common style file across repos.
Custom commands
Drop a Markdown file in .claude/commands/ (project) or ~/.claude/commands/ (global) to create a reusable slash command. The filename becomes the command name.
Inside a command you can use $ARGUMENTS (everything passed), positional $1 / $2, embed shell output with !`command`, and reference files with @path.
Skills
Skills package a repeatable workflow, checklist or reference so Claude can pull it in exactly when it's relevant. A skill is a folder with a SKILL.md describing when and how to use it, plus any supporting scripts or files.
Skills live in .claude/skills/ (project) or ~/.claude/skills/ (global). Claude invokes a skill automatically when your request matches its description, or you can trigger it explicitly with /skill-name.
Skill vs subagent
A skill loads instructions into the current conversation β great for procedures and conventions. A subagent runs in its own context window β great for isolating heavy work (research, review) so it doesn't crowd the main thread.
Subagents
Subagents are specialised assistants with their own prompt, tools, and context window β useful for delegating focused tasks (code review, debugging, research) without polluting the main conversation. Manage them with /agents, or define one as Markdown with YAML frontmatter:
The optional model field lets a subagent run on a cheaper/faster model than the main session. Claude delegates to a subagent automatically when the task fits its description, or you can ask for it by name.
Output styles
Change how Claude formats its responses without touching the underlying behaviour:
| Style | Behaviour |
|---|---|
default | Concise, task-focused (the standard) |
explanatory | Adds insight into why it made each choice |
learning | Interactive β leaves small TODOs for you to implement |
Switch with /output-style, or set a default in settings: "outputStyle": "explanatory".
Plugins
Plugins bundle skills, subagents, commands, hooks and MCP servers into one installable package, distributed through marketplaces (a Git repo or URL).
Manage everything interactively with /plugin. Enabled plugins are recorded in settings under enabledPlugins, so a project can ship a curated toolset to the whole team.
Permissions
Claude Code asks before writing files or running commands. You can adjust this per session:
| Option | Description |
|---|---|
--allowedTools | Comma-separated list of tools to allow without prompting |
--disallowedTools | Tools that are always denied |
/add-dir <path> | Allow reads/writes in an extra directory |
Persist rules in settings under permissions, using tool-specific matchers:
Dangerous permissions
--dangerously-skip-permissions disables all permission checks. Only use this in isolated environments (containers, CI).
Permission modes
Press Shift+Tab to cycle between modes during a session:
| Mode | Behavior |
|---|---|
| Normal | Ask before edits and commands (default) |
| Auto-accept edits | Apply file edits without prompting (acceptEdits) |
| Plan | Read-only: Claude explores and proposes a plan, but makes no changes until you approve (plan) |
| Bypass | Skip every permission prompt (bypassPermissions) |
Plan mode is ideal for "explore β plan β implement" workflows on anything non-trivial. Start a session straight in a mode with claude --permission-mode plan.
Hooks
Hooks are shell commands that run automatically at key points in the Claude Code lifecycle. Define them in ~/.claude/settings.json (global) or .claude/settings.json (project).
Each hook receives a JSON payload on stdin (containing the tool name, tool input, etc.) β parse it with jq. The environment variable $CLAUDE_PROJECT_DIR points at the project root.
A hook can also influence the flow by returning JSON on stdout (e.g. {"decision": "block", "reason": "..."} to stop a tool call and feed a message back to Claude) or via its exit code β exit 2 blocks and surfaces stderr to Claude; any other non-zero exit is a non-blocking error.
Hook events
| Event | Triggers when⦠|
|---|---|
PreToolUse | Before a tool call (can block it) |
PostToolUse | After a tool call completes |
UserPromptSubmit | When you submit a prompt (can inject context or block) |
Notification | Claude sends a system notification |
Stop | Claude finishes a response turn |
SubagentStop | A subagent finishes its turn |
SessionStart / SessionEnd | A session starts / ends |
PreCompact | Before the conversation is compacted |
Hook matchers
The matcher field is a regex matched against the tool name:
| Matcher | Matches |
|---|---|
Bash | Shell commands |
Write | File writes (new files) |
Edit | File edits (existing files) |
Read | File reads |
.* | All tools |
MCP servers
Claude Code supports Model Context Protocol servers for extending available tools (and exposing resources you can @-mention).
The quickest way to add one is the claude mcp add command, which writes the config for you:
Project-scoped servers are stored in a .mcp.json file at the repo root (commit it to share with the team):
Manage and inspect servers at runtime with the /mcp slash command.
Configuration
Settings are stored in ~/.claude/settings.json (global) or .claude/settings.json (project-level). A settings.local.json holds personal, gitignored overrides.
Key settings
| Key | Description |
|---|---|
model | Default model |
theme | dark, light, dark-daltonism, light-daltonism |
outputStyle | Default response style (see Output styles) |
includeCoAuthoredBy | Add a Co-Authored-By: Claude trailer to commits |
cleanupPeriodDays | Days before conversation logs are purged (default: 30) |
env | Environment variables passed to all sessions |
apiKeyHelper | Script that prints an API key/token (for rotation) |
permissions | allow / deny / ask rules for tools (see Permissions) |
enabledPlugins | Plugins to enable for this project |
statusLine | Command that renders a custom status line |
hooks | Lifecycle hooks (see Hooks) |
Background tasks
Long-running commands (dev servers, test watchers, builds) can run in the background so the session stays interactive. Press Ctrl+B while a command runs to detach it; Claude keeps a handle on its output and can check on it, read logs, or kill it later. Useful when you want Claude to start poetry run uvicorn and then keep working against the running server.
Workflow: explore β plan β implement
Use plan mode for steps 1β2
Press Shift+Tab to enter plan mode so Claude explores and proposes its approach without editing any files until you approve.
Multi-agent with git worktrees
Run multiple independent Claude Code sessions in parallel using git worktrees:
Isolate long-running tasks
Each worktree has its own working directory and git state, so agents can't interfere with each other.
Tips & recommended patterns
A few habits that pay off, especially on a Python/backend + CI workflow:
- Give it a
CLAUDE.mdearly. Pin the package manager (Poetry), the test command, the linter (ruff), and any project quirks. It stops Claude from guessing on every session. Run/initto bootstrap it. - Auto-format on write. A
PostToolUsehook runningruff format/ruff check --fixonWrite|Editkeeps the diff clean without you asking. - Plan mode for anything multi-file. Migrations, refactors touching many modules, a new endpoint across schema + service + tests β let it lay out the approach first (Shift+Tab), review, then let it build.
- Package repeatable reviews as skills. You already lean on skills (SonarQube review, schema building). Anything you re-explain more than twice β a review checklist, a project scaffold, a release procedure β belongs in a
SKILL.md. - Use the built-in review commands before pushing.
/code-reviewfor bugs,/security-reviewfor vulnerabilities,/verifyto actually run the change end-to-end (not just the tests). - Restrict a review subagent to read-only tools (
Read, Grep, Glob) and put it onhaikuβ cheap, fast, and it can't accidentally edit anything. - Wire it into CI / git hooks.
claude -p "..." --output-format jsonin a pipeline, or apre-commithook that asks Claude to sanity-check the staged diff. - Add the GitHub MCP server so Claude can read issues and PRs directly instead of you pasting them.
- Manage context deliberately.
/clearbetween unrelated tasks,/compactwhen a long session gets sluggish,/contextto see what's eating the window. - Reach for
ultrathinkon genuinely hard design or debugging problems β and skip it for routine edits, since it costs tokens and time.