是什么

Claude Code 日常开发的常用工作流和提示词模板,覆盖探索代码库、修复 Bug、重构、测试、PR、文档等典型场景,以及跨会话、并行会话、管道集成等高级用法。

核心机制

探索新代码库:

give me an overview of this codebase
explain the main architecture patterns used here
trace the login process from front-end to database

修复 Bug:

I'm seeing an error when I run npm test
suggest a few ways to fix the @ts-ignore in user.ts
update user.ts to add the null check you suggested

重构代码:

find deprecated API usage in our codebase
refactor utils.js to use ES2024 features while maintaining the same behavior
run tests for the refactored code

创建 PR:

summarize the changes I've made to the authentication module
create a pr
enhance the PR description with more context about the security improvements

引用文件:用 @filename 快速引用文件(@src/utils/auth.js),用 @server:resource 引用 MCP 资源(@github:repos/owner/repo/issues)。

跨会话继续任务:

  • claude --continue:继续当前目录最近的会话
  • claude --resume:从列表选择历史会话
  • /resume:在会话内切换

并行会话(git worktree):

claude --worktree feature-auth   # 在独立 worktree 中启动会话

每个 worktree 是独立的分支检出,多个 Claude 会话可以同时工作不冲突。

管道集成:

git log --oneline -20 | claude -p "summarize these recent commits"
tail -200 app.log | claude -p "Slack me if you see any anomalies"
git diff main --name-only | claude -p "review these changed files for security issues"

定时任务选择:

选项运行位置适用场景
RoutinesAnthropic 云端电脑关机时也要运行的任务
Desktop 定时任务本机需要访问本地文件的任务
/loop当前 CLI 会话会话内快速轮询

关键细节

  • 图片可以拖拽或 Ctrl+V 粘贴到 CLI(不是 Cmd+V)
  • @ 引用文件时会同时加载该文件目录及父目录的 CLAUDE.md
  • 目录引用(@src/components/)显示文件列表,不是文件内容
  • 创建 PR 后会话仍保持活跃,可继续处理 CI 失败或审查意见
  • claude --from-pr <number> 可恢复与特定 PR 关联的会话

关联

实践要点

  • 探索陌生代码库时先问宏观问题,再深入具体组件
  • 修复 Bug 时提供复现命令和错误信息,比描述症状更有效
  • 重构时要求 Claude 先解释现代方式的优势,再执行变更
  • 用 Subagent 隔离大量文件读取:「use a subagent to investigate how our auth system handles token refresh」
  • 定时任务的提示词要明确成功标准,因为任务自主运行无法提问
  • 并行会话适合独立任务(功能开发 + Bug 修复),不适合有依赖关系的任务