Use UserPromptSubmit for caveman mode tracking

Switch caveman mode tracking from PostToolUse to UserPromptSubmit: update README to document the new hook, adjust caveman-mode-tracker.js to read the incoming `prompt` field (removing `user_prompt`), and modify install.sh to register the UserPromptSubmit hook with timeouts and status messages (and add a timeout/status for the activate hook). This ensures mode detection runs on every user prompt and prevents hook stalls by setting command timeouts and status text. Files changed: hooks/README.md, hooks/caveman-mode-tracker.js, hooks/install.sh.
This commit is contained in:
Julius Brussee
2026-04-09 21:14:43 +02:00
parent a9e62b48c3
commit 602d1639c6
3 changed files with 10 additions and 7 deletions
+4 -4
View File
@@ -18,10 +18,10 @@ Or from a cloned repo: `bash hooks/install.sh`
- Writes `full` to `~/.claude/.caveman-active` (flag file)
- Emits caveman rules as hidden SessionStart context
### `caveman-mode-tracker.js` — PostToolUse hook
### `caveman-mode-tracker.js` — UserPromptSubmit hook
- Fires after any Skill tool invocation
- Detects caveman-related skills and writes the active mode to the flag file
- Fires on every user prompt, checks for `/caveman` commands
- Writes the active mode to the flag file when a caveman command is detected
- Supports: `full`, `lite`, `ultra`, `wenyan`, `wenyan-lite`, `wenyan-ultra`, `commit`, `review`, `compress`
## Statusline Badge
@@ -52,7 +52,7 @@ Badge examples:
## How It Works
```
SessionStart hook ──writes "full"──▶ ~/.claude/.caveman-active ◀──writes mode── PostToolUse hook
SessionStart hook ──writes "full"──▶ ~/.claude/.caveman-active ◀──writes mode── UserPromptSubmit hook
reads
+1 -1
View File
@@ -13,7 +13,7 @@ process.stdin.on('data', chunk => { input += chunk; });
process.stdin.on('end', () => {
try {
const data = JSON.parse(input);
const prompt = (data.user_prompt || data.prompt || '').trim().toLowerCase();
const prompt = (data.prompt || '').trim().toLowerCase();
// Match /caveman commands
if (prompt.startsWith('/caveman')) {
+5 -2
View File
@@ -1,6 +1,6 @@
#!/bin/bash
# caveman — one-command hook installer for Claude Code
# Installs: SessionStart hook (auto-load rules) + PostToolUse hook (mode tracking)
# Installs: SessionStart hook (auto-load rules) + UserPromptSubmit hook (mode tracking)
# Usage: bash hooks/install.sh
# or: bash <(curl -s https://raw.githubusercontent.com/JuliusBrussee/caveman/main/hooks/install.sh)
set -e
@@ -50,6 +50,7 @@ node -e "
hooks: [{
type: 'command',
command: 'node $HOOKS_DIR/caveman-activate.js',
timeout: 5,
statusMessage: 'Loading caveman mode...'
}]
});
@@ -64,7 +65,9 @@ node -e "
settings.hooks.UserPromptSubmit.push({
hooks: [{
type: 'command',
command: 'node $HOOKS_DIR/caveman-mode-tracker.js'
command: 'node $HOOKS_DIR/caveman-mode-tracker.js',
timeout: 5,
statusMessage: 'Tracking caveman mode...'
}]
});
}