常见场景速查
2026/6/27大约 3 分钟
常见场景速查
Step-by-step 配方,对应官方 Common workflows。可按项目改写措辞。
新功能开发
1. /plan 描述功能:意图、约束、涉及模块、验收标准
2. 审查 plan;不满意则继续讨论或让 Claude 写入 docs/plans/xxx.md
3. 批准后选:Auto 执行 / acceptEdits 逐步确认 / 清除 plan context 省 token
4. 实施完成后:/simplify 或 code-reviewer subagent
5. 跑测试 → create a prclaude --model opusplan --permission-mode plan --name "feat-xxx"Bug 修复
快速:
claude "Safari 登录按钮无响应。错误:[粘贴]。复现:..."深度:
1. 给出复现命令 + 完整 stack trace
2. Claude 假设 → 加日志/断点 → 验证根因
3. 修复 + 回归测试
/debug # 启用调试日志辅助诊断技巧:第一条消息包含如何复现和期望行为。
Code Review
review 当前分支相对 main 的所有改动,按 Critical / Warning / Suggestion 分级Use the code-reviewer subagent on git diff HEAD~1- PR 链式:
gh pr create后会话可--from-pr <n>恢复 - CI:GitHub Actions / GitLab CI 集成(第 11、24 章)
大型重构 / 迁移
/batch(需 git):
/batch migrate src/ from JavaScript to TypeScript
/batch replace class components with functional components in packages/ui/多 worktree:
# T1: 总 Plan
claude -w migration-plan --permission-mode plan
# T2–T5: 按模块并行(Plan 批准后)
claude -w mod-api
claude -w mod-ui避免两会话改同一目录。
代码库探索
总览:
give me an overview of this codebase
explain the main architecture patterns
what are the key data models?定位代码:
find files that handle JWT refresh
trace login from frontend to database省 context:
use a subagent to investigate how caching works in src/cache/LSP 插件:安装语言 code intelligence 插件后 Claude 可 go-to-definition / find-references。
@ 引用文件与目录
Explain @src/utils/auth.js
What's in @packages/core/?
Compare @src/old.ts and @src/new.ts- @ 单文件 = 全文进 context;@ 目录 = 列表非内容
- 会加载该路径相关的 CLAUDE.md / rules
- MCP:
@github:repos/owner/repo/issues
文档
add JSDoc to undocumented exports in @src/api/
write README setup steps from @package.json scripts
find functions without docstrings in auth module图像
| 方式 | 说明 |
|---|---|
| 拖拽 / Ctrl+V(非 Cmd+V) | 粘贴到 CLI |
| 路径 | Analyze /path/to/screenshot.png |
| 用途 | UI 复刻、错误截图、架构图、mockup → CSS |
笔记 / 非代码目录
Claude Code 可在 Obsidian vault、docs 文件夹运行——.claude/ 与现有工具配置并存;每次 Read 读最新磁盘内容。
定时 / 自动化
| 方式 | 运行位置 | 计算机关机 |
|---|---|---|
Routines /schedule | Anthropic 云端 | 可继续 |
| Desktop 定时 | 本机 | 需开机 |
/loop 5m ... | 当前 CLI 会话 | 停止 |
| GitHub Actions | CI | 按 cron |
Routines prompt 要写清成功标准与输出动作( autonomous 无法追问)。
示例 Routines prompt:
Review open PRs labeled
needs-review, comment inline, post summary to #eng-reviews.
会话恢复
claude --continue # 本目录最近会话
claude --resume # 交互选择
claude --resume auth-refactor
claude --from-pr 42
/rewind # /clear 之前恢复对话(v2.1.186+ 区域)管道与 CI
git log --oneline -20 | claude -p "summarize themes"
git diff main --name-only | claude -p "security review" --output-format json
tail -500 app.log | claude -p "alert on ERROR patterns"问 Claude 自身能力
can Claude Code create pull requests?
what skills are available?
how does auto mode work on Bedrock?Claude 内置文档索引;也可 /powerup 交互教程。
场景 → 命令对照
| 场景 | 首选 |
|---|---|
| 先审再改 | --permission-mode plan |
| 少确认长任务 | auto(Team/Enterprise/API) |
| 并行功能 | claude -w feat-a × N |
| 大迁移 | /batch |
| 调研 | Explore / Plan subagent |
| 旁路不问 | /btw |
| 后台长跑 | /background 或 claude --bg |
| 云端定时 | /schedule |