From a550a2675e031d144338d7558d9cc529a26896e2 Mon Sep 17 00:00:00 2001 From: Joywayer Date: Thu, 28 May 2026 17:07:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20rtk=20hook=20=E6=94=B9=E4=B8=BA=E7=BB=9D?= =?UTF-8?q?=E5=AF=B9=E8=B7=AF=E5=BE=84=EF=BC=8C=E9=81=BF=E5=85=8D=20Claude?= =?UTF-8?q?=20Code=20PATH=20=E4=B8=AD=E6=89=BE=E4=B8=8D=E5=88=B0=20rtk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rtk init 后自动将 settings.json hook command 替换为绝对路径 /root/.cargo/bin/rtk hook claude Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- claude-dev-stack/deploy.ps1 | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/claude-dev-stack/deploy.ps1 b/claude-dev-stack/deploy.ps1 index 1ac5e51..2b27047 100644 --- a/claude-dev-stack/deploy.ps1 +++ b/claude-dev-stack/deploy.ps1 @@ -680,7 +680,32 @@ CARGO_NET_GIT_FETCH_WITH_CLI=true cargo install --git https://github.com/rtk-ai/ # rtk init -g:安装 Claude Code PreToolUse hook(幂等,yes 管道自动确认所有提示) Invoke-WSL ". ~/.cargo/env 2>/dev/null; yes | rtk init -g --auto-patch 2>/dev/null || true" -IgnoreError | Out-Null -Write-OK "rtk hook 已注册 (rtk init -g),重启 Claude Code 后生效" + +# 将 settings.json 中的 hook command 改为绝对路径(避免 Claude Code 找不到 rtk) +$fixRtkHookCmd = @' +. ~/.cargo/env 2>/dev/null || true +RTK_BIN=$(which rtk 2>/dev/null) +if [ -n "$RTK_BIN" ] && [ -f ~/.claude/settings.json ]; then + python3 -c " +import json, sys +p='/root/.claude/settings.json' +with open(p) as f: d=json.load(f) +hooks=d.get('hooks',{}) +changed=False +for event in hooks: + for h in (hooks[event] if isinstance(hooks[event],list) else [hooks[event]]): + if isinstance(h,dict) and 'command' in h and 'rtk hook' in h['command']: + h['command']=h['command'].replace('rtk hook','$RTK_BIN hook') + changed=True +if changed: + with open(p,'w') as f: json.dump(d,f,indent=2) + print('hook path updated to $RTK_BIN') +" 2>/dev/null || true +fi +true +'@ +Invoke-WSL $fixRtkHookCmd -IgnoreError | Out-Null +Write-OK "rtk hook 已注册(绝对路径),重启 Claude Code 后生效" # ══════════════════════════════════════════════════════════════ # Step 8: PowerShell Profile 配置