index / guides / claude-code-guide

Claude Code: Quick Reference for Developers

Compact cheat sheet — installation, CLAUDE.md, permissions, hooks, MCP, tools, slash commands, and CLI flags. With links to official docs.

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):

ScopeFileCommitted?
Managed (org)system-deployedyes (IT)
User~/.claude/settings.jsonno
Project.claude/settings.jsonyes
Local.claude/settings.local.jsonno

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):

  1. Managed (org-wide)
  2. ./CLAUDE.md or ./.claude/CLAUDE.md — commit this
  3. ~/.claude/CLAUDE.md — user-wide
  4. Parent directories (auto-loaded up the tree)
  5. 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:

PatternMatches
BashAll 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:

ModeBehavior
defaultPrompt per tool
acceptEditsAuto-approve file edits
planRead-only, no changes
autoClassifier-based safety check
bypassPermissionsSkip 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 contents
  • Glob — find files by pattern
  • Grep — search file contents (regex)

Writes (approval required):

  • Edit — targeted string replacement
  • Write — create or overwrite file

Execution (approval required):

  • Bash — shell commands
  • PowerShell — Windows (opt-in)

External (approval required):

  • WebSearch — web search
  • WebFetch — fetch a URL

Planning & agents:

  • Agent — spawn subagent with own context
  • EnterPlanMode / ExitPlanMode — read-only analysis mode
  • EnterWorktree / ExitWorktree — isolated git worktree

Misc:

  • TodoWrite — internal checklists
  • AskUserQuestion — multiple-choice clarification
  • CronCreate / CronList / CronDelete — scheduled tasks

Hooks

Deterministic commands that fire at lifecycle events. Unlike CLAUDE.md, hooks always run.

Events:

EventWhen
SessionStartSession begins/resumes
PreToolUseBefore tool executes
PermissionRequestBefore permission dialog
PostToolUseAfter tool succeeds
PostToolUseFailureAfter tool fails
StopClaude finishes responding
NotificationClaude needs input
PreCompact / PostCompactContext compression
SessionEndSession 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

CommandWhat it does
/helpList all available commands
/clearNew conversation, reset context
/compact [focus]Compress history (/compact focus on auth changes)
/rewindUndo recent changes, restore previous state
/memoryView CLAUDE.md and auto-memory
/permissionsView/manage tool permissions
/hooksBrowse configured hooks
/configOpen settings interface
/model [name]Switch model (/model opus)
/initGenerate CLAUDE.md from codebase
/reviewReview current pull request — reads the diff, checks for issues, summarizes changes
/commitCreate a commit with an auto-generated message
/add-dir <path>Add a working directory
/costShow token usage and cost for session
/btw <question>Quick side question without polluting main context
/agentsList available subagents
/vimToggle 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

  1. Create .claude/CLAUDE.md — build commands, style rules, architecture notes. Run /init.
  2. Set permissions.allow for your normal workflow commands (npm *, git status, git diff *).
  3. Add permissions.deny for things that must never happen (rm -rf *, .env*).
  4. Add PostToolUse hook to auto-format on edit if you have a formatter.
  5. Connect an MCP server if you use GitHub, a database, or Sentry regularly.
  6. Use /clear between unrelated tasks. Keep sessions focused.

Docs: docs.anthropic.com/en/claude-code · CLI ref · Settings · Hooks · MCP · Permissions · Memory