Skip to content

fix(init): use canonical PostToolUse hook event (fixes #1)#2

Open
CircleFiller wants to merge 1 commit intovincent-k2026:masterfrom
CircleFiller:fix/post-tool-use-hook-event
Open

fix(init): use canonical PostToolUse hook event (fixes #1)#2
CircleFiller wants to merge 1 commit intovincent-k2026:masterfrom
CircleFiller:fix/post-tool-use-hook-event

Conversation

@CircleFiller
Copy link
Copy Markdown

Closes #1.

Summary

  • Rename hook event PostToolExecutionPostToolUse across runInit / runUninstall. The former isn't a valid Claude Code hook event, so /doctor flagged it and the hook never fired — meaning events.json stayed empty and the pet had nothing to react to (defeated the main selling point).
  • Switch the entry to Claude Code's canonical {matcher, hooks: [{type, command}]} shape.
  • Migrate any legacy PostToolExecution entries onto PostToolUse on re-init so existing users upgrade cleanly with a single npx codachi init.
  • runUninstall sweeps both keys so lingering legacy entries also get cleaned.
  • Codachi-detection now matches both the wrapped and legacy flat shapes, so idempotency works across the upgrade.

New tests

Adds src/init.test.ts (11 tests) covering:

  • PostToolUse key is used (and PostToolExecution is not).
  • Entries are written in the canonical wrapped shape.
  • statusLine is set.
  • Legacy PostToolExecution entries migrate onto PostToolUse.
  • Idempotency — running init twice leaves exactly one codachi entry.
  • Flat-shape legacy codachi entries get replaced with the wrapped form.
  • Unrelated PostToolUse entries from other tools are preserved.
  • Unrelated top-level settings keys (e.g. mcpServers) are preserved.
  • Uninstall cleans codachi from both PostToolUse and PostToolExecution.
  • Uninstall preserves other hooks.

Full suite: 381 tests pass (was 370).

Test plan

  • npm test — all 381 pass.
  • npm run build clean.
  • Manual: ran the rebuilt init against a dirty settings.json that had the legacy PostToolExecution entry → it cleanly migrated, /doctor passes.
  • Reviewer sanity check: run npx codachi init on a fresh config, confirm /doctor is happy and ~/.claude/plugins/codachi/events.json starts gaining entries.

🤖 Generated with Claude Code

`runInit()` was writing the hook under `PostToolExecution`, which isn't
a valid Claude Code hook event. Result: `claude /doctor` flagged an
unknown settings key, and the hook never fired, so `events.json` stayed
empty and the pet had no tool activity to react to.

Also fixes the entry shape — Claude Code's canonical form is
`{matcher, hooks: [{type, command}]}`, not the flat `{matcher, command}`.

Changes:
- `PostToolExecution` → `PostToolUse` everywhere in init/uninstall.
- Writes entries in the wrapped canonical shape.
- Migrates any legacy `PostToolExecution` entries onto `PostToolUse` on
  re-init, so existing users upgrade cleanly without losing the hook.
- Uninstall sweeps both keys so lingering legacy entries are cleaned too.
- Codachi-detection helper now matches both the wrapped and legacy flat
  shapes when deciding whether to replace vs preserve an entry.

Adds `src/init.test.ts` (11 tests) covering the shape, key, idempotency,
legacy migration, unrelated-hook preservation, and uninstall cleanup.

Full suite: 381 tests pass (was 370).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

init.ts writes invalid hook event name (PostToolExecution) — hook never fires; /doctor flags it

1 participant