主题
常见工作流程
本文档中的每项任务都包含清晰的说明、示例命令和最佳实践,帮助您充分利用 Claude Code。
理解新代码库
快速获取代码库概览
bash
cd /path/to/project
claude
> give me an overview of this codebase
> explain the main architecture patterns used here
> what are the key data models?查找相关代码
> find the files that handle user authentication
> how do these authentication files work together?
> trace the login process from front-end to database高效修复错误
> 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
> suggest how to refactor utils.js to use modern JavaScript features
> refactor utils.js to use ES2024 features while maintaining the same behavior使用专门的子代理
> /agents
> review my recent code changes for security issues
> use the code-reviewer subagent to check the auth module使用计划模式进行安全的代码分析
何时使用计划模式
- 多步实现:当您的功能需要编辑许多文件时
- 代码探索:当您想在更改任何内容之前彻底研究代码库时
- 交互式开发:当您想与 Claude 迭代方向时
如何使用计划模式
bash
# 在计划模式下启动新会话
claude --permission-mode plan
# 或使用 Shift+Tab 在会话期间切换使用测试
> 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创建拉取请求
> summarize the changes I've made to the authentication module
> create a pr
> enhance the PR description with more context about the security improvements处理文档
> find functions without proper JSDoc comments in the auth module
> add JSDoc comments to the undocumented functions in auth.js使用图像
您可以使用以下任何方法将图像添加到对话中:
- 将图像拖放到 Claude Code 窗口中
- 复制图像并使用
Ctrl+V粘贴 - 向 Claude 提供图像路径
> What does this image show?
> Generate CSS to match this design mockup引用文件和目录
使用 @ 快速包含文件或目录:
> Explain the logic in @src/utils/auth.js
> What's the structure of @src/components?使用扩展思考
> I need to implement a new authentication system using OAuth2. Think deeply about the best approach.
> think about potential security vulnerabilities in this approach
> think hard about edge cases we should handle恢复之前的对话
bash
# 继续最近的对话
claude --continue
# 显示对话选择器
claude --resume使用 Git worktrees 运行并行 Claude Code 会话
bash
# 创建新的 worktree
git worktree add ../project-feature-a -b feature-a
# 在每个 worktree 中运行 Claude Code
cd ../project-feature-a
claude将 Claude 用作 unix 风格的实用程序
bash
# 将 Claude 添加到您的验证流程
cat build-error.txt | claude -p 'concisely explain the root cause of this build error' > output.txt
# 控制输出格式
cat code.py | claude -p 'analyze this code for bugs' --output-format json > analysis.json创建自定义斜杠命令
创建项目特定的命令
bash
mkdir -p .claude/commands
echo "Analyze the performance of this code and suggest optimizations:" > .claude/commands/optimize.md使用:> /optimize
使用 $ARGUMENTS 添加命令参数
bash
echo 'Find and fix issue #$ARGUMENTS.' > .claude/commands/fix-issue.md使用:> /fix-issue 123