Claude Code is an agentic AI coding tool by Anthropic — reads your codebase, edits files, runs commands, and integrates with your development tools.
$ curl -fsSL https://claude.ai/install.sh | bash
> irm https://claude.ai/install.ps1 | iex
$ brew install --cask claude-code
> winget install Anthropic.ClaudeCode
Native install auto-updates. Homebrew/WinGet require brew upgrade claude-code or winget upgrade Anthropic.ClaudeCode to update.
Windows requires Git for Windows.
$ cd your-project
$ claude
/help for all commands/resume to continue a prior conversation? to see keyboard shortcutsexit or press Ctrl+D to quit| Concept | Description |
|---|---|
| Agent loop | Claude reads, edits files, runs commands, and repeats |
| CLAUDE.md | Persistent instructions Claude reads every session |
| Auto memory | Claude saves learnings across sessions automatically |
| Skills | Custom /commands for reusable workflows |
| Hooks | Shell scripts triggered at lifecycle events |
| MCP | Connect Claude to external tools and APIs |
| Permission mode | Controls what Claude can do without asking |
what does this project do?find the bug causing the login errorwrite unit tests for the auth modulerefactor this to use async/awaitcommit my changes with a descriptive messagecreate a PR and describe my changesreview my changes for security issuesadd input validation to the signup form| Command | Description |
|---|---|
claude |
Start interactive session |
claude "task" |
Start with initial prompt |
claude -p "query" |
Print response and exit |
claude -c |
Continue most recent conversation |
claude -r [name] |
Resume session by name or ID |
claude -n "name" |
Name this session |
claude -w [name] |
Start in isolated git worktree |
claude update |
Update to latest version |
claude -v |
Show version number |
claude doctor |
Check installation health |
claude auto-mode defaults |
Print auto mode classifier rules |
claude agents |
List configured subagents |
| Command | Description |
|---|---|
claude auth login |
Sign in to account |
claude auth login --console |
Sign in with Anthropic Console |
claude auth logout |
Sign out |
claude auth status |
Show auth status |
| Command | Description |
|---|---|
claude mcp list |
List configured servers |
claude mcp add <n> <cmd> |
Add a stdio MCP server |
claude mcp get <name> |
Show server details |
claude mcp remove <name> |
Remove a server |
claude mcp serve |
Start Claude as MCP server |
| Command | Description |
|---|---|
claude plugin install <name> |
Install a plugin |
claude plugin list |
List installed plugins |
claude plugin remove <name> |
Remove a plugin |
# Explain a build error
$ cat error.log | claude -p "explain the root cause"
# Review changed files
$ git diff main --name-only | claude -p "review for issues"
# Analyze logs
$ tail -200 app.log | claude -p "summarize anomalies"
# Save output to file
$ cat data.txt | claude -p "summarize this" > summary.txt
Add Claude as a linter in package.json:
{
"scripts": {
"lint:ai": "claude -p 'review changes vs main, report file:line + issue'"
}
}
Use --output-format for structured output:
$ claude -p "analyze for bugs" --output-format json
| Flag | Description |
|---|---|
--model <model> |
Model alias: sonnet, opus, or full ID |
--permission-mode <m> |
Set permission mode at startup |
-c, --continue |
Load most recent conversation |
-r, --resume [id] |
Resume by session ID or name |
-n, --name <name> |
Name the current session |
-w, --worktree [name] |
Create isolated git worktree |
-p, --print |
Non-interactive print mode |
--effort <level> |
low medium high max |
--ide |
Auto-connect to IDE on startup |
--verbose |
Show full turn-by-turn output |
--debug [filter] |
Enable debug (e.g. "api,hooks") |
--fork-session |
New ID when resuming |
--from-pr [num] |
Resume sessions linked to PR |
--version, -v |
Print version number |
| Flag | Description |
|---|---|
--output-format |
text / json / stream-json |
--input-format |
text or stream-json |
--max-turns <n> |
Limit agentic turns |
--max-budget-usd <n> |
Spending cap (print mode) |
--json-schema <s> |
Validate structured output |
--include-partial-messages |
Stream partial chunks |
--no-session-persistence |
Don't save session to disk |
--fallback-model <m> |
Fallback when overloaded |
| Flag | Description |
|---|---|
--allowedTools <tools> |
Pre-approve tools (no prompt) |
--disallowedTools <tools> |
Deny specific tools |
--tools <list> |
Restrict available tools |
--add-dir <dirs> |
Extra directories to access |
--dangerously-skip-permissions |
Bypass all permission checks |
--allow-dangerously-skip-permissions |
Add bypass to mode cycle |
--enable-auto-mode |
Add auto to Shift+Tab cycle |
--bare |
Minimal mode (no hooks/memory) |
--mcp-config <file> |
Load MCP config from file |
--strict-mcp-config |
Only use CLI MCP config |
| Flag | Behavior |
|---|---|
--system-prompt <text> |
Replace entire default prompt |
--system-prompt-file <file> |
Replace from file |
--append-system-prompt <text> |
Append to default prompt |
--append-system-prompt-file <f> |
Append from file |
Prefer --append-* to preserve Claude's built-in capabilities. Use --system-prompt only when full control is needed.
| Command | Description |
|---|---|
/clear |
Clear history (aliases: /new, /reset) |
/compact [focus] |
Compact context with optional focus |
/resume [name] |
Resume session (alias: /continue) |
/branch [name] |
Fork conversation (alias: /fork) |
/rewind |
Undo to checkpoint (alias: /checkpoint) |
/diff |
View uncommitted changes interactively |
/export [file] |
Export conversation as plain text |
/copy [N] |
Copy Nth-last response to clipboard |
/cost |
Show token usage stats |
/usage |
Show plan limits and rate limit status |
/context |
Visualize context window usage |
/btw <q> |
Side question without adding to history |
| Command | Description |
|---|---|
/plan [desc] |
Enter plan (read-only) mode |
/security-review |
Audit branch changes for vulnerabilities |
/pr-comments [PR] |
Fetch GitHub PR comments |
/install-github-app |
Set up GitHub Actions integration |
/install-slack-app |
Install Slack integration |
| Command | Description |
|---|---|
/config |
Open settings (alias: /settings) |
/model [model] |
Change AI model |
/effort [level] |
Set effort: low medium high max |
/permissions |
Manage allow / ask / deny rules |
/hooks |
View configured hooks |
/memory |
Edit CLAUDE.md and auto memory |
/mcp |
Manage MCP server connections |
/agents |
Manage subagent configurations |
/skills |
List available skills |
/plugin |
Manage installed plugins |
/keybindings |
Open keybindings config file |
| Command | Description |
|---|---|
/theme |
Change color theme |
/vim |
Toggle vim editing mode |
/color [color] |
Set prompt bar color |
/statusline |
Configure status line display |
/stats |
View daily usage and streaks |
/insights |
Analyze session patterns |
/fast [on\|off] |
Toggle fast mode |
/powerup |
Interactive feature tour |
/tasks |
Manage background tasks |
/add-dir <path> |
Add working directory |
| Command | Description |
|---|---|
/help |
Show available commands |
/init |
Generate CLAUDE.md for project |
/doctor |
Diagnose installation |
/voice |
Toggle voice dictation |
/schedule [desc] |
Create cloud scheduled task |
/login |
Sign in to account |
/logout |
Sign out |
/feedback |
Submit feedback (alias: /bug) |
/release-notes |
View changelog |
/status |
Show version, model, account info |
| Shortcut | Description |
|---|---|
Ctrl+C |
Cancel current input or generation |
Ctrl+D |
Exit Claude Code |
Shift+Tab |
Cycle permission modes |
Ctrl+R |
Reverse search command history |
Ctrl+G |
Open prompt in text editor |
Ctrl+L |
Redraw the screen |
Ctrl+O |
Toggle verbose output |
Ctrl+V |
Paste image from clipboard |
Ctrl+B |
Background the running command |
Ctrl+T |
Toggle task list display |
Esc Esc |
Rewind or summarize conversation |
Option+P |
Switch model (macOS) |
Option+T |
Toggle extended thinking (macOS) |
Option+O |
Toggle fast mode (macOS) |
| Shortcut | Description |
|---|---|
Ctrl+K |
Delete to end of line |
Ctrl+U |
Delete to start of line |
Ctrl+Y |
Paste deleted text |
Alt+Y |
Cycle paste history |
Alt+B |
Move back one word |
Alt+F |
Move forward one word |
Enable with /vim or in /config. Esc → NORMAL, i/a/o → INSERT.
| Key | Action |
|---|---|
h j k l |
Move left / down / up / right |
w / b |
Next / previous word |
0 / $ |
Line start / end |
gg / G |
Input start / end |
dd / yy |
Delete / yank line |
cc / p |
Change line / paste |
f{c} / F{c} |
Jump to character |
. |
Repeat last change |
| Method | How |
|---|---|
| Multiline (all terminals) | \ then Enter |
| Multiline (macOS default) | Option+Enter |
| Multiline (modern terms) | Shift+Enter |
| Run bash directly | ! prefix |
| File path autocomplete | @ prefix |
| All commands / skills | / prefix |
| Session picker shortcut | P preview, R rename |
macOS: set Option as Meta in terminal prefs for Alt+* shortcuts to work.
| Mode | What Claude does without asking | Best for |
|---|---|---|
default |
Read files only | Getting started, sensitive work |
acceptEdits |
Read + edit files | Active coding, iteration |
plan |
Read only, writes a plan file | Exploration, planning before editing |
auto |
All actions with background classifier | Long tasks, fewer interruptions |
dontAsk |
Only pre-approved tools | Locked CI/CD environments |
bypassPermissions |
All actions except protected dirs | Containers and VMs only |
Regardless of mode, writes to .git, .vscode, .idea, .husky, and .claude always prompt (except .claude/commands, .claude/agents, .claude/skills).
{
"permissions": {
"defaultMode": "acceptEdits"
}
}
Requires Team / Enterprise / API plan + Claude Sonnet 4.6 or Opus 4.6. A separate classifier reviews each action before it runs and blocks actions that escalate beyond your intent. Enable at startup:
$ claude --enable-auto-mode
During a session:
Press Shift+Tab to cycle:
default → acceptEdits → plan → (auto)
At startup:
$ claude --permission-mode plan
$ claude --permission-mode acceptEdits
Bypass all (containers only):
$ claude --dangerously-skip-permissions
Layer allow / deny rules on top of any mode in .claude/settings.json:
{
"permissions": {
"allow": ["Bash(npm test)", "Bash(git log *)"],
"deny": ["Bash(rm -rf *)"]
}
}
View and edit rules with /permissions.
| Scope | Location | Shared with |
|---|---|---|
| Managed policy | System-level (IT/DevOps deployed) | All users on machine |
| Project | ./CLAUDE.md or ./.claude/CLAUDE.md |
Team via git |
| User | ~/.claude/CLAUDE.md |
Personal, all projects |
| Local | ./CLAUDE.local.md (add to .gitignore) |
Personal, this project |
Files in parent directories load at launch. Subdirectory files load on demand when Claude reads files there. More specific scope wins on conflict.
"Use 2-space indentation" not "format code nicely"Run /init to auto-generate a CLAUDE.md from your codebase. Set CLAUDE_CODE_NEW_INIT=1 for an interactive multi-phase flow that also sets up skills and hooks.
.claude/rules/.claude/
├── CLAUDE.md
└── rules/
├── code-style.md # style guidelines
├── testing.md # test conventions
└── security.md # security requirements
---
paths:
- 'src/api/**/*.ts'
- 'tests/**/*.test.ts'
---
# API Rules
All endpoints must include input validation.
Rules without paths load every session. Rules with paths load only when matching files are opened.
Claude saves its own notes in:
~/.claude/projects/<project>/memory/
├── MEMORY.md # index (first 200 lines loaded)
├── debugging.md # topic files (loaded on demand)
└── api-conventions.md
/memory or set autoMemoryEnabled: falseDisable via env:
$ export CLAUDE_CODE_DISABLE_AUTO_MEMORY=1
Reference other files from CLAUDE.md:
See @README.md for project overview.
Build commands: @package.json
# Workflows
@docs/git-workflow.md
| Event | When it fires |
|---|---|
SessionStart |
Session begins, resumes, or clears |
UserPromptSubmit |
User submits a prompt |
PreToolUse |
Before a tool executes |
PermissionRequest |
Before permission dialog shows |
PostToolUse |
After tool completes successfully |
PostToolUseFailure |
After tool execution fails |
PermissionDenied |
Auto mode classifier denies action |
Stop |
Claude finishes responding |
StopFailure |
Turn ends due to API error |
Notification |
Claude needs attention |
SubagentStart |
Subagent is spawned |
SubagentStop |
Subagent finishes |
FileChanged |
Watched file changes on disk |
PreCompact |
Before context compaction |
PostCompact |
After context compaction |
WorktreeCreate |
Worktree being created |
WorktreeRemove |
Worktree being removed |
InstructionsLoaded |
CLAUDE.md file loaded |
ConfigChange |
Settings file changes |
TaskCreated |
Task created via TaskCreate |
TaskCompleted |
Task marked complete |
Exit codes: 0 = success (JSON decision), 2 = block action (stderr to model), other = non-blocking error.
Use $CLAUDE_PROJECT_DIR to reference hook scripts relative to the project root.
| Type | Description |
|---|---|
command |
Run shell script, reads JSON from stdin |
http |
POST JSON to an HTTP endpoint |
prompt |
Ask Claude for a yes/no decision |
agent |
Spawn subagent with tools to verify |
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "npm run lint --silent"
}
]
}
]
}
}
{
"hooks": {
"Notification": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "osascript -e 'display notification \"Claude needs attention\" with title \"Claude Code\"'"
}
]
}
]
}
}
Config in ~/.claude/settings.json (user) or .claude/settings.json (project). View hooks with /hooks.
$ claude mcp add my-server -- npx my-mcp-server
$ claude mcp add -e KEY=val my-server -- npx server
$ claude mcp add --transport http sentry https://mcp.sentry.dev/mcp
$ claude mcp add --transport http my-api https://api.example.com/mcp --header "Authorization: Bearer $TOKEN"
$ claude mcp add-json my-server '{"command":"npx","args":["my-mcp"]}'
$ claude mcp add-from-claude-desktop
$ claude mcp list # list all servers
$ claude mcp get <name> # show server details
$ claude mcp remove <name> # remove a server
Config stored in ~/.claude/settings.json (user) or .claude/settings.json (project).
Reference MCP resources with @:
@github:repos/owner/repo/issues
@memory:entities
@filesystem:/path/to/file
Run MCP prompts as slash commands:
/mcp__github__search_repositories
/mcp__memory__create_entities
MCP tool pattern: mcp__<server>__<tool>
Manage in session:
/mcp
Hook on MCP tools:
{
"hooks": {
"PreToolUse": [
{
"matcher": "mcp__memory__.*",
"hooks": [{ "type": "command", "command": "logger.sh" }]
}
]
}
}
Run parallel sessions in isolated branches:
# Create worktree and start Claude
$ claude --worktree feature-auth
$ claude -w bugfix-123
# Auto-generated name
$ claude --worktree
Worktrees are created at .claude/worktrees/<name>/ and branch from origin/HEAD.
Auto-cleanup: no changes → removed on exit. With changes → Claude prompts to keep or remove.
Add to .gitignore:
.claude/worktrees/
Create .worktreeinclude in project root:
.env
.env.local
config/secrets.json
# Create with specific branch
$ git worktree add ../project-feat -b feat
# List all worktrees
$ git worktree list
# Remove when done
$ git worktree remove ../project-feat
Re-sync origin HEAD after remote branch change:
$ git remote set-head origin -a
Create in .claude/agents/<name>.md:
---
name: code-reviewer
description: Reviews code for bugs and style
tools:
- Read
- Grep
- Glob
---
You are an expert code reviewer.
Focus on correctness and clarity.
Use subagents naturally in conversation:
review the auth module for security issuesuse the code-reviewer agent on api.ts/agents — manage agent configsSubagent with worktree isolation:
---
name: parallel-worker
isolation: worktree
description: Works in isolated branch
---
Shared auto memory for subagents — add to frontmatter:
autoMemoryEnabled: true
Run Claude programmatically with -p / --print:
# Basic one-off query
$ claude -p "what does this file do?"
# Stream JSON (real-time events)
$ claude -p "query" --output-format stream-json
# JSON with full metadata
$ claude -p "query" --output-format json
# Limit turns and cost
$ claude -p "query" --max-turns 5 --max-budget-usd 1.00
# Validated structured output
$ claude -p "query" --json-schema '{"type":"object"}'
# Continue most recent session
$ claude -c -p "follow-up question"
# Resume named session
$ claude -r my-session -p "continue the task"
| Format | Use case |
|---|---|
text |
Human-readable (default) |
json |
Full metadata + cost info |
stream-json |
Real-time per-turn events |
$ claude --bare -p "query"
Skips hooks, CLAUDE.md auto-discovery, plugins, MCP, and auto memory. Sets CLAUDE_CODE_SIMPLE=1. Ideal for scripting.
# Don't save session to disk
$ claude -p "query" --no-session-persistence
Create a cloud scheduled task:
/schedule review open PRs every morning at 9am
Session-scoped loop (stays open):
/loop 5m check for new issues
- uses: anthropics/claude-code-action@beta
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
prompt: 'review this PR for issues and comment'
claude-review:
script:
- claude -p "review changes in this MR"
--output-format json
| Scheduling option | Runs on |
|---|---|
| Cloud scheduled tasks | Anthropic infrastructure |
| Desktop scheduled tasks | Your local machine |
| GitHub Actions | CI/CD pipeline |
/loop |
Current CLI session only |