fix: register the hook as PostToolUse so it actually fires#3
Open
quad341 wants to merge 1 commit into
Open
Conversation
`init` wrote the hook under `PostToolExecution` with a flat `command` key.
Claude Code has no such event, and matcher entries need a nested
`hooks: [{type, command}]` array — so the hook was silently ignored on every
install. No events reached events.json, and the mood engine never saw a tool
use, leaving pets on idle messages permanently.
Write the documented shape instead, and clear the stale `PostToolExecution`
entry on init so existing installs are migrated by re-running `codachi init`.
`uninstall` now cleans up both event names, and both paths leave other tools'
hooks untouched.
Adds src/init.test.ts (14 tests) covering the written shape, idempotency,
legacy migration, foreign-hook preservation, and uninstall.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
codachi initwrites the hook into~/.claude/settings.jsonlike this:Two problems: Claude Code has no
PostToolExecutionevent (it'sPostToolUse), and a matcher entry carries its commands in a nestedhooks: [{type, command}]array rather than a flatcommandkey.The result is a hook that never runs. Claude Code ignores the unknown event,
codachi-hookis never invoked, nothing is ever appended toevents.json, and the mood engine has no events to read — so pets sit on idle/context messages forever and none of the ~40 event categories or the reactions built on them ever surface. It fails silently: the install prints success and the statusline renders fine, which is presumably why it went unnoticed.CLAUDE.mdalready documents the data flow asPostToolUse, so this looks like a straightforward slip ininit.tsrather than a deliberate choice.The fix
initwritesPostToolUsewith the nestedhooksarray andmatcher: "*".initalso drops any stale codachi entry left underPostToolExecution, so existing users are migrated by re-runningcodachi init— no manual settings editing.uninstallcleans up both event names.README.mdmanual-setup block and prose,CLAUDE.md,hook.tsheader.Verification
src/init.test.tsis new — 14 tests covering the written shape, statusLine, idempotent re-init, legacy migration, preservation of foreign hooks and unrelated settings, local-clone absolute paths, and the uninstall paths including the no-op cases.Full suite: 375 passed (20 files),
tsc --noEmitclean.Also verified end-to-end against a throwaway
$HOMEcontaining a legacy install plus an unrelatedPreToolUsehook:initmigrated it toPostToolUse, left the foreign hook alone, anduninstallremoved only codachi's entry.I'm running this fix locally and the hook now records events as expected.
🤖 Generated with Claude Code
https://claude.ai/code/session_018sFUvWzeRmjzQGDUsLnYgY