Skip to content
看累了听个音乐吧

7.4 Issue 驱动开发

7.4 Issue 驱动开发

@claude 就是你的触发器

安装好之后,在任何 Issue 或 PR 评论里 @claude,Claude Code 就会被激活,读取上下文,然后干活。

不需要记命令,不需要特殊语法,就是正常说话然后 @claude


场景一:从 Issue 直接生成功能 PR

你在 Issue 里描述了一个功能需求:

Issue #47:添加用户头像上传功能

用户应该可以在个人设置页面上传头像。支持 JPG/PNG,最大 5MB,自动压缩到 200×200px 存储。

在 Issue 评论里:

@claude implement this feature based on the issue description.
follow the existing patterns in src/features/profile/
and make sure to add tests.

Claude Code 会:

  1. 读取 Issue 的完整描述
  2. 浏览 src/features/profile/ 了解现有代码结构
  3. 实现功能(上传逻辑、压缩、存储)
  4. 写测试
  5. 创建一个 PR,描述里会说明实现了什么

你去 review 那个 PR,而不是自己从零写代码。


场景二:在 PR 里要求修改

PR 里有个 reviewer 留了评论,但他今天不在线了,你不想等:

@claude the reviewer mentioned we should use a service layer here
instead of putting the business logic directly in the controller.
please refactor accordingly.

Claude Code 会读取这条评论和整个 PR 的上下文,做出对应的修改,push 到同一个分支。


场景三:修复 bug

有个 Issue 报告了一个 bug,附上了复现步骤:

Issue #89:用户在 Safari 上无法完成支付

在 Safari 15+ 上点击支付按钮后页面卡住,控制台报 Cannot read properties of undefined (reading 'stripe')。Chrome 正常。

@claude investigate and fix the Safari payment bug described in this issue.
reproduce the issue in code, fix it, and add a test to prevent regression.

写好 Issue 描述的技巧

Claude Code 的实现质量很大程度上取决于 Issue 描述的质量。你的 Issue 越清晰,它做出来的东西越符合预期。

一个好 Issue 通常包含:

markdown
## 背景
[这个功能/bug 的背景,为什么需要它]

## 需求描述
[具体要实现什么,越详细越好]

## 验收标准
- [ ] 用户可以上传 JPG/PNG 格式的头像
- [ ] 文件大小超过 5MB 时显示友好的错误提示
- [ ] 上传后自动压缩到 200×200px
- [ ] 原图不保存,只保存压缩后的版本

## 技术约束
- 使用现有的 S3 工具类 `src/utils/storage.ts`
- 文件命名规则:`avatars/{userId}/{timestamp}.jpg`
- 不要引入新的图像处理库,使用 sharp(已安装)

## 不需要做的
- 不需要支持 GIF 动图
- 不需要头像裁剪功能(v2 再做)

有了清晰的验收标准,Claude Code 知道"什么算完成";有了技术约束,它不会引入你不想要的依赖;有了"不需要做的",它不会画蛇添足。


审查 AI 生成的 PR

AI 生成的 PR 和普通 PR 一样,需要认真 review。以下是特别要注意的地方:

边界条件和错误处理

@claude review the PR you just created.
specifically check: what happens if the uploaded file is corrupted?
what if S3 is temporarily unavailable? are these cases handled?

和现有代码的一致性

@claude compare your implementation style with the existing code
in src/features/. does it follow the same patterns?
list any inconsistencies.

测试是否真正有效

@claude for the tests you wrote, run them against a version
of the code where you intentionally break the file size validation.
do the tests catch it?

一个反直觉的提醒

Claude Code 在 GitHub Actions 里能力很强,但它不了解你的产品愿景和业务背景

它能把验收标准里写的功能实现出来,但决定"这个功能该不该做"、"这个设计对不对"——这些判断还是需要人来做。

把 AI 当成一个执行力很强但需要方向指引的工程师来用,而不是一个能自主做决策的产品经理。


下一节,一些高级的 Workflow 配置技巧。

基于 CC BY-NC-SA 4.0 协议发布