Claude Code: Quick Reference for Developers
Agentic coding tool from Anthropic. Reads your codebase, edits files, runs commands, verifies its own work. Lives in the terminal, integrates with VS Code and JetBrains.
Official docs: docs.anthropic.com/en/claude-code
Install
# macOS / Linux / WSL
curl -fsSL https://claude.ai/install.sh | bash
# Windows PowerShell
irm https://claude.ai/install.ps1 | iex
# Homebrew
brew install --cask claude-code
# WinGet
winget install Anthropic.ClaudeCode
IDE extensions: search “Claude Code” in VS Code marketplace or JetBrains Marketplace.
Start a session:
cd your-project && claude
Settings Files
Four scopes, applied in this order (later overrides earlier):
| Scope | File | Committed? |
|---|---|---|
| Managed (org) | system-deployed | yes (IT) |
| User | ~/.claude/settings.json | no |
| Project | .claude/settings.json | yes |
| Local | .claude/settings.local.json | no |
Key options:
{
"language": "English",
"effortLevel": "medium",
"autoMemoryEnabled": true,
"defaultMode": "default",
"permissions": {
"allow": ["Bash(npm run *)", "Bash(git commit *)"],
"ask": ["Bash(git push *)"],
"deny": ["Bash(rm -rf *)", "Edit(.env*)"]
}
}
Docs: Settings reference
CLAUDE.md
Persistent instructions loaded at session start. Write once, applies every time.
Locations (all loaded, highest priority first):
- Managed (org-wide)
./CLAUDE.mdor./.claude/CLAUDE.md— commit this~/.claude/CLAUDE.md— user-wide- Parent directories (auto-loaded up the tree)
- Subdirectories (loaded on demand)
Import other files: @path/to/file.md or @~/.claude/prefs.md
What to include:
## Commands
- Dev: `npm run dev`
- Test: `npm test`
- Build: `npm run build`
## Style
- TypeScript strict mode
- ES modules only, no CommonJS
- No `any` without a comment
## Architecture
- DB access only through `src/db/` — no direct Prisma in routes
- Error handling pattern: `src/api/errors.ts`
## Do Not
- Edit `src/config/production.ts` without explicit instruction
- Push directly to main
Keep it under 200 lines. Auto-generate with /init.
Path-specific rules in .claude/rules/:
---
paths:
- "src/api/**/*.ts"
---
# API Rules
- Validate inputs with Zod
- Standard error format: `{ error: string, code: string }`
Docs: Memory & CLAUDE.md
Permissions
Rule syntax:
| Pattern | Matches |
|---|---|
Bash | All bash |
Bash(npm *) | Any npm command |
Bash(git commit *) | Any git commit |
Edit(src/**/*.ts) | TS files in src/ |
Edit(.env*) | Any .env file |
WebFetch(domain:api.github.com) | Specific domain |
mcp__github__* | All GitHub MCP tools |
Agent(Explore) | Explore subagent |
Evaluation: deny → ask → allow. First match wins.
Permission modes:
| Mode | Behavior |
|---|---|
default | Prompt per tool |
acceptEdits | Auto-approve file edits |
plan | Read-only, no changes |
auto | Classifier-based safety check |
bypassPermissions | Skip all prompts (containers only) |
claude --permission-mode plan # safe exploration
claude --permission-mode bypassPermissions -p "..." # CI/CD
Docs: Permissions
Built-in Tools
Reads (no approval needed):
Read— file contentsGlob— find files by patternGrep— search file contents (regex)
Writes (approval required):
Edit— targeted string replacementWrite— create or overwrite file
Execution (approval required):
Bash— shell commandsPowerShell— Windows (opt-in)
External (approval required):
WebSearch— web searchWebFetch— fetch a URL
Planning & agents:
Agent— spawn subagent with own contextEnterPlanMode/ExitPlanMode— read-only analysis modeEnterWorktree/ExitWorktree— isolated git worktree
Misc:
TodoWrite— internal checklistsAskUserQuestion— multiple-choice clarificationCronCreate/CronList/CronDelete— scheduled tasks
Hooks
Deterministic commands that fire at lifecycle events. Unlike CLAUDE.md, hooks always run.
Events:
| Event | When |
|---|---|
SessionStart | Session begins/resumes |
PreToolUse | Before tool executes |
PermissionRequest | Before permission dialog |
PostToolUse | After tool succeeds |
PostToolUseFailure | After tool fails |
Stop | Claude finishes responding |
Notification | Claude needs input |
PreCompact / PostCompact | Context compression |
SessionEnd | Session terminates |
Hook types:
// Command
{ "type": "command", "command": "prettier --write ..." }
// Single LLM call (no tools)
{ "type": "prompt", "prompt": "Verify tasks are complete" }
// Agent with tools
{ "type": "agent", "prompt": "Run tests and report failures", "timeout": 120 }
// HTTP POST
{ "type": "http", "url": "http://localhost:8080/hooks", "allowedEnvVars": ["TOKEN"] }
Exit codes: 0 = allow · 2 = block (stderr shown) · other = log only
Common examples:
// Auto-format on edit
{
"hooks": {
"PostToolUse": [{
"matcher": "Edit|Write",
"hooks": [{ "type": "command", "command": "npx prettier --write \"$(jq -r '.tool_input.file_path')\"" }]
}]
}
}
// Block edits to production config
{
"hooks": {
"PreToolUse": [{
"matcher": "Edit|Write",
"hooks": [{ "type": "command", "command": "FILE=$(jq -r '.tool_input.file_path'); [[ $FILE == *production* ]] && echo 'protected' >&2 && exit 2 || exit 0" }]
}]
}
}
// Desktop notification (macOS)
{
"hooks": {
"Notification": [{
"hooks": [{ "type": "command", "command": "osascript -e 'display notification \"Claude needs input\" with title \"Claude Code\"'" }]
}]
}
}
Docs: Hooks guide
MCP Servers
Connect external tools — databases, APIs, services — as first-class tools.
Add a server:
claude mcp add server-name https://api.example.com/mcp # HTTP
claude mcp add github-mcp node /path/to/server.js # local stdio
claude mcp list
Or via .mcp.json (commit to share with team):
{
"mcpServers": {
"github": {
"command": "node",
"args": ["/path/to/github-mcp/index.js"],
"type": "stdio",
"env": { "GITHUB_TOKEN": "$GITHUB_TOKEN" }
},
"postgres": {
"url": "http://localhost:3001/mcp",
"type": "http"
}
}
}
Popular servers: GitHub · GitLab · Slack · Jira · Notion · PostgreSQL · Sentry · AWS
Control via permissions:
{ "permissions": { "allow": ["mcp__github__get_pull_request"], "deny": ["mcp__github__push_files"] } }
Docs: MCP setup
Slash Commands
| Command | What it does |
|---|---|
/help | List all available commands |
/clear | New conversation, reset context |
/compact [focus] | Compress history (/compact focus on auth changes) |
/rewind | Undo recent changes, restore previous state |
/memory | View CLAUDE.md and auto-memory |
/permissions | View/manage tool permissions |
/hooks | Browse configured hooks |
/config | Open settings interface |
/model [name] | Switch model (/model opus) |
/init | Generate CLAUDE.md from codebase |
/review | Review current pull request — reads the diff, checks for issues, summarizes changes |
/commit | Create a commit with an auto-generated message |
/add-dir <path> | Add a working directory |
/cost | Show token usage and cost for session |
/btw <question> | Quick side question without polluting main context |
/agents | List available subagents |
/vim | Toggle vim keybindings |
/rename [name] | Rename current session |
/review detail: Reads the diff of the current branch vs. base, then reports issues, style problems, logic errors, and a short summary. Works best with an active PR or staged changes.
/compact keeps you in context but summarizes older conversation turns. Provide a focus hint to preserve the most relevant history: /compact focus on the payment module refactor.
CLI Flags
claude "Fix the failing tests" # start with task
claude -p "query" < input.txt # non-interactive, read stdin
claude -c # continue last session
claude -r "session-name" "continue..." # resume named session
claude -n "my-feature" # name this session
claude -w feature-branch # isolated git worktree
claude --permission-mode plan # read-only exploration
claude --model opus # switch model
claude --effort high # effort level (low/medium/high/max)
claude --tools "Read,Grep,Glob" # restrict tools
claude --allowedTools "Bash(npm *)" # pre-approve specific commands
claude --append-system-prompt "..." # add instructions to system prompt
claude -p --output-format json "..." # JSON output for scripts
claude -p --max-turns 5 "..." # limit agentic turns
claude --debug "hooks,api" # debug mode
Docs: CLI reference
Auto-Memory
Claude writes notes to itself during sessions. Persists across /clear and compaction.
Location: ~/.claude/projects/<repo>/memory/MEMORY.md
Loaded: first 200 lines at session start
View: /memory
Disable:
CLAUDE_CODE_DISABLE_AUTO_MEMORY=1 claude
# or in settings:
{ "autoMemoryEnabled": false }
Environment Variables
CLAUDE_CODE_DISABLE_AUTO_MEMORY=1 # disable auto-memory
CLAUDE_CODE_SIMPLE=1 # skip auto-discovery (faster startup)
CLAUDE_BASH_MAINTAIN_PROJECT_WORKING_DIR=1 # reset cwd after each Bash command
CLAUDE_CODE_USE_POWERSHELL_TOOL=1 # enable PowerShell tool (Windows)
CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1 # disable background tasks
Quickstart Checklist
- Create
.claude/CLAUDE.md— build commands, style rules, architecture notes. Run/init. - Set
permissions.allowfor your normal workflow commands (npm *,git status,git diff *). - Add
permissions.denyfor things that must never happen (rm -rf *,.env*). - Add
PostToolUsehook to auto-format on edit if you have a formatter. - Connect an MCP server if you use GitHub, a database, or Sentry regularly.
- Use
/clearbetween unrelated tasks. Keep sessions focused.
Docs: docs.anthropic.com/en/claude-code · CLI ref · Settings · Hooks · MCP · Permissions · Memory