Skip to content

Commit f7d1a89

Browse files
fix: detect kavex source repo in activate to use correct hook paths
kavex activate was hardcoding .claude/hooks/ paths, which breaks when running inside the kavex source repo where hooks live at hooks/. Now detects the repo by checking for hooks at the project root and uses "$CLAUDE_PROJECT_DIR"/hooks/ paths accordingly. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent fd11bad commit f7d1a89

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

scripts/kavex

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,34 +361,46 @@ cmd_activate() {
361361
fi
362362
fi
363363

364-
# Define hooks config — references scripts installed by install.sh into .claude/hooks/
365-
# Legacy install path; plugin mode uses hooks/hooks.json instead
364+
# Detect hook path prefix:
365+
# - Kavex source repo: hooks live at $PROJECT_ROOT/hooks/ -> use "$CLAUDE_PROJECT_DIR"/hooks/
366+
# - Installed project: hooks live at $PROJECT_ROOT/.claude/hooks/ -> use .claude/hooks/
367+
local hook_prefix
368+
if [ -f "$PROJECT_ROOT/hooks/format.sh" ] && [ -f "$PROJECT_ROOT/hooks/block-dangerous.sh" ]; then
369+
# We're inside the Kavex source repo — use $CLAUDE_PROJECT_DIR paths
370+
# Escaped quotes for JSON embedding
371+
hook_prefix='\"$CLAUDE_PROJECT_DIR\"/hooks'
372+
else
373+
# Legacy install — hooks copied into .claude/hooks/
374+
hook_prefix='.claude/hooks'
375+
fi
376+
377+
# Define hooks config using detected path prefix
366378
local hooks_json
367-
hooks_json=$(cat <<'HOOKS'
379+
hooks_json=$(cat <<HOOKS
368380
{
369381
"PreToolUse": [
370382
{
371383
"matcher": "Bash",
372384
"hooks": [
373-
{"type": "command", "command": "cat | .claude/hooks/block-dangerous.sh", "timeout": 5},
374-
{"type": "command", "command": "cat | .claude/hooks/kavex-commit-gate.sh", "timeout": 5}
385+
{"type": "command", "command": "cat | ${hook_prefix}/block-dangerous.sh", "timeout": 5},
386+
{"type": "command", "command": "cat | ${hook_prefix}/kavex-commit-gate.sh", "timeout": 5}
375387
]
376388
},
377389
{
378390
"matcher": "Write|Edit|MultiEdit",
379-
"hooks": [{"type": "command", "command": "cat | .claude/hooks/protect-files.sh", "timeout": 5}]
391+
"hooks": [{"type": "command", "command": "cat | ${hook_prefix}/protect-files.sh", "timeout": 5}]
380392
}
381393
],
382394
"PostToolUse": [
383395
{
384396
"matcher": "Write|Edit|MultiEdit",
385-
"hooks": [{"type": "command", "command": "cat | .claude/hooks/format.sh", "timeout": 30}]
397+
"hooks": [{"type": "command", "command": "cat | ${hook_prefix}/format.sh", "timeout": 30}]
386398
}
387399
],
388400
"Stop": [
389401
{
390402
"matcher": "",
391-
"hooks": [{"type": "command", "command": "cat | .claude/hooks/verify-on-stop.sh", "timeout": 60}]
403+
"hooks": [{"type": "command", "command": "cat | ${hook_prefix}/verify-on-stop.sh", "timeout": 60}]
392404
}
393405
]
394406
}

0 commit comments

Comments
 (0)