From d1f4180dd94d611c88aec7ecb9ad2aed08967cdd Mon Sep 17 00:00:00 2001 From: Gmaker689 <1711322114@qq.com> Date: Thu, 18 Jun 2026 19:50:09 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=B7=BB=E5=8A=A0=20Claude=20Code=20Ho?= =?UTF-8?q?oks=20=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- claude-hooks-config.example.jsonc | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 claude-hooks-config.example.jsonc diff --git a/claude-hooks-config.example.jsonc b/claude-hooks-config.example.jsonc new file mode 100644 index 0000000..239a301 --- /dev/null +++ b/claude-hooks-config.example.jsonc @@ -0,0 +1,48 @@ +// ============================================================ +// AI Code Diff Preview — Claude Code Hooks 配置 +// ============================================================ +// +// 使用方式(二选一): +// +// 方式 A:项目级配置 +// 将以下内容写入项目根目录的 .claude/settings.json 中 +// +// 方式 B:用户级配置 +// 将以下内容写入 %USERPROFILE%/.claude/settings.json 中 +// (Windows: C:\Users\<用户名>\.claude\settings.json) +// (macOS/Linux: ~/.claude/settings.json) +// +// 注意:如果 .claude/settings.json 已存在,请合并 "hooks" 部分, +// 不要覆盖已有配置。 +// ============================================================ + +{ + "hooks": { + // PostToolUse: 每次 Claude 调用 Edit/Write 工具后触发 + // 写入事件到 pending.json → VSCode 插件监听到 → 记录变更 + "PostToolUse": [ + { + // 匹配条件:只有 Edit 或 Write 工具调用才触发 + "matcher": "tool_name === 'Edit' || tool_name === 'Write'", + "hooks": [ + { + "type": "command", + "command": "node -e \"const fs=require('fs');const p=process.cwd()+'/.claude/hooks/pending.json';try{fs.mkdirSync(require('path').dirname(p),{recursive:true});fs.writeFileSync(p,JSON.stringify({toolName:process.env.CLAUDE_TOOL_NAME,filePath:process.env.CLAUDE_TOOL_INPUT_FILE_PATH,oldString:process.env.CLAUDE_TOOL_INPUT_OLD_STRING||'',newString:process.env.CLAUDE_TOOL_INPUT_NEW_STRING||'',content:process.env.CLAUDE_TOOL_INPUT_CONTENT||'',timestamp:Date.now(),type:'edit'}));}catch(e){console.error(e)}\"" + } + ] + } + ], + // Stop: Claude 对话结束时触发 + // 写入 Stop 事件 → 插件弹出 QuickPick 总览 + "Stop": [ + { + "hooks": [ + { + "type": "command", + "command": "node -e \"const fs=require('fs');const p=process.cwd()+'/.claude/hooks/pending.json';try{fs.mkdirSync(require('path').dirname(p),{recursive:true});fs.writeFileSync(p,JSON.stringify({toolName:'Stop',filePath:'',oldString:'',newString:'',content:'',timestamp:Date.now(),type:'stop'}));}catch(e){console.error(e)}\"" + } + ] + } + ] + } +} \ No newline at end of file