
Hello,朋友们,又见面了。
很多身边的朋友在学Claude code,但是官方文档其实很多人不怎么看。
放在以前,我也不看,谁没事去看英文文档啊~
但是现在,CC的开发辅助能力比较强大,所以我也大概翻了一下,操作了其中的案例,希望对大家有所帮助。
接下来我会带着大家边实操+案例,逐步掌握Claude code的使用流程。
实际上操作Claude code过程中,需要遵循代码开发的流程,有一些提问的技巧。
本部分包括:每个阶段的任务说明、指令示范、最佳实践等。
CC新用户在接触一个新的项目时候,通常都很懵逼。
这玩意一个黑窗口,我咋用???
所以很多朋友就弃用CC了,其实并不难,掌握正确的使用方法即可。
比如,刚刚入职某节的员工,加入一个新项目组,需要快速了解现有代码库时,可以利用 Claude Code 的概览和探索功能。
提示:
cd /path/to/project
claude
这部分主要是了解新的代码库主要是干嘛的,包括核心功能、技术架构、项目结构等。
> give me an overview of this codebase
以GitHub代码库 https://github.com/hanshuaikang/AI-Media2Doc 为例,首先预览整个代码库

如上涉及的特定组件如何深挖?
比如你想快速了解这个项目架构是怎么样的,数据模型是怎么做的,登陆验证是怎么做的,只要涉及整个项目的,都可以提问。
示例提问:
> explain the main architecture patterns used here
> what are the key data models?
> how is authentication handled?
针对我们选择的GitHub项目,进行深入了解特定组件,可以这样问:音视频转文档的这部分功能设计是怎么样的?


接手一个新项目过程中,其中一个模块我不太懂,于是就需要定位与特定功能或功能相关的代码。
提示:
> find the files that handle user authentication
前面已经介绍了,音视频转文档分为三层,前端、音视频处理、后端服务,小白都可以看懂。

接下来我想找到处理ASR服务和LLM文档生成的文件

> how do these authentication files work together?




> trace the login process from front-end to database




新手在run项目的时候,往往会遇到各种error,要么是环境问题,要么是网络bug等等,如果遇到了错误消息,就需要找到并修复其源头。
放在以前,还得打开浏览器,搜CSDN和各种帖子去看怎么解决,运气好能一下子找到,运气不好就难说。
现在其实就能用CC直接帮你解决错误问题。
提示:
> 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
一些传统的国企央企,会用旧的Java框架以及老掉牙的版本,迭代更新是大问题,并且还不能完全更新,更新旧代码过程中,使用现代模式和实践往往会遇到很多问题。
现在倒是可以使用CC解决这类问题,有一些技巧:
> 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
测试这块,严格来说是测试工程师干的话,但是目前大环境下,实习生都得干,毕竟你不干有的是人干。
如果用CC的话,参考:
> 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
在与CC交互过程中,可能会引用相关文档,或者为项目添加或更新文档,
不同于cursor,在cursor里面还有快捷指令提供选择,很方便就能在整个项目里面搜索到文件。
这里的CC使用技巧值得一看:
> 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
其实很多任务单靠一个agent解决不了实际大的问题。
所以cc里面支持了subagent,就是你可以拉起一个AI开发团队,里面成员的功能职责全是有你来定,然后你的领导给你来了任务,交给他,不同AI员工进行响应,直接互相协同,这样你摸鱼的时间更长了,效率提高,年终奖更多了。
如果想使用专门的 AI 子agent来更有效地处理特定任务。
参考如下使用方法:
> /agents
这显示所有可用的子代理并让您创建新的子代理。 2. 自动使用子代理 Claude Code 将自动将适当的任务委托给专门的子代理:
> review my recent code changes for security issues
> run all tests and fix any failures
> use the code-reviewer subagent to check the auth module
> have the debugger subagent investigate why users can't log in
> /agents
然后选择”Create New subagent”并按照提示定义:
什么是拉取请求?
其实是代码测试&合并方面的知识,就是你以及修改了代码的部分,需要将其合并到项目组的分支里面(一般大厂里面会有git的不同链路,比如dev、test这种)
可以参考如下的使用方法。
> summarize the changes I've made to the authentication module
> create a pr
> enhance the PR description with more context about the security improvements
> add information about how these changes were tested
这里需要注意的是,Claude code原生是Claude系列模型,原本是多模态的,如果使用kimi-k2或者GLM-4.5等其他夺舍版,处理图像功能不可用。
如果需要在代码库中处理图像,并希望 Claude 帮助分析图像内容,可以使用这个方法。
使用技巧:
> What does this image show?
> Describe the UI elements in this screenshot
> This is our current database schema. How should we modify it for the new feature?
> Generate CSS to match this design mockup
> What HTML structure would recreate this component?
这里提一下cursor的引用文件和目录功能,

在CC里面,可以使用 @ 快速唤起文件或目录,不需要等待 Claude 读取它们。
使用必须要注意:
> 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
这使用格式 @server:resource 从连接的 MCP 服务器获取数据。 实例:
Explain the logic in @xxx

What's the structure of @xxx

一般简单的问题CC可以轻松解决,遇到复杂的问题,也不能怪CC不够智能,还是需要一定的方法,这种处理复杂的架构决策、具有挑战性的错误或需要深度推理的多步骤实现规划。
扩展思考对复杂任务最有价值,例如:
提示思考的方式会导致不同深度的思考:
> I need to implement a new authentication system using OAuth2 for our API. Think deeply about the best approach for implementing this in our codebase.
Claude 将从代码库收集相关信息并使用扩展思考,这将在界面中可见。
> think about potential security vulnerabilities in this approach
> think harder about edge cases we should handle
最常见的情况是,昨天晚上你刚用完Claude code,第二天需要重新启动,怎么找回之前的聊天记录???
Claude Code 就提供两个恢复之前对话的选项:
提示:
--continue 快速访问最近的对话# 继续最近的对话
claude --continue
# 使用特定提示继续最近的对话
claude --continue --print "Show me our progress"
# 在非交互模式下继续最近的对话
claude --continue --print "Run the tests again"
--resume# 显示对话选择器
claude --resume
这显示一个交互式对话选择器,显示:对话开始时间、初始提示或对话摘要、消息计数。使用箭头键导航并按 Enter 选择对话。
工作原理:
如果用户需要同时处理多个任务,并在 Claude Code 实例之间完全隔离代码,互补产生交集,这部分值得一看。
Git worktrees 允许将同一存储库的多个分支检出到单独的目录中。每个 worktree 都有自己的工作目录和隔离的文件,同时共享相同的 Git 历史。
# 使用新分支创建新的 worktree
git worktree add ../project-feature-a -b feature-a
# 或使用现有分支创建 worktree
git worktree add ../project-bugfix bugfix-123
这创建一个新目录,其中包含您存储库的单独工作副本。
# 导航到您的 worktree
cd ../project-feature-a
# 在这个隔离环境中运行 Claude Code
claude
cd ../project-bugfixclaude
# 列出所有
worktreesgit worktree list
# 完成后删除
worktreegit worktree remove ../project-feature-a
这部分其实是最终代码提交过程时候,需要进行代码审查,防止出现注入等漏洞,就可以将 Claude Code 用作 linter 或代码审查器。
你可以这样使用:
将 Claude 添加到构建脚本:
// package.json
{
...
"scripts": {
...
"lint:claude": "claude -p 'you are a linter. please look at the changes vs. main and report any issues related to typos. report the filename and line number on one line, and a description of the issue on the second line. do not return any other text.'"
}
}
程序员可以很方便的将CC与终端命令进行结合,比如用户可以将数据管道输入 Claude,并以结构化格式获取数据。
你可以这样使用:
通过 Claude 管道数据:
cat build-error.txt | claude -p 'concisely explain the root cause of this build error' > output.txt
如果像让Claude 的输出采用特定格式,特别是在将 Claude Code 集成到脚本或其他工具中时。
参考如下使用方法:
--output-format text--output-format json--output-format stream-jsoncat data.txt | claude -p 'summarize this data' --output-format text > summary.txt
只输出 Claude 的纯文本响应(默认行为)。
cat code.py | claude -p 'analyze this code for bugs' --output-format json > analysis.json
这输出一个包含元数据(包括成本和持续时间)的消息 JSON 数组。
cat log.txt | claude -p 'parse this log file for errors' --output-format stream-json
这在 Claude 处理请求时实时输出一系列 JSON 对象。每个消息都是有效的 JSON 对象,但如果连接,整个输出不是有效的 JSON。
Claude Code 对于高级用户来说,支持自定义斜杠命令,可以创建这些命令来快速执行特定提示或任务。
假设你想为项目创建可重用的斜杠命令,所有团队成员都可以使用。
参考使用方法:
mkdir -p .claude/commands
echo "Analyze the performance of this code and suggest three specific optimizations:" > .claude/commands/optimize.md
> /optimize
假设你想创建可以接受用户额外输入的灵活斜杠命令。
提示:
echo "Find and fix issue #$ARGUMENTS. Follow these steps: 1.Understand the issue described in the ticket 2. Locate the relevant code inour codebase 3. Implement a solution that addresses the root cause 4. Addappropriate tests 5. Prepare a concise PR description" >.claude/commands/fix-issue.md
> /fix-issue 123
这将在提示中将 $ARGUMENTS 替换为”123”。
高级用户可以创建在所有项目中都有效的个人斜杠命令,你可以自定义,把经常使用的命令放到一起。
使用技巧:
mkdir -p ~/.claude/commands
echo "Review this code for security vulnerabilities, focusing on:" >~/.claude/commands/security-review.md
> /security-review
Claude 里面内置了CC使用文档,可以回答关于其自身功能和限制的问题。
但是在使用过程中需要注意:
> how do I use MCP with Claude Code?
> how do I configure Claude Code for Amazon Bedrock?
> what are the limitations of Claude Code?
有一些基础的代码能力,对CC上手还是比较轻松一点的。
但是到了高级阶段,做各种大型项目,还是程序员的天下,高级程序员还没有到被淘汰的阶段,只能说,越老越吃香(35岁之前).
国内的模型能力还是得能力,啥时候能都支持多模态啊。