fix: rtk hook 改为绝对路径,避免 Claude Code PATH 中找不到 rtk

rtk init 后自动将 settings.json hook command 替换为绝对路径
/root/.cargo/bin/rtk hook claude

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-05-28 17:07:45 +08:00
parent afbbb031d3
commit a550a2675e

View File

@@ -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 管道自动确认所有提示) # 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 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 配置 # Step 8: PowerShell Profile 配置