Quick Reference
A dense, scannable cheat sheet of commands, shortcuts, patterns, and troubleshooting tips. Bookmark this page for fast lookups.
Essential Slash Commands
Type these directly into the Claude Code prompt. All commands start with /.
| Command | Description |
|---|---|
| /help | Show all available commands and usage tips |
| /clear | Clear conversation history and start fresh (keeps CLAUDE.md context) |
| /compact | Condense the conversation to save context window space |
| /cost | Show current session token usage and cost breakdown |
| /doctor | Run diagnostic checks on your Claude Code installation |
| /init | Create a CLAUDE.md file for the current project with sensible defaults |
| /login | Switch accounts or re-authenticate |
| /logout | Log out of your current session |
| /memory | Open and edit the project CLAUDE.md directly |
| /model | Switch between available Claude models mid-session |
| /permissions | View and manage tool permissions (allow/deny rules) |
| /review | Review pending file changes before accepting them |
| /status | Show current session info: model, project, context usage |
| /terminal-setup | Configure terminal integration (shell, theme, key bindings) |
| /vim | Toggle vim keybindings for the input prompt |
Keyboard Shortcuts
These shortcuts work in the Claude Code input prompt.
| Shortcut | Action |
|---|---|
| Escape | Interrupt Claude while it is generating a response |
| Ctrl + C | Cancel the current input or running command |
| Ctrl + D | Exit Claude Code (end session) |
| Ctrl + L | Clear the terminal screen (keeps conversation history) |
| Up / Down | Navigate through your previous prompts |
| Shift + Enter | Insert a newline in the input (multi-line prompt) |
| Tab | Autocomplete file paths and slash commands |
| Enter | Send the current prompt to Claude |
y (yes once), n (deny), or a (always allow this tool for the session).Common Patterns
Copy-and-adapt these prompt patterns for everyday tasks.
Explain Code
Explain what src/services/auth.ts does. Focus on the token refresh logic and how it handles expired sessions.
Find and Fix Bugs
Users are reporting 500 errors on POST /api/orders. Check the route handler in src/routes/orders.ts, the validation logic, and the database query. Find the bug and fix it.
Write Tests
Write unit tests for src/utils/formatCurrency.ts. Cover edge cases: negative numbers, zero, very large numbers, different locales. Use the testing patterns from tests/utils/formatDate.test.ts as a reference.
Refactor
Refactor src/components/Dashboard.tsx. It's 400 lines and does too much. Extract the chart section into a DashboardChart component and the stats section into DashboardStats. Keep all existing functionality and tests passing.
Code Review
Review the staged changes (git diff --cached). Look for: bugs, security issues, performance problems, missing error handling, and deviations from our coding standards. Be specific about line numbers and suggest fixes.
Generate Documentation
Generate JSDoc comments for all exported functions in src/services/. Don't change any logic -- only add documentation. Include parameter descriptions, return types, and a brief example for complex functions.
Git Operations
# Commit with a good message Commit my staged changes with a descriptive message. # Create a PR Create a PR for this branch. Summarize all changes since we branched from main. # Resolve merge conflicts There are merge conflicts after rebasing on main. Resolve them, keeping our branch's logic but accepting main's structural changes.
Project Scaffolding
Create a new API endpoint POST /api/invitations. It should:
- Accept { email, role } in the body
- Validate the email and role (admin, member, viewer)
- Check the user doesn't already exist
- Create an invitation record in the database
- Send an invitation email via the existing email service
- Return 201 with the invitation object
Follow the patterns in src/routes/users.ts.CLAUDE.md Template
Copy this template as a starting point for your project's CLAUDE.md file. Customize it to match your project's conventions.
# Project: [Your Project Name] ## Overview [One-sentence description of what this project does] ## Tech Stack - Language: TypeScript - Framework: Next.js 14 (App Router) - Database: PostgreSQL via Drizzle ORM - Styling: Tailwind CSS - Testing: Vitest + Testing Library - Package Manager: pnpm ## Project Structure - src/app/ → Next.js pages and routes - src/components/ → Reusable React components - src/lib/ → Shared utilities and helpers - src/services/ → Business logic and API clients - src/db/ → Database schema and migrations ## Coding Standards - Use functional components with hooks (no class components) - Prefer named exports over default exports - Use TypeScript strict mode -- no `any` types - Error handling: always use try/catch with typed errors - Imports: use @/ path aliases, group by external/internal ## Testing Requirements - All new functions need unit tests - Test files go next to source: foo.ts → foo.test.ts - Use `describe/it` blocks with clear test names - Mock external services, never hit real APIs in tests - Run: `pnpm test` (unit), `pnpm test:e2e` (integration) ## Common Commands - `pnpm dev` → Start dev server on port 3000 - `pnpm build` → Production build - `pnpm test` → Run unit tests - `pnpm lint` → ESLint + Prettier check - `pnpm db:migrate` → Run pending database migrations - `pnpm db:seed` → Seed database with test data ## Important Notes - Never commit .env files or secrets - The /api/admin/* routes require admin auth middleware - Database migrations must be backward-compatible - Use the logger from src/lib/logger.ts (not console.log)
/memory to edit it quickly from within a Claude session.CLI Flags Reference
Flags you can pass when launching claude from your terminal.
| Flag | Description |
|---|---|
| -p, --print | Non-interactive mode: run a prompt and print the result (no TUI) |
| --model <name> | Choose a specific model (e.g., claude-sonnet-4-20250514) |
| --allowedTools <list> | Restrict which tools Claude can use (comma-separated) |
| --resume <id> | Resume a previous conversation by session ID |
| --continue | Continue the most recent conversation |
| --output-format <fmt> | Set output format: text, json, or stream-json |
| --verbose | Show detailed logging (useful for debugging) |
| --version | Print the installed Claude Code version |
Troubleshooting
Common issues and how to resolve them.
Authentication Errors
Symptom: "Authentication failed" or "Invalid API key" messages.
- Run
/loginto re-authenticate - Check that your API key is still valid in your Anthropic dashboard
- If using an organization key, verify your access has not been revoked
- Run
/doctorto diagnose configuration issues
Context Window Full
Symptom: Claude stops understanding earlier parts of the conversation or gives inconsistent answers.
- Run
/compactto compress the conversation history - Run
/costto check your current token usage - Start a new session with
/clearif the context is too polluted - For large codebases, point Claude to specific files instead of asking it to scan everything
Slow Responses
Symptom: Claude takes a long time to respond or seems to hang.
- Check your internet connection -- Claude Code requires a stable connection
- Large file operations take longer; be patient or scope the request to fewer files
- Press Escape to interrupt and rephrase with a narrower scope
- Run
/statusto check if a background process is still running
Permission Denied Errors
Symptom: Claude cannot read or write files, or tool calls are blocked.
- Run
/permissionsto review your current tool permission rules - Check that Claude Code has access to the project directory (file system permissions)
- If you previously denied a tool, you may need to reset permissions or start a new session
- On macOS, check System Settings > Privacy & Security for terminal access
Wrong Files Edited
Symptom: Claude edited a file you did not intend it to modify.
- Use
git diffto see exactly what changed - Undo with
git checkout -- path/to/filefor specific files - Be more explicit about which files to modify in your next prompt
- Use
--allowedToolsto restrict write access to specific paths
Installation Issues
Symptom: claude command not found or crashes on startup.
- Ensure Node.js 18+ is installed:
node --version - Reinstall:
npm install -g @anthropic-ai/claude-code - Check your PATH includes the npm global bin directory
- On macOS with Homebrew Node: try
npx @anthropic-ai/claude-codeas a quick test - Run
claude /doctorfor a full diagnostic report
/doctor first. It checks your installation, authentication, permissions, and network connectivity. Share the output when asking for help.Further Resources
Deepen your Claude Code knowledge with these resources:
- Official Documentation --
docs.anthropic.com/en/docs/claude-code-- comprehensive reference for all features and APIs - Claude Code GitHub --
github.com/anthropics/claude-code-- source code, issue tracker, and release notes - Anthropic Cookbook --
github.com/anthropics/anthropic-cookbook-- practical examples and integration patterns - Prompt Engineering Guide --
docs.anthropic.com/en/docs/build-with-claude/prompt-engineering-- techniques for writing more effective prompts - Anthropic Discord -- community discussions, tips from other users, and direct support from the team
- Keyset --
keyset.dev-- host, schedule, and add human-in-the-loop routing to your Claude Code agents
npm update -g @anthropic-ai/claude-code to stay on the latest version.