Claude Code
Claude Code — Workflows
Tool-specific mini-workflows built from verified commands. For cross-tool versions of these workflows, see Example: Understand a new repository (and the other walkthroughs such as Example: Build a new feature end to end) and the feature matrix.
Understand a codebase
cd the-repo
claude
> /init
> give me a high-level tour of this codebase: entry points, data flow, and the riskiest modules
> how does the billing flow work end to end?
> /compact keep the architecture summary
Tips:
/initwrites a starterCLAUDE.mdso future sessions start smarter (see Claude Code — Project Instructions (CLAUDE.md)).- Large explorations are delegated to the read-only Explore subagent automatically, keeping your main context clean (see Claude Code — Subagents).
- Working across repos?
/add-dir ../other-repoorclaude --add-dir. - Use
/btwfor quick asides you don’t want in the conversation history.
Build a feature
claude --permission-mode plan
> /plan add pagination to the /users endpoint
# review the plan, approve it
> implement the plan, then run the tests
> /diff
> commit this with a conventional-commit message
Tips:
- Plan mode is read-only until you approve the plan — the cheapest place to catch a wrong approach (see Claude Code — Permissions).
- Shift+Tab toggles into plan mode at any time.
/diffshows uncommitted changes before you commit.- Long-running implementation?
/backgrounddetaches the session as a background agent; check on it with/tasks.
Debug
cat failing-test-output.log | claude -p "find the root cause"
or interactively:
> the login flow returns a 401 after the token refresh — here's the failing test: [paste]
> form a hypothesis, add logging to confirm it, then fix it
> /rewind # if the fix made things worse — rolls code and conversation back to a checkpoint
Tips:
/rewind(or Esc+Esc) rolls code and conversation back to a checkpoint — the fastest undo./debug [description]diagnoses issues with Claude Code itself;/doctorchecks the installation.- Piped input (
cat file | claude -p "...") is great for large logs that would flood the interactive UI.
Refactor
claude -w refactor-auth # start in an isolated git worktree
> /plan extract the auth logic from middleware.ts into lib/auth/ without changing behavior
> implement it and keep the test suite green after each step
Tips:
--worktree(-w) isolates the refactor at<repo>/.claude/worktrees/<name>so your checkout stays clean.- For sweeping, repetitive changes,
/batch <instruction>decomposes the work into units run in worktrees. /branchforks an earlier conversation if you want to try two refactor strategies.
Code review
> /review 123 # fast single-pass read-only review of PR 123
> /code-review high # multi-agent review of the local diff
> /code-review high --fix # same, but apply the suggested fixes
> /security-review # vulnerability pass on the diff
> /pr-comments 123 # pull in reviewer comments to address
Tips:
/review,/code-review, and/security-revieware distinct: quick read-only PR check, deep multi-agent diff review (low→ultra;ultraruns in the cloud), and security-focused pass.- Resume the session behind a PR with
/resume(paste the PR URL) orclaude --from-pr 123.
Automate with headless mode
# one-shot, machine-readable
claude -p "list the TODO comments in src/" --output-format json
# bounded and budgeted
claude -p "fix the failing tests" --max-turns 10 --max-budget-usd 2 --allowedTools "Bash(pnpm test *)" "Edit" "Read"
# chain runs via session IDs
claude -p "draft the migration" --output-format json # grab session_id from the JSON
claude --resume <session_id> -p "now apply the review feedback"
Tips:
- Built-in and user slash commands are not available in
-pmode. --json-schemagives validated structured output in thestructured_outputfield.- See Claude Code — CLI Flags for the full automation flag set.
Last verified: 2026-09-07
Official sources:
- https://code.claude.com/docs/en/commands.md
- https://code.claude.com/docs/en/cli-reference.md
- https://code.claude.com/docs/en/headless.md
- https://docs.claude.com/en/docs/claude-code/interactive-mode
- https://docs.claude.com/en/docs/claude-code/overview
AI coding tools evolve quickly. If you find outdated information, please open an issue or pull request.