Install & First Run Full guide →
Install (npm)
npm install -g @anthropic-ai/claude-code
| Step | Command |
|---|---|
| Install | npm i -g @anthropic-ai/claude-code |
| Set API key | export ANTHROPIC_API_KEY=sk-ant-… |
| Verify | claude --version |
| Launch | claude (in your project dir) |
| Update | npm update -g @anthropic-ai/claude-code |
Quick CLAUDE.md template
# CLAUDE.md — project context for Claude Code ## Stack Node 20 · TypeScript · Postgres · React ## Commands - Build: npm run build - Test: npm test - Lint: npm run lint ## Conventions - kebab-case files, camelCase functions - No default exports - Tests alongside source files ## Off-limits Never edit: src/generated/, .env
CLI Commands Full reference →
Core commands
| Command | What it does |
|---|---|
claude | Launch interactive REPL in cwd |
claude "prompt" | One-shot: run prompt, print, exit |
claude -p "msg" | Pipe-friendly non-interactive mode |
claude --continue | Resume last conversation |
claude --resume <id> | Resume a specific conversation by ID |
claude --model opus | Override model (opus / sonnet / haiku) |
claude --add-dir ./lib | Add extra directory to context |
claude --dangerously-skip-permissions | Skip all prompts (CI/headless only) |
Flags reference
| Flag | Purpose |
|---|---|
--output-format json | JSON output for scripting |
--output-format stream-json | Streaming JSON (pipe-friendly) |
--max-turns N | Limit agentic loop iterations |
--system "…" | Override system prompt |
--allowedTools T1,T2 | Whitelist specific tools only |
--no-mcp | Disable MCP servers this session |
--verbose | Show tool calls and reasoning |
--version | Print version and exit |
Slash Commands (in-REPL) Full reference →
Session
/clear | Reset context |
/compact | Summarise + free tokens |
/memory | View/edit CLAUDE.md files |
/config | Open settings editor |
/status | Token usage & model info |
/help | List all slash commands |
/quit | Exit the REPL |
Code actions
/review | Review current changes |
/commit | Stage + commit with AI message |
/pr | Create a pull request |
/test | Run test suite, fix failures |
/lint | Run linter, auto-fix issues |
/build | Run build command from config |
/fix | Fix last error or lint warning |
Model & tools
/model | Switch model in-session |
/fast | Toggle fast (Opus) mode |
/tools | List available tools |
/mcp | Manage MCP connections |
/permissions | View granted permissions |
/bug | File a bug report |
/doctor | Diagnose setup issues |
Keyboard Shortcuts Full reference →
REPL input
| Key | Action |
|---|---|
| Enter | Submit prompt |
| Shift+Enter | New line (multi-line input) |
| ↑ / ↓ | Navigate history |
| Ctrl+C | Cancel current generation |
| Ctrl+L | Clear screen |
| Ctrl+R | Search history (if shell) |
| Tab | Autocomplete file paths & commands |
| Esc | Cancel input / go back |
During generation
| Key | Action |
|---|---|
| Ctrl+C | Interrupt generation |
| Ctrl+Z | Suspend to background |
| y / Enter | Approve a tool call |
| n | Deny a tool call |
| a | Approve + allow all similar |
| d | View full diff before approving |
| e | Edit the tool call before approving |
| ? | Help (permission prompt options) |
Settings & Config Full reference →
Settings file locations
| Scope | Path |
|---|---|
| global | ~/.claude/settings.json |
| project | .claude/settings.json |
| local | .claude/settings.local.json |
| Context | CLAUDE.md (any dir in tree) |
Project settings override global; local overrides both. Commit
settings.json, gitignore settings.local.json.Key settings (settings.json)
{
"model": "claude-opus-4-5",
"permissions": {
"allow": ["Bash(git *)", "Bash(npm *)"],
"deny": ["Bash(rm -rf *)"]
},
"hooks": {
"PostToolUse": [{
"matcher": "Bash",
"hooks": [{"type": "command",
"command": "echo 'ran bash'"}]
}]
},
"env": {
"NODE_ENV": "development"
}
}
CLAUDE.md Patterns Memory guide →
Essential sections
| Section | What to include |
|---|---|
## Stack | Languages, frameworks, Node/Python version |
## Commands | build, test, lint, dev-server commands |
## Conventions | Naming, file structure, export style |
## Architecture | Key dirs, data flow, module layout |
## Testing | Test framework, pattern, where files live |
## Off-limits | Auto-generated files, secrets, migrations |
## Deploy | How to deploy (command, env vars needed) |
Advanced patterns
# Scoped context (applies only in src/api/) # src/api/CLAUDE.md ## API module rules - All routes must validate with Zod - Errors: throw AppError, not raw Error - No direct DB calls — use the repo layer # ~/.claude/CLAUDE.md (global defaults) ## My defaults - Prefer functional style - Always add return types in TypeScript - Ask before creating new files
Permissions & Safety
Permission syntax
| Pattern | Meaning |
|---|---|
Bash | All bash commands |
Bash(git *) | Only git commands |
Bash(npm run *) | Only npm scripts |
Write | All file writes |
Write(src/*) | Only writes in src/ |
Read | All file reads |
WebFetch(*) | All HTTP fetches |
Env vars (runtime)
| Var | Effect |
|---|---|
ANTHROPIC_API_KEY | Required — your API key |
CLAUDE_NO_CONFIRM=1 | Skip all permission prompts (CI) |
CLAUDE_MODEL | Default model override |
CLAUDE_MAX_TOKENS | Cap response length |
ANTHROPIC_BASE_URL | Proxy / custom endpoint |
Safety checklist
| ✅ | Review every diff before approving |
| ✅ | CLAUDE.md: declare off-limits files |
| ✅ | Use deny rules for destructive cmds |
| ✅ | Never set CLAUDE_NO_CONFIRM=1 locally |
| ✅ | Separate API key per developer / CI |
| ✅ | Add .claude/ to .gitignore for local settings |
| ✅ | Run in a branch — never directly on main |
MCP (Model Context Protocol) Full guide →
Register an MCP server
# .claude/settings.json
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres",
"postgresql://localhost/mydb"]
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {"GITHUB_TOKEN": "${GITHUB_TOKEN}"}
}
}
}
Useful MCP servers
| Server | Gives Claude access to |
|---|---|
@mcp/server-github | Issues, PRs, repos |
@mcp/server-postgres | SQL queries on local DB |
@mcp/server-sqlite | Local SQLite databases |
@mcp/server-filesystem | Expanded filesystem access |
@mcp/server-slack | Slack channels & threads |
@mcp/server-puppeteer | Browser automation |
@mcp/server-sentry | Error tracking & issues |
Run
claude /mcp to list connected servers and their available tools.Hooks Full guide →
Hook events
| Event | Fires when |
|---|---|
PreToolUse | Before any tool call (can block) |
PostToolUse | After tool completes |
Notification | Claude sends a user notification |
Stop | Claude finishes responding |
SubagentStop | A sub-agent completes |
Hook recipes
# Auto-run tests after every file write "PostToolUse": [{ "matcher": "Write", "hooks": [{"type": "command", "command": "npm test -- --passWithNoTests"}] }] # Desktop notification when done "Stop": [{ "hooks": [{"type": "command", "command": "notify-send 'Claude done'"}] }]
Workflow One-liners
Git workflows
| Task | Command |
|---|---|
| Smart commit | claude /commit |
| Review my PR | claude /review |
| Create PR | claude /pr |
| Explain diff | git diff | claude -p "explain" |
| Write changelog | git log --oneline | claude -p "write changelog" |
| Summarise PR | gh pr diff 42 | claude -p "summarise" |
Code operations
| Task | Command |
|---|---|
| Fix lint errors | npm run lint 2>&1 | claude -p "fix" |
| Explain file | claude "explain src/auth.ts" |
| Add tests | claude "write tests for src/utils.ts" |
| Refactor fn | claude "refactor getUser for readability" |
| Find bug | cat error.log | claude -p "what caused this" |
| Headless CI | CLAUDE_NO_CONFIRM=1 claude -p "run checks" |
Sub-agents & Parallel Work Full guide →
# Ask Claude Code to spawn parallel sub-agents "Run these tasks in parallel using sub-agents: 1. Write unit tests for src/api/users.ts 2. Update the API docs in docs/api.md 3. Check for TypeScript errors in src/lib/" # Each sub-agent gets its own context + tool access # Use when tasks are independent (no shared files) # Results are synthesised by the orchestrator Claude
Sub-agents are most effective for parallel research, independent file edits, or multi-repo operations. Avoid for tasks with inter-dependencies — conflicts from parallel writes are hard to reconcile.
All Guides
Setup & Config
Workflows
- → Git Workflow
- → GitHub Integration
- → Code Review
- → Debugging
- → Refactoring
- → Testing
- → CI/CD