# Claude Code essentials

Source: https://codewiki.com/cheatsheets/claude-code/

## Launch and diagnose

- `claude` — start an interactive session in the current directory
- `claude 'explain this repository'` — start interactively with an initial prompt
- `claude -p 'summarize src/auth/'` — print one result and exit
- `cat test.log | claude -p 'explain the failure'` — send standard input with a non-interactive prompt
- `claude --version` — print the installed Claude Code version
- `claude doctor` — check installation health and report configuration errors

## Scope a task

- `Read src/auth/; do not edit yet; map the request flow.` — explore the named area without writing
- `Plan this change; list files, risks, and verification commands.` — require a plan with concrete impact and checks
- `Implement issue #123; change only src/auth/ and tests/auth/.` — state the deliverable and writable paths
- `Preserve the public API; ask before changing the contract.` — put an approval gate before an interface change
- `Stop if credentials, network access, or a migration is required.` — surface capability expansion before acting
- `Finish only after tests pass; report commands and exit codes.` — define completion with reproducible evidence

## Project instructions

- `/init` — generate or improve starter project instructions
- `CLAUDE.md` — store shared instructions at the project root
- `~/.claude/CLAUDE.md` — store personal instructions for every project
- `CLAUDE.local.md` — store private project instructions and keep them out of Git
- `.claude/rules/testing.md` — store project rules split by path or topic
- `@docs/testing.md` — import a file from inside `CLAUDE.md`
- `@AGENTS.md` — reuse cross-agent instructions from `CLAUDE.md`

## Context

- `Explain @src/auth/session.ts` — attach one file's full contents to the prompt
- `Map @src/auth/` — attach a directory listing, not every file's contents
- `/add-dir ../shared` — grant the current session access to another directory
- `/context` — show what occupies the context window
- `/compact keep the failing test output and current plan` — summarize the session with an explicit focus
- `/clear completed-task` — start with empty context and name the previous conversation
- `/rewind` — restore code or conversation from a checkpoint

## Permissions

- `/permissions` — view and edit allow, ask, and deny rules
- `/plan fix the auth bug` — enter plan mode and begin the stated task
- `claude --permission-mode plan` — start a read-only planning session
- `claude --permission-mode dontAsk --allowedTools 'Read,Grep,Glob'` — approve listed read tools and deny anything else
- `claude --disallowedTools 'Read(./.env)' 'Read(./secrets/**)'` — deny reads from two sensitive paths
- `claude --restricted -p 'inspect this repository'` — run one non-interactive check with restricted tools and settings

## Sessions and isolation

- `/rename auth-refactor` — name the current session for later lookup
- `claude -c` — continue the latest conversation for this directory
- `claude -r auth-refactor 'finish the tests'` — resume a named session with a new prompt
- `claude -r auth-refactor --fork-session` — resume as a copy with a new session ID
- `/branch alternate-fix` — branch the conversation without creating a Git branch
- `claude -w auth-refactor` — create an isolated Git worktree for a new session

## Model and effort

- `/model` — open the model picker
- `/model sonnet` — switch models and save the default for new sessions
- `/effort high` — set the current session's reasoning effort
- `/effort status` — print the current effort level
- `claude --model sonnet --effort high` — choose model and effort for this launch only

## Review and verify

- `/diff` — inspect uncommitted and per-turn diffs interactively
- `/code-review high` — review the current diff for correctness at high effort
- `/code-review high 123` — review pull request 123 at high effort
- `/security-review` — check the current branch against the origin default branch for vulnerabilities
- `/verify` — build and run the application to verify observed behavior
- `Compare the diff with the acceptance criteria; cite each gap by file and line.` — turn unmet requirements into traceable findings

## Specs and tests

- `Restate the acceptance criteria as observable behavior before editing.` — turn the request into pass-or-fail observations
- `Before refactoring, add characterization tests for current behavior.` — pin legacy behavior before structural changes
- `Reproduce the bug with a failing test before changing production code.` — capture evidence that fails before the fix
- `Keep existing tests; add boundary, error, and cancellation cases.` — cover success paths and relevant failure modes
- `Run the narrowest relevant test first, then the full required suite.` — get focused feedback before the delivery gate
- `Do not weaken assertions or remove tests solely to make the suite pass.` — protect the specification from test tampering
- `If behavior changes, update the API contract and tests together.` — keep implementation, contract, and evidence aligned

## Non-interactive automation

- `claude -p 'review the current diff' --output-format text` — emit plain text and exit
- `claude -p 'summarize the diff' --output-format json` — emit one JSON result object
- `claude -p 'review the diff' --output-format stream-json --verbose` — emit streaming JSON events
- `claude -p 'return a summary' --json-schema '{"type":"object","properties":{"summary":{"type":"string"}},"required":["summary"]}'` — validate the final JSON object against a schema
- `claude -p 'review the diff' --max-budget-usd 1` — cap API-call spending at one US dollar
- `claude -p 'review the diff' --max-turns 8` — stop with an error after eight unfinished agentic turns
- `claude -p 'one-shot check' --no-session-persistence` — leave no resumable session

## MCP tools

- `claude mcp add --transport http sentry https://mcp.sentry.dev/mcp` — add a local-scope HTTP server configuration
- `claude mcp list` — list configured servers and their connection status
- `claude mcp get sentry` — inspect one server's configuration and status
- `claude mcp login sentry` — start OAuth authentication for an HTTP server
- `/mcp` — inspect server status and authentication inside a session
- `claude mcp remove sentry` — remove the local-scope server configuration

## Subagents and skills

- `.claude/agents/code-reviewer.md` — store a project-scoped subagent definition
- `claude --agent code-reviewer` — run the whole session as a configured subagent
- `/subtask inspect the parser for race conditions` — fork a background subagent with the current conversation
- `/tasks` — view and manage background work in this session
- `.claude/skills/fix-issue/SKILL.md` — store a reusable project skill
- `/skills` — list discovered skills and manage their visibility
- `/fix-issue 123` — invoke a skill and pass `123` as its arguments
