Skip to content
FunCoding

Search

Search docs, agents, posts, Skills and MCP servers

常见工作流

探索代码库、修 bug、重构、写测试、建 PR 等日常任务的提示词配方,以及恢复会话、并行 worktree、计划模式和管道用法。

本页收集日常开发的短配方。关于提示词和上下文管理的更高层指导,见最佳实践。下面每个配方在 Claude Code 的任何入口都能用,按你的项目调整措辞即可。

提示词配方

理解新的代码库

快速获得概览:刚加入一个新项目,想迅速了解结构。进入项目根目录,运行 claude,然后:

give me an overview of this codebase
explain the main architecture patterns used here
what are the key data models?
how is authentication handled?

提示:先问宽泛的问题,再缩小到具体领域;问问项目用到的编码约定和模式;让它整理一份项目专用术语表。

找到相关代码:

find the files that handle user authentication
how do these authentication files work together?
trace the login process from front-end to database

提示:要具体说明你在找什么,使用项目里的领域语言;为你的语言安装代码智能插件,让 Claude 拥有精确的「跳转到定义」和「查找引用」。

高效修 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

提示:告诉 Claude 复现问题和拿到堆栈的命令;说明复现步骤;告知错误是偶发还是必现。

重构代码

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

提示:让 Claude 解释现代写法的好处;需要时要求保持向后兼容;以小的、可测试的增量做重构。

处理测试

find functions in NotificationsService.swift that are not covered by tests
add tests for the notification service
add test cases for edge conditions in the notification service
run the new tests and fix any failures

Claude 会检查现有测试文件,沿用其中的风格、框架和断言模式。要求测试时说清楚想验证什么行为;想要更全面的覆盖,让它找出你可能漏掉的边界情况(错误条件、边界值、意外输入)。

创建 Pull Request

可以直接说「create a pr for my changes」,或分步引导:

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

之后要找回这个会话,运行 claude --from-pr 1234(换成你的 PR 号),或把 PR 链接粘进 /resume 选择器的搜索框。当 Claude 用 gh pr create 或 glab mr create 创建 PR 时,Claude Code 会把会话和 PR 关联起来。提交前先审阅 Claude 生成的 PR,并让它指出潜在风险。

处理文档

find functions without proper JSDoc comments in the auth module
add JSDoc comments to the undocumented functions in auth.js
improve the generated documentation with more context and examples
check if the documentation follows our project standards

提示:指明想要的文档风格(JSDoc、docstring 等),要求带示例,并优先为公共 API、接口和复杂逻辑写文档。

在笔记和非代码目录里工作

Claude Code 在任何目录里都能用。在笔记库、文档目录或任何 markdown 集合里运行它,可以像处理代码一样搜索、编辑和整理内容。.claude/ 目录和 CLAUDE.md 与其他工具的配置目录并存不冲突;Claude 每次工具调用都重新读取文件,所以能看到你在其他应用里做的修改。

处理图片

向对话里添加图片的方法:拖放到 Claude Code 窗口;复制后在 CLI 里按 Ctrl+V(Windows 和 WSL 用 Alt+V);或给出图片路径。然后可以问:

What does this image show?
Here's a screenshot of the error. What's causing it?
Generate CSS to match this design mockup

提示:文字描述不清楚或太啰嗦时用图片;可以在一次对话里使用多张图片;Claude 引用图片(如 [Image #1])时,按住 Cmd(Mac)或 Ctrl(Windows/Linux)点击可在默认查看器里打开。

引用文件和目录

用 @ 快速包含文件或目录,不用等 Claude 自己去读:

Explain the logic in @src/utils/auth.js
What's the structure of @src/components?
Show me the data from @github:repos/owner/repo/issues

最后一种格式 @server:resource 从已连接的 MCP 服务器获取数据。提示:路径可以是相对或绝对的;输入 @ 会弹出路径建议菜单,按 Enter 或 Tab 接受高亮项;@ 引用文件会把该文件所在目录及上级目录的 CLAUDE.md 带入上下文;引用目录显示的是文件列表而不是内容;一条消息里可以引用多个文件。

按计划定时运行 Claude

按任务运行的位置选方案:

选项运行位置适合
例程(Routines)云端(默认由 Anthropic 托管)电脑关机也要运行的任务;除了定时,还可由 API 调用或 GitHub 事件触发
桌面端定时任务你的机器,通过桌面应用需要直接访问本地文件、工具或未提交改动的任务
GitHub Actions你的 CI 流水线与仓库事件(如 PR 打开)绑定的任务,或应和工作流配置放在一起的 cron
/loop当前 CLI 会话会话开着时的快速轮询

给定时任务写提示词时,要明确说明成功的标准以及结果怎么处理,因为任务自主运行,不能追问澄清。例如:「Review open PRs labeled needs-review, leave inline comments on any issues, and post a summary in the #eng-reviews Slack channel.」

询问 Claude 自己的能力

Claude 内置了对自家文档的访问,可以回答关于自身功能和限制的问题,比如「can Claude Code create pull requests?」「how do I configure Claude Code for Amazon Bedrock?」。想要动手演示,运行 /powerup 获取带动画演示的交互式课程。

恢复之前的对话

claude --continue

恢复当前目录里最近的会话;还没有会话时会打印 No conversation found to continue 并退出。用 claude --resume 从列表里选,或在会话里用 /resume。详见管理会话。

用 worktree 并行运行会话

一个终端里做功能,另一个终端里让 Claude 修 bug,互不冲突。每个 git worktree 是一个独立的、在自己分支上的检出,需要仓库至少有一次提交:

claude --worktree feature-auth

在第二个终端用不同名字运行同样的命令,就启动了一个隔离的并行会话。

先计划再编辑

想在改动落盘前先审阅时,切换到计划模式:Claude 读文件并提出计划,在你批准前不做任何编辑。计划模式开启时状态栏显示 ⏸ plan mode on。

claude --permission-mode plan

也可以在会话中途按 Shift+Tab 直到状态栏显示它。

把调研委托给子智能体

探索大型代码库会让文件读取塞满你的上下文,把探索委托出去,只让结论回来:

use a subagent to investigate how our auth system handles token refresh

子智能体在自己的上下文窗口里读文件,只汇报摘要。详见子智能体。

把 Claude 接进脚本

用于 CI、pre-commit Hook 或批处理的非交互运行,标准输入输出像任何 Unix 工具一样工作:

git log --oneline -20 | claude -p "summarize these recent commits"

输出格式、权限标志和扇出模式见以编程方式运行。