Skip to content

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

@CircleFiller

Description

@CircleFiller

Summary

npx codachi init writes the hook under the event key PostToolExecution, but Claude Code's canonical hook event name is PostToolUse. As a result:

  1. claude /doctor flags an unknown settings key (Found 1 settings issue).
  2. The hook never fires, so events.json stays empty and the pet has no events to react to (defeats the main selling point).

The entry shape is also flat ({matcher, command}); Claude Code's canonical form is {matcher, hooks: [{type, command}]}.

Repro

On a fresh box:

npx codachi init
claude /doctor      # → "Found 1 settings issue"

Then inspect ~/.claude/settings.json — you'll see "PostToolExecution" where "PostToolUse" should be.

Evidence

src/init.ts:65 currently:

hooks.PostToolExecution = cleaned;

…and cleaned.push({ matcher: '', command: hookCmd }) on line 64 produces the flat shape.

Suggested fix

// init.ts — around lines 62–66
const postHooks = Array.isArray(hooks.PostToolUse) ? hooks.PostToolUse : [];
const cleaned = postHooks.filter(/* existing codachi filter */);
cleaned.push({
  matcher: '',
  hooks: [{ type: 'command', command: hookCmd }],
});
hooks.PostToolUse = cleaned;

Plus a one-off migration in runInit() to move any old PostToolExecution entries onto PostToolUse so existing users upgrade cleanly.

Canonical hook event names from Claude Code docs: PreToolUse, PostToolUse, UserPromptSubmit, Notification, Stop, SubagentStop, SessionStart, SessionEnd, PreCompact.

Happy to open a PR if useful — small change, plus a test against the expected settings.json shape.


Discovered while setting up codachi on Claude Code v2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions