mirror of
https://github.com/Gmaker689/ai-diff-preview.git
synced 2026-09-27 03:21:52 +08:00
docs: 添加 Claude Code Hooks 配置文件
This commit is contained in:
@@ -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)}\""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user