Loading lesson…
Loading lesson…
Master these techniques and your Claude Code efficiency can improve by multiple times. They come from real development practice and cover high-frequency scenarios.
This is the most common and important shortcut in Claude Code. During collaboration, you may mistype, give wrong instruction, or dislike an answer. Double-pressing Esc gives you quick "time rewind."
Shortcut details:
Press Esc once -> clear current input (similar to Ctrl+C)
Press Esc twice -> roll back to previous conversation state (undo previous turn)
Press Esc three times -> clear all conversation history (start over)
Use cases:
Important note: double Esc rolls back conversation state, not code changes. If Claude already edited files, those edits are not auto-reverted. You must manually restore via Git.
Recommendation: before potentially large code edits, save current state (git commit or git stash) so recovery is easy.
Although Claude Code can read project files automatically, explicitly referencing files makes intent clearer and avoids wasting tokens on unrelated files.
Basic usage:
Instead of vague:
Explain src/utils.ts
Use explicit reference:
@src/utils.ts Explain this file
Advanced usage:
Compare multiple files:
@src/app.tsx @src/components/Header.tsx What is the relationship between these two files?
Reference directory:
@src/components/ Summarize all components under this directory
Reference specific lines (with editor):
@src/utils.ts:45-60 Explain what this code does
Usage tips:
@ then press Tab, Claude shows file list under current directory and you can choose with arrows@./config.json or @../shared/types.ts@utils can match src/utils.ts or src/utils/index.tsClaude Code has built-in command execution. You can run commands without switching to another terminal.
Basic usage:
!npm test # run tests
!git status # check Git status
!ls -la # list files
Practical scenarios:
Scenario: run tests and analyze failure
!npm test
# after failure
Analyze test failure reasons and fix code
Scenario: inspect Git diff
!git diff
# ask Claude to explain changes
Summarize key changes in this diff
Scenario: build project
!npm run build
# if build fails
Build failed, help me fix it
Safety note:
For sensitive commands (for example rm -rf, sudo), Claude Code asks for confirmation. This is a protection mechanism. Confirm carefully.
For complex tasks, directly coding is often inefficient. /plan enters planning mode: define implementation plan first, then execute step by step.
Usage:
/plan
I want to add user authentication. Please create an implementation plan.
What Claude does:
Sample output:
📋 User Authentication Implementation Plan
Phase 1: Database design
- [ ] Create users table (id, email, password_hash, created_at)
- [ ] Create sessions table (id, user_id, expires_at)
Phase 2: Backend API
- [ ] POST /api/auth/register - register
- [ ] POST /api/auth/login - login
- [ ] POST /api/auth/logout - logout
- [ ] GET /api/auth/me - get current user
Phase 3: Frontend integration
- [ ] Create login page
- [ ] Create register page
- [ ] Add route guards
Phase 4: Testing
- [ ] Write unit tests
- [ ] Write integration tests
Which phase do you want to start with? Or should we adjust the plan?
Best practice:
/plan first/plan to adjust/init is one of Claude Code's most powerful commands. It scans your project automatically, identifies stack and structure, and generates a complete CLAUDE.md.
Usage:
/init
Claude performs:
Generated CLAUDE.md example:
# My Project
## Tech Stack
- Framework: Next.js 14 (App Router)
- Language: TypeScript
- Styling: Tailwind CSS
- State: Zustand
- Database: Prisma + PostgreSQL
## Common Commands
\`\`\`bash
npm run dev # start dev server
npm run build # production build
npm run test # run tests
npx prisma migrate dev # DB migration
\`\`\`
## Code Conventions
- Use function components + Hooks
- File naming: PascalCase (components), camelCase (utility funcs)
- Commit style: Conventional Commits
Why this matters:
CLAUDE.md is Claude Code's "project memory." On every launch, Claude reads this file and understands project background. That means:
Recommendation: after project initialization, run /init immediately, then refine generated config to match reality.
Claude Code context window is limited (often around 200K tokens). Long conversations consume many tokens, increase cost, and may push important early info out of context.
Usage:
/compact
How it works:
/compact analyzes chat history, extracts key information (decisions made, code generated, confirmed requirements), and creates a concise summary. Later dialogue is based on this summary rather than full history.
When to use:
Recommendation:
# compress after long conversation
/compact
# keep working
Now that user module is done, let's build order module.
In Claude Code, recommended commit workflow is: let Claude inspect diff and draft commit message, then you run standard Git commands. This is clear and gives you one more review checkpoint before commit.
Official references:
Recommended workflow:
# 1. Check current changes
/diff
!git status
# 2. Ask Claude to summarize and generate commit message
Based on current git diff, generate a Conventional Commits message,
and explain in Chinese why this category is appropriate.
# 3. After you confirm, run standard Git commit
!git add -A
!git commit -m "feat(docs): update Claude Code workflow guidance"
Benefits of this approach:
If you want "one-command commit" experience:
Claude Code now recommends plugin-based extension. For example, commit-commands provides commands like /commit-commands:commit.
# 1. Add plugin marketplace example
/plugin marketplace add anthropics/claude-code
# 2. Install commit workflow plugin
/plugin install commit-commands@anthropics-claude-code
# 3. Reload plugins
/reload-plugins
# 4. Use plugin command to commit
/commit-commands:commit
Additional notes:
/commit-commands:commit is provided by plugin, not current default built-in command/diff or ask Claude to explain git diff/review has also been marked deprecated; for similar capability, use plugin or natural-language review flowBy default, Claude asks confirmation before editing code. This is useful when learning, but may feel slow later. Shift+Tab enables auto-accept mode for faster iteration.
Usage:
Shift+Tab -> enter auto-accept modeShift+Tab again -> exit auto-accept modeMode comparison:
| Mode | Behavior | Use scenario |
|---|---|---|
| Default mode | Ask confirmation for every edit | Learning stage, important code |
| Auto-accept | Apply edits directly | After familiarization, rapid iteration |
Notes:
When Claude is running a long task, or you realize you gave a wrong instruction, Ctrl+C is the emergency brake.
Usage:
Ctrl+C once -> cancel currently running operationCtrl+C twice -> fully exit Claude CodeUse cases:
Difference from double Esc:
Ctrl+C: stop ongoing operation (running command / generating code)double Esc: roll back conversation state (undo previous turn)/context displays current session context usage, helping you understand token consumption and optimize cost.
Usage:
/context
Sample output:
📊 Context Usage
Token usage: 45,230 / 200,000 (22.6%)
File references: 12 files
Conversation rounds: 8
Top token-consuming files:
1. src/api/users.ts (3,420 tokens)
2. node_modules/@types/react/index.d.ts (2,890 tokens)
3. src/components/Dashboard.tsx (1,560 tokens)
Suggestions:
- Current usage is healthy, no compression needed
- To reduce usage, add node_modules into .claudeignore
How to use this information:
/compactWhen handling multiple tasks, you may run multiple conversation threads. /resume lets you switch back to previous session context in the current chat, without restarting.
Usage:
/resume
How it works:
Claude Code records previous sessions automatically. When you run /resume, it switches to previous session context and keeps all prior discussion content and state.
Use cases:
Case A: parallel multi-tasking
# Task 1: fix bug
claude> Fix login-page validation issue
# ... one conversation ...
# Task 2: add feature (new thread)
claude> Add user registration feature
# ... another conversation ...
# Switch back to task 1
claude> /resume
# Continue previous bug-fix work
Case B: temporary lookup then return
claude> Explain this algorithm
# ... discuss algorithm ...
claude> /resume
# Return to previous coding work
Case C: resume after interruption
claude> Continue previous work
# If you interrupted before, /resume brings you back
Comparison with related commands:
| Command | Function | Scenario |
|---|---|---|
/resume | Switch back to previous session in current chat | Multi-task switching |
claude -c | Continue most recent session | Reconnect after exit |
claude -r | Restore previous session | Recover prior state after exit |
double Esc | Roll back one turn | Undo most recent conversation turn |
Suggestions:
/resume is more efficient than re-explaining context/resume preserves it