Skip to main content

 理解新的代码库

1

导航到项目根目录

cd /path/to/project
2

启动 Coding Agent

claude ## 以 claude 为例
3

请求高级概览

give me an overview of this codebase
3

深入了解特定组件

explain the main architecture patterns used here
what are the key data models?
how is authentication handled?
提示:
  • 从广泛的问题开始,然后缩小到特定领域
  • 询问项目中使用的编码约定和模式
  • 请求项目特定术语的词汇表

 修复 bug

1

与 Coding Agent 分享错误

I'm seeing an error when I run npm test
2

请求修复建议

suggest a few ways to fix the @ts-ignore in user.ts
3

应用修复

update user.ts to add the null check you suggested
提示:
  • 告诉 Claude 重现问题的命令并获取堆栈跟踪
  • 提及重现错误的任何步骤
  • 让 Claude 知道错误是间歇性的还是持续的

 重构代码

1

识别用于重构的遗留代码

find deprecated API usage in our codebase
2

获取重构建议

suggest how to refactor utils.js to use modern JavaScript features
3

安全地应用更改

refactor utils.js to use ES2024 features while maintaining the same behavior
3

验证重构

run tests for the refactored code
提示:
  • 要求 Coding Agent 解释现代方法的优势
  • 请求在需要时保持向后兼容性的更改
  • 以小的、可测试的增量进行重构

 使用专门的 subagents

1

查看可用的 subagents

/agents
这显示所有可用的 subagents 并让您创建新的。
2

自动使用 subagents

Coding Agent 自动将适当的任务委派给专门的 subagents:
review my recent code changes for security issues
run all tests and fix any failures
3

明确请求特定的 subagents

use the code-reviewer subagent to check the auth module
have the debugger subagent investigate why users can't log in
4

为工作流创建自定义 subagents

/agents
然后选择 Create New subagent 并按照提示定义:
  • 描述 subagent 目的的唯一标识符(例如 code-reviewerapi-designer)。
  • Coding Agent 何时应该使用此代理
  • 它可以访问哪些工具
  • 描述代理角色和行为的系统提示
提示:
  • .coding agent/agents/ 中创建项目特定的 subagents 以供团队共享
  • 使用描述性的 description 字段来启用自动委派
  • 限制工具访问权限为每个 subagent 实际需要的内容

 使用 Plan Mode 进行安全的代码分析

Plan Mode 是一种工作模式,它会限制 Coding Agent 只使用 只读操作(read-only tools) 来分析代码库,从而先制定执行计划,而不会直接修改代码。这种模式适用于 探索代码结构、规划复杂修改或进行安全的代码审查 等场景。 Claude Code 为例,在 Plan Mode 下,Claude 会通过 AskUserQuestion 工具主动向用户提问,以进一步澄清需求。在充分理解目标之后,才会生成一份具体的执行计划。

什么时候应该使用 Plan Mode

  • 复杂功能开发:当一个任务涉及多个文件或多步修改时
  • 代码库分析:在动手修改代码之前,希望先系统地理解项目结构
  • 方案讨论:希望先与 Claude 反复确认需求和实现思路,再开始执行

如何使用 Plan Mode —— 以 Claude Code 为例

在当前会话中,可以通过 Shift + Tab 在不同权限模式之间循环切换。如果当前处于 Normal Mode,按一次 Shift + Tab 会切换到 Auto-Accept Mode,终端底部会显示: ⏵⏵ accept edits on再按一次 Shift + Tab,即可进入 Plan Mode,终端会显示: ⏸ plan mode on

示例:规划复杂的重构

claude --permission-mode plan
I need to refactor our authentication system to use OAuth2. Create a detailed migration plan.
Claude Code 将分析当前实现方法并创建全面的计划。通过后续问题进行细化:
What about backward compatibility?
How should we handle database migration?
Ctrl+G 在默认文本编辑器中打开计划,您可以在 Claude 继续之前直接编辑它。

将 Plan Mode 配置为默认值

// .claude/settings.json
{
  "permissions": {
    "defaultMode": "plan"
  }
}

 编写测试用例

1

识别未测试的代码

find functions in NotificationsService.swift that are not covered by tests
2

生成测试框架

add tests for the notification service
3

添加有意义的测试用例

add test cases for edge conditions in the notification service
4

运行并验证测试

run the new tests and fix any failures

 创建拉取请求

可以通过直接要求 Coding Agent 创建拉取请求(“create a pr for my changes”),或逐步指导 Coding Agent:
1

总结更改

summarize the changes I've made to the authentication module
2

生成拉取请求

create a pr
3

审查和细化

enhance the PR description with more context about the security improvements

 处理文档

1

识别未记录的代码

find functions without proper JSDoc comments in the auth module
2

生成文档

add JSDoc comments to the undocumented functions in auth.js
3

审查和增强

improve the generated documentation with more context and examples
4

验证文档

check if the documentation follows our project standards
提示:
  • 指定您想要的文档样式(JSDoc、docstrings 等)
  • 请求文档中的示例
  • 请求公共 API、接口和复杂逻辑的文档

 添加图像

如果你需要在对话中提供图像,并希望 Coding Agent 帮助分析图像内容,可以按照以下步骤操作。
1

将图像添加到对话中

可以使用以下任何方法:
  • 将图像拖放到 Coding Agent 窗口中
  • 复制图像并使用 ctrl+v 将其粘贴到 CLI 中(不要使用 cmd+v)
  • 向 Coding Agent 提供图像路径。例如 Analyze this image: /path/to/your/image.png
2

让 Coding Agent 分析图像

What does this image show?
Describe the UI elements in this screenshot
Are there any problematic elements in this diagram?
3

结合图像描述问题

Here's a screenshot of the error. What's causing it?
This is our current database schema. How should we modify it for the new feature?
4

从视觉内容获取代码建议

Generate CSS to match this design mockup
What HTML structure would recreate this component?

 引用文件和目录

使用 @ 快速包含文件或目录,无需等待 Coding Agent 读取它们。
1

引用单个文件

Explain the logic in @src/utils/auth.js
这在对话中包含文件的完整内容。
2

引用目录

What's the structure of @src/components?
这提供了带有文件信息的目录列表。
3

引用 MCP 资源

Show me the data from @github:repos/owner/repo/issues

 学习资源