feat: add claude #1008

This commit is contained in:
小弟调调
2025-09-09 13:53:52 +08:00
parent ea84393d77
commit f39f922578
5 changed files with 657 additions and 179 deletions

View File

@@ -118,7 +118,7 @@ Quick Reference
[R 语言](./docs/r.md)<!--rehype:style=background:rgb(39 108 192);&class=contributing-->
[Elixir](./docs/elixir.md)<!--rehype:style=background:rgb(124 26 156);&class=contributing tag&data-lang=Elixir-->
[Tauri](./docs/tauri.md)<!--rehype:style=background:rgb(103 214 237);&class=contributing-->
[Docker Compose](./docs/docker-compose.md)<!--rehype:style=background: rgb(72 143 223);&class=contributing tag&data-lang=Docker-->
[Claude Code](./docs/claude.md)<!--rehype:style=background:rgb(217 119 87);&class=contributing tag&data-lang=AI-->
<!--rehype:class=home-card-->
## 编程
@@ -283,7 +283,8 @@ Quick Reference
## 工具
[ChatGPT](./docs/chatgpt.md)<!--rehype:style=background: rgb(74, 161, 129);&class=tag&data-lang=AI-->
[ChatGPT](./docs/chatgpt.md)<!--rehype:style=background:rgb(74 161 129);&class=tag&data-lang=AI-->
[Claude Code](./docs/claude.md)<!--rehype:style=background:rgb(217 119 87);&class=tag&data-lang=AI-->
[Emacs](./docs/emacs.md)<!--rehype:style=background:rgb(98 36 134);-->
[Linux Command](./docs/linux-command.md)<!--rehype:style=background:rgb(215 89 62);&class=tag&data-lang=命令速查-->
[Mitmproxy](./docs/mitmproxy.md)<!--rehype:style=background:rgb(4 92 135);-->

1
assets/claude.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 40 40"><path fill="currentColor" d="M7.75,26.28 L15.52,21.92 L15.65,21.54 L15.52,21.33 L15.14,21.33 L13.84,21.25 L9.4,21.13 L5.55,20.97 L1.82,20.77 L0.88,20.57 L0,19.41 L0.09,18.83 L0.88,18.3 L2.01,18.4 L4.51,18.57 L8.26,18.83 L10.98,18.99 L15.01,19.41 L15.65,19.41 L15.74,19.15 L15.52,18.99 L15.35,18.83 L11.47,16.2 L7.27,13.42 L5.07,11.82 L3.88,11.01 L3.28,10.25 L3.02,8.59 L4.1,7.4 L5.55,7.5 L5.92,7.6 L7.39,8.73 L10.53,11.16 L14.63,14.18 L15.23,14.68 L15.47,14.51 L15.5,14.39 L15.23,13.94 L13,9.91 L10.62,5.81 L9.56,4.11 L9.28,3.09 C9.18,2.67 9.11,2.32 9.11,1.89 L10.34,0.22 L11.02,0 L12.66,0.22 L13.35,0.82 L14.37,3.15 L16.02,6.82 L18.58,11.81 L19.33,13.29 L19.73,14.66 L19.88,15.08 L20.14,15.08 L20.14,14.84 L20.35,12.03 L20.74,8.58 L21.12,4.14 L21.25,2.89 L21.87,1.39 L23.1,0.58 L24.06,1.04 L24.85,2.17 L24.74,2.9 L24.27,5.95 L23.35,10.73 L22.75,13.93 L23.1,13.93 L23.5,13.53 L25.12,11.38 L27.84,7.98 L29.04,6.63 L30.44,5.14 L31.34,4.43 L33.04,4.43 L34.29,6.29 L33.73,8.21 L31.98,10.43 L30.53,12.31 L28.45,15.11 L27.15,17.35 L27.27,17.53 L27.58,17.5 L32.28,16.5 L34.82,16.04 L37.85,15.52 L39.22,16.16 L39.37,16.81 L38.83,18.14 L35.59,18.94 L31.79,19.7 L26.13,21.04 L26.06,21.09 L26.14,21.19 L28.69,21.43 L29.78,21.49 L32.45,21.49 L37.42,21.86 L38.72,22.72 L39.5,23.77 L39.37,24.57 L37.37,25.59 L34.67,24.95 L28.37,23.45 L26.21,22.91 L25.91,22.91 L25.91,23.09 L27.71,24.85 L31.01,27.83 L35.14,31.67 L35.35,32.62 L34.82,33.37 L34.26,33.29 L30.63,30.56 L29.23,29.33 L26.06,26.66 L25.85,26.66 L25.85,26.94 L26.58,28.01 L30.44,33.81 L30.64,35.59 L30.36,36.17 L29.36,36.52 L28.26,36.32 L26,33.15 L23.67,29.58 L21.79,26.38 L21.56,26.51 L20.45,38.46 L19.93,39.07 L18.73,39.53 L17.73,38.77 L17.2,37.54 L17.73,35.11 L18.37,31.94 L18.89,29.42 L19.36,26.29 L19.64,25.25 L19.62,25.18 L19.39,25.21 L17.03,28.45 L13.44,33.3 L10.6,36.34 L9.92,36.61 L8.74,36 L8.85,34.91 L9.51,33.94 L13.44,28.94 L15.81,25.84 L17.34,24.05 L17.33,23.79 L17.24,23.79 L6.8,30.57 L4.94,30.81 L4.14,30.06 L4.24,28.83 L4.62,28.43 L7.76,26.27 L7.75,26.28 Z"/></svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

432
docs/claude.md Normal file
View File

@@ -0,0 +1,432 @@
ClaudeCode 备忘清单
===
ClaudeCode 命令行开发工具快速参考备忘单。
CLI 参考
---
### 命令行
<!--rehype:wrap-class=col-span-2-->
| 命令 | 描述 | 示例 |
| --- | --- | --- |
| `claude` | 启动交互式 REPL | `claude` |
| `claude "query"` | 使用初始提示启动 REPL | `claude "explain this project"` |
| `claude -p "query"` | 通过 SDK 查询,然后退出 | `claude -p "explain this function"` |
| `cat file \| claude -p "query"` | 处理管道内容 | `cat logs.txt \| claude -p "explain"` |
| `claude -c` | 继续最近的对话 | `claude -c` |
| `claude -c -p "query"` | 通过 SDK 继续 | `claude -c -p "Check for type errors"` |
| `claude -r "<session-id>" "query"` | 通过 ID 恢复会话 | `claude -r "abc123" "Finish this PR"` |
| `claude update` | 更新到最新版本 | `claude update` |
| `claude mcp` | 配置模型上下文协议 (MCP) 服务器 | 请参阅 [Claude Code MCP 文档](https://docs.anthropic.com/zh-CN/docs/claude-code/mcp)。 |
<!--rehype:className=left-align-->
### CLI 标志
<!--rehype:wrap-class=row-span-2-->
使用这些命令行标志自定义 Claude Code 的行为:
| 标志 | 描述 | 示例 |
| --- | --- | --- |
| `--add-dir` | 添加额外的工作目录供 Claude 访问(验证每个路径是否作为目录存在) | `claude --add-dir ../apps ../lib` |
| `--allowedTools` | 除了 [settings.json 文件](https://docs.anthropic.com/zh-CN/docs/claude-code/settings) 之外,应该在不提示用户许可的情况下允许的工具列表 | `"Bash(git log:*)" "Bash(git diff:*)" "Read"` |
| `--disallowedTools` | 除了 [settings.json 文件](https://docs.anthropic.com/zh-CN/docs/claude-code/settings) 之外,应该在不提示用户许可的情况下禁止的工具列表 | `"Bash(git log:*)" "Bash(git diff:*)" "Edit"` |
| `--print`, `-p` | 打印响应而不使用交互模式(有关编程使用详细信息,请参阅 [SDK 文档](https://docs.anthropic.com/zh-CN/docs/claude-code/sdk) | `claude -p "query"` |
| `--append-system-prompt` | 附加到系统提示(仅与 `--print` 一起使用) | `claude --append-system-prompt "Custom instruction"` |
| `--output-format` | 为打印模式指定输出格式(选项:`text``json``stream-json` | `claude -p "query" --output-format json` |
| `--input-format` | 为打印模式指定输入格式(选项:`text``stream-json` | `claude -p --output-format json --input-format stream-json` |
| `--verbose` | 启用详细日志记录,显示完整的轮次输出(在打印和交互模式中都有助于调试) | `claude --verbose` |
| `--max-turns` | 在非交互模式下限制代理轮次数量 | `claude -p --max-turns 3 "query"` |
| `--model` | 使用最新模型的别名(`sonnet``opus`)或模型的全名为当前会话设置模型 | `claude --model claude-sonnet-4-20250514` |
| `--permission-mode` | 在指定的[权限模式](iam#permission-modes)下开始 | `claude --permission-mode plan` |
| `--permission-prompt-tool` | 指定一个 MCP 工具来处理非交互模式下的权限提示 | `claude -p --permission-prompt-tool mcp_auth_tool "query"` |
| `--resume` | 通过 ID 恢复特定会话,或在交互模式下选择 | `claude --resume abc123 "query"` |
| `--continue` | 在当前目录中加载最近的对话 | `claude --continue` |
| `--dangerously-skip-permissions` | 跳过权限提示(谨慎使用) | `claude --dangerously-skip-permissions` |
<!--rehype:className=style-list-arrow squarefill-->
### 内置斜杠命令
<!--rehype:wrap-class=col-span-2-->
| 命令 | 用途 |
| --- | --- |
| `/add-dir` | 添加额外的工作目录 |
| `/agents` | 管理用于专门任务的自定义AI子代理 |
| `/bug` | 报告错误将对话发送给Anthropic |
| `/clear` | 清除对话历史 |
| `/compact [instructions]` | 压缩对话,可选择性地提供重点指令 |
| `/config` | 查看/修改配置 |
| `/cost` | 显示令牌使用统计(请参阅[成本跟踪指南](https://docs.anthropic.com/zh-CN/docs/claude-code/costs#using-the-cost-command)了解订阅特定详情) |
| `/doctor` | 检查您的Claude Code安装的健康状况 |
| `/help` | 获取使用帮助 |
| `/init` | 使用CLAUDE.md指南初始化项目 |
| `/login` | 切换Anthropic账户 |
| `/logout` | 从您的Anthropic账户登出 |
| `/mcp` | 管理MCP服务器连接和OAuth身份验证 |
| `/memory` | 编辑CLAUDE.md内存文件 |
| `/model` | 选择或更改AI模型 |
| `/permissions` | 查看或更新[权限](https://docs.anthropic.com/zh-CN/docs/claude-code/iam#configuring-permissions) |
| `/pr_comments` | 查看拉取请求评论 |
| `/review` | 请求代码审查 |
| `/status` | 查看账户和系统状态 |
| `/terminal-setup` | 安装Shift+Enter键绑定用于换行仅限iTerm2和VSCode |
| `/vim` | 进入vim模式以在插入和命令模式之间切换 |
<!--rehype:className=left-align-->
键盘快捷键
---
### 通用控制
| 快捷键 | 描述 | 上下文 |
| --- | --- | --- |
| `Ctrl+C` | 取消当前输入或生成 | 标准中断 |
| `Ctrl+D` | 退出 Claude Code 会话 | EOF 信号 |
| `Ctrl+L` | 清除终端屏幕 | 保留对话历史 |
| `上/下箭头` | 导航命令历史 | 回调之前的输入 |
| `Esc` + `Esc` | 编辑上一条消息 | 双击 Esc 键修改 |
| `Shift+Tab` | 切换权限模式 | 在自动接受模式、计划模式和正常模式之间切换 |
<!--rehype:className=left-align shortcuts-->
### 多行输入
| 方法 | 快捷键 | 上下文 |
| --- | --- | --- |
| 快速转义 | `\` + `Enter` | 在所有终端中有效 |
| macOS 默认 | `Option+Enter` | macOS 上的默认设置 |
| 终端设置 | `Shift+Enter` | 在 `/terminal-setup` 之后 |
| 控制序列 | `Ctrl+J` | 多行换行符 |
| 粘贴模式 | 直接粘贴 | 用于代码块、日志 |
<!--rehype:className=left-align shortcuts-->
### 快速命令
| 快捷键 | 描述 | 注释 |
| --- | --- | --- |
| 开头的 `#` | 内存快捷键 - 添加到 CLAUDE.md | 提示文件选择 |
| 开头的 `/` | 斜杠命令 | 参见[斜杠命令](https://docs.anthropic.com/zh-CN/docs/claude-code/slash-commands) |
| 开头的 `!` | Bash 模式 | 直接运行命令并将执行输出添加到会话中 |
<!--rehype:className=left-align shortcuts-->
Vim 编辑器模式
---
### 模式切换
| 命令 | 操作 | 从模式 |
| --- | --- | --- |
| `Esc` | 进入 NORMAL 模式 | INSERT |
| `i` | 在光标前插入 | NORMAL |
| `I` | 在行首插入 | NORMAL |
| `a` | 在光标后插入 | NORMAL |
| `A` | 在行尾插入 | NORMAL |
| `o` | 在下方打开新行 | NORMAL |
| `O` | 在上方打开新行 | NORMAL |
### 导航NORMAL 模式)
| 命令 | 操作 |
| --- | --- |
| `h`/`j`/`k`/`l` | 向左/下/上/右移动 |
| `w` | 下一个单词 |
| `e` | 单词末尾 |
| `b` | 上一个单词 |
| `0` | 行首 |
| `$` | 行尾 |
| `^` | 第一个非空白字符 |
| `gg` | 输入开头 |
| `G` | 输入末尾 |
### 编辑NORMAL 模式)
| 命令 | 操作 |
| --- | --- |
| `x` | 删除字符 |
| `dd` | 删除行 |
| `D` | 删除到行尾 |
| `dw`/`de`/`db` | 删除单词/到末尾/向后 |
| `cc` | 更改行 |
| `C` | 更改到行尾 |
| `cw`/`ce`/`cb` | 更改单词/到末尾/向后 |
| `.` | 重复上次更改 |
Hooks 参考
---
### 配置
* `~/.claude/settings.json` 用户设置
* `.claude/settings.json` 项目设置
* `.claude/settings.local.json` 本地项目设置(不提交)
* 企业管理策略设置
### 结构
<!--rehype:wrap-class=col-span-2 row-span-2-->
```json
{
"hooks": {
"EventName": [
{
"matcher": "ToolPattern",
"hooks": [
{ "type": "command", "command": "your-command-here" }
]
}
]
}
}
```
#### <pur>matcher</pur> 匹配工具名称的模式,区分大小写(仅适用于 `PreToolUse` 和 `PostToolUse`
* 简单字符串精确匹配:`Write` 仅匹配 Write 工具
* 支持正则表达式:`Edit|Write``Notebook.*`
* 使用 `*` 匹配所有工具。您也可以使用空字符串(`""`)或留空 `matcher`
#### <pur>hooks</pur> 当模式匹配时要执行的命令数组
* `type`:目前仅支持 `"command"`
* `command`:要执行的 bash 命令(可以使用 `$CLAUDE_PROJECT_DIR` 环境变量)
* `timeout`:(可选)命令应该运行多长时间(以秒为单位),在取消该特定命令之前。
### 项目特定的 Hook 脚本
```json {9}
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/check-style.sh"
}
]
}
]
}
}
```
可通过环境变量 `CLAUDE_PROJECT_DIR` 引用项目中的脚本,确保无论 Claude 当前目录如何都能正常使用(仅在生成 hook 命令时可用)
Hook 事件
---
### PreToolUse
#### 常见匹配器
* `Task` - 子代理任务(参见[子代理文档](https://docs.anthropic.com/zh-CN/docs/claude-code/sub-agents)
* `Bash` - Shell 命令
* `Glob` - 文件模式匹配
* `Grep` - 内容搜索
* `Read` - 文件读取
* `Edit`、`MultiEdit` - 文件编辑
* `Write` - 文件写入
* `WebFetch`、`WebSearch` - Web 操作
在 Claude 创建工具参数之后、处理工具调用之前运行。
### 其它 Hook
Hook | 描述
--- | ---
`PostToolUse` | 在工具成功完成后立即运行。
`UserPromptSubmit` | 当用户提交提示时、Claude 处理之前运行。这允许您根据提示/对话添加额外的上下文、验证提示或阻止某些类型的提示。
`Stop` | 当主 Claude Code 代理完成响应时运行。如果停止是由于用户中断而发生的,则不会运行。
`SubagentStop` | 当 Claude Code 子代理Task 工具调用)完成响应时运行。
<!--rehype:className=style-list-arrow square-->
### Notification
当 Claude Code 发送通知时运行。通知在以下情况下发送:
Hook | 描述
--- | ---
Claude 需要您的权限来使用工具。 | 示例“Claude needs your permission to use Bash”
提示输入已空闲至少 `60` 秒。 | “Claude is waiting for your input”
<!--rehype:className=style-list-arrow square-->
### PreCompact
在 Claude Code 即将运行压缩操作之前运行。
#### 匹配器
<!--rehype:style=text-align:left;-->
Hook | 描述
--- | ---
`manual` | 从 `/compact` 调用
`auto` | 从自动压缩调用(由于上下文窗口已满)
<!--rehype:className=style-list-arrow square-->
### SessionStart
当 Claude Code 启动新会话或恢复现有会话时运行(目前确实会在底层启动新会话)
#### 匹配器
<!--rehype:style=text-align:left;-->
* `startup` - 从启动调用
* `resume` - 从 `--resume`、`--continue` 或 `/resume` 调用
* `clear` - 从 `/clear` 调用
* `compact` - 从自动或手动压缩调用。
对于加载开发上下文(如现有问题或代码库的最近更改)很有用。
### SessionEnd
#### hook 输入中的 reason 字段将是以下之一
<!--rehype:style=text-align:left;-->
* `clear` - 使用 /clear 命令清除会话
* `logout` - 用户注销
* `prompt_input_exit` - 用户在提示输入可见时退出
* `other` - 其他退出原因
当 Claude Code 会话结束时运行。对于清理任务、记录会话统计信息或保存会话状态很有用。
Hook 输入
---
### 示例
Hooks 通过 `stdin` 接收包含会话信息和事件特定数据的 JSON 数据:
```json
{
// 通用字段
session_id: string
// 对话 JSON 的路径
transcript_path: string
// 调用 hook 时的当前工作目录
cwd: string
// 事件特定字段
hook_event_name: string
...
}
```
### PreToolUse 输入
`tool_input` 的确切模式取决于工具。
```json {5}
{
"session_id": "abc123",
"transcript_path": "/Users/.../.claude/projects/.../00893aaf-19fa-41d2-8238-13269b9b3ca0.jsonl",
"cwd": "/Users/...",
"hook_event_name": "PreToolUse",
"tool_name": "Write",
"tool_input": {
"file_path": "/path/to/file.txt",
"content": "file content"
}
}
```
### PostToolUse 输入
`tool_input` 和 `tool_response` 的确切模式取决于工具。
```json {5}
{
"session_id": "abc123",
"transcript_path": "/Users/.../.claude/projects/.../00893aaf-19fa-41d2-8238-13269b9b3ca0.jsonl",
"cwd": "/Users/...",
"hook_event_name": "PostToolUse",
"tool_name": "Write",
"tool_input": {
"file_path": "/path/to/file.txt",
"content": "file content"
},
"tool_response": {
"filePath": "/path/to/file.txt",
"success": true
}
}
```
### Notification 输入
```json {5}
{
"session_id": "abc123",
"transcript_path": "/Users/.../.claude/projects/.../00893aaf-19fa-41d2-8238-13269b9b3ca0.jsonl",
"cwd": "/Users/...",
"hook_event_name": "Notification",
"message": "Task completed successfully"
}
```
### UserPromptSubmit 输入
```json {5}
{
"session_id": "abc123",
"transcript_path": "/Users/.../.claude/projects/.../00893aaf-19fa-41d2-8238-13269b9b3ca0.jsonl",
"cwd": "/Users/...",
"hook_event_name": "UserPromptSubmit",
"prompt": "Write a function to calculate the factorial of a number"
}
```
### Stop 和 SubagentStop 输入
```json {4}
{
"session_id": "abc123",
"transcript_path": "~/.claude/projects/.../00893aaf-19fa-41d2-8238-13269b9b3ca0.jsonl",
"hook_event_name": "Stop",
"stop_hook_active": true
}
```
当 Claude Code 已经因为 `stop hook` 而继续时,`stop_hook_active` 为 `true`。检查此值或处理记录以防止 Claude Code 无限运行。
### PreCompact 输入
```json {4}
{
"session_id": "abc123",
"transcript_path": "~/.claude/projects/.../00893aaf-19fa-41d2-8238-13269b9b3ca0.jsonl",
"hook_event_name": "PreCompact",
"trigger": "manual",
"custom_instructions": ""
}
```
对于 `manual``custom_instructions` 来自用户传递给 `/compact` 的内容。对于 `auto``custom_instructions` 为空。
### SessionStart 输入
```json {4}
{
"session_id": "abc123",
"transcript_path": "~/.claude/projects/.../00893aaf-19fa-41d2-8238-13269b9b3ca0.jsonl",
"hook_event_name": "SessionStart",
"source": "startup"
}
```
### SessionEnd 输入
```json {5}
{
"session_id": "abc123",
"transcript_path": "~/.claude/projects/.../00893aaf-19fa-41d2-8238-13269b9b3ca0.jsonl",
"cwd": "/Users/...",
"hook_event_name": "SessionEnd",
"reason": "exit"
}
```
另见
----
* [Claude 代码参考](https://docs.anthropic.com/zh-CN/docs/claude-code/cli-reference) _(docs.anthropic.com)_

View File

@@ -882,6 +882,50 @@ H2 部分
[#](https://github.com/jaywcjlove/reference/blob/ee03850619440e3700ed68ccc2ed21d3591a1490/docs/quickreference.md?plain=1#L850-L855)<!--rehype:target=__blank--> `<!--rehype:className=style-list-->`
### 列表圆圈样式展示表格
:- | :-
:- | :-
`visualEffectState.inactive` | 后台应一直显示为非激活状态。
`titleBarStyle` _string_ _(win/mac)_ | 窗口标题栏样式。默认值 _(default)_
`titleBarStyle.default` | 分别返回 _mac_ 或者 _win_ 的标准标题栏
<!--rehype:className=style-list-arrow circle-->
添加 `style-list-arrow` 和 `circle` 样式
### 列表实心圆圈样式展示表格
:- | :-
:- | :-
`visualEffectState.inactive` | 后台应一直显示为非激活状态。
`titleBarStyle` _string_ _(win/mac)_ | 窗口标题栏样式。默认值 _(default)_
`titleBarStyle.default` | 分别返回 _mac_ 或者 _win_ 的标准标题栏
<!--rehype:className=style-list-arrow circlefill-->
添加 `style-list-arrow` 和 `circlefill` 样式
### 列表方形展示表格
:- | :-
:- | :-
`visualEffectState.inactive` | 后台应一直显示为非激活状态。
`titleBarStyle` _string_ _(win/mac)_ | 窗口标题栏样式。默认值 _(default)_
`titleBarStyle.default` | 分别返回 _mac_ 或者 _win_ 的标准标题栏
<!--rehype:className=style-list-arrow square-->
添加 `style-list-arrow` 和 `square` 样式
### 列表实心方形展示表格
:- | :-
:- | :-
`visualEffectState.inactive` | 后台应一直显示为非激活状态。
`titleBarStyle` _string_ _(win/mac)_ | 窗口标题栏样式。默认值 _(default)_
`titleBarStyle.default` | 分别返回 _mac_ 或者 _win_ 的标准标题栏
<!--rehype:className=style-list-arrow squarefill-->
添加 `style-list-arrow` 和 `squarefill` 样式
### 列表箭头样式展示表格
:- | :-

View File

@@ -36,7 +36,7 @@
"markdownlint": "^0.33.0",
"markdownlint-cli": "^0.39.0",
"prettier": "^3.0.0",
"refs-cli": "^1.9.1"
"refs-cli": "^1.10.1"
},
"engines": {
"node": ">=16.0.0"