Claude Code
1. 安装claude code
npm install -g @anthropic-ai/claude-code
环境变量方式启动或直接修改~/.claude/settings.json文件
export ANTHROPIC_BASE_URL=https://ark.cn-beijing.volces.com/api/compatible
export ANTHROPIC_AUTH_TOKEN=<ARK-API-KEY>
export ANTHROPIC_MODEL=doubao-seed-code-preview-latest
使用claude code
# 将claude code路由至其他大模型提供商
npm install -g @musistudio/claude-code-router
<span class="tag">#安装阿里云百炼的config</span>
npm install -g @dashscope-js/claude-code-config
# power shell开启执行命令权限
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
# 配置ali key
ccr-dashscope
# 启动,启动命令执行的路径要和vscode准备打开的项目路径一致
ccr code
在vscode中安装claude code插件,然后在claude code命令行界面使用/idea即可连接到vscode。claude code就可以和vscode进行交付,感知你在vscode中选中的代码、文件,claude code的修改也会在vscode中以diff形式呈现。
2. 常用命令
| 命令 | 功能 | 示例 |
|---|---|---|
claude |
启动交互模式 | claude |
claude "task" |
运行一次性任务 | claude "fix the build error" |
claude -p "query" |
运行一次性查询,然后退出 | claude -p "explain this function" |
claude -c |
继续最近的对话 | claude -c |
claude -r |
恢复之前的对话 | claude -r |
claude commit |
创建 Git 提交 | claude commit |
/clear |
清除对话历史 | > /clear |
/help |
显示可用命令 | > /help |
exit 或 Ctrl+C |
退出 Claude Code | > exit |
/export |
把当次对话复制到剪贴板,便于归档或交叉验证(例如贴给 GPT 审核推理链)。 |
3. 使用技巧
/init claude code会分析当前文件夹,把它学到的关于项目的知识记录在根目录下CLAUDE.md里。当然,我们也可以手动修改这个文件,把我们认为的一些重要信息(提示、约束等)放到里面。
/commpact 压缩
/clear 清楚会话记录,开启一个新工程的应该使用
think < think hard < think harder < ultrathink
思考等级逐级递增,ultrathink可以用来思考一些比较难的问题
!可以临时执行命令行,并将执行结果作为后续上下文
输入#号进入记忆模式,
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
# Add to memory. Try "Always use descriptive variable names"
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
# to memorize
可以选择存放位置
- 用户级别:所有项目都会生效
- 项目
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
# 所有代码都需要经过严格测试
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Select memory file to edit: │
│ │
│ ❯ 1. User memory Saved in ~/.claude/CLAUDE.md │
│ 2. Project memory Saved in ./CLAUDE.md │
│ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
/permissions 添加工具或者命令,允许自动执行
claude --dangerously-skip-permissions 赋予claude code最高权限,可以自动执行任何命令
[hooks(https://code.claude.com/docs/en/hooks-guide)
subagent可以让claude在后台开启多个子任务,并行执行。/agents
4. claudia
可视化界面
5. mcp安装
本地安装claude mcp add [alias] -- npx @upstash/context7-mcp
remote httpclaude mcp add --transport http
sse transportclaude mcp add --transport sse
# 卸载
claude mcp remove context7
项目级别,仅在当前项目下生效claude mcp add context7 -- npx @upstash/context7-mcp
用户级别的,所有项目生效claude mcp add context7 --scope user -- npx @upstash/context7-mcp
使用/mcp命令可以进行mcp管理
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Manage MCP servers │
│ │
│ ❯ 1. context7 ✔ connected · Enter to view details │
│ │
│ MCP Config locations (by scope): │
│ • User config (available in all your projects): │
│ • C:\Users\jstxz\.claude.json │
│ • Project config (shared via .mcp.json): │
│ • D:\workspace\proj\blog\.mcp.json (file does not exist) │
│ • Local config (private to you in this project): │
│ • C:\Users\jstxz\.claude.json [project: D:\workspace\proj\blog] │
│ │
│ Tip: Use /mcp enable or /mcp disable to quickly toggle all servers │
│ │
│ For help configuring MCP servers, see: https://code.claude.com/docs/en/mcp │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
使用示例
> java中如何创建虚拟线程 使用context7
● 我将帮您了解如何在Java中创建虚拟线程。首先,让我使用Context7来获取相关的文档信息。
● context7 - resolve-library-id (MCP)(libraryName: "Java virtual threads")
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Tool use
context7 - resolve-library-id(libraryName: "Java virtual threads") (MCP)
Resolves a package/product name to a Context7-compatible library ID and returns a list of matching libraries.
You MUST call this function before 'get-library-docs' to obtain a valid Context7-compatible library ID UNLESS the
user explicitly provides a library ID in the format '/org/project' or '/org/project/version' in their query.
Selection Process:
1. Analyze the query to understand what library/package the user is looking for
2. Return the most relevant match based on:
- Name similarity to the query (exact matches prioritized)
- Description relevance to the query's intent
- Documentation coverage (prioritize libraries with higher Code Snippet counts)
- Source reputation (consider libraries with High or Medium reputation more authoritative)
- Benchmark Score: Quality indicator (100 is the highest score)
Response Format:
- Return the selected library ID in a clearly marked section
- Provide a brief explanation for why this library was chosen
- If multiple good matches exist, acknowledge this but proceed with the most relevant one
- If no good matches exist, clearly state this and suggest query refinements
For ambiguous queries, request clarification before proceeding with a best-guess match.
Do you want to proceed?
❯ 1. Yes
2. Yes, and don't ask again for context7 - resolve-library-id commands in D:\workspace\proj\blog
3. No, and tell Claude what to do differently (esc)
6. claude code状态
- deliberating: 深思熟虑;仔细考虑;商议;审议
- effecting: 生效
- puzzling: 令人费解
- concating: 连接
- elucidating: 阐明
- churning: 搅拌
- crafting: 手工制作
- Reticulating: 网状
- scheming