Skip to content

fix(hooks): use SessionEnd not Stop for Claude Code transcript extraction#355

Open
Huntehhh wants to merge 1 commit into
buildingjoshbetter:mainfrom
Huntehhh:fix/claude-adapter-use-session-end-not-stop
Open

fix(hooks): use SessionEnd not Stop for Claude Code transcript extraction#355
Huntehhh wants to merge 1 commit into
buildingjoshbetter:mainfrom
Huntehhh:fix/claude-adapter-use-session-end-not-stop

Conversation

@Huntehhh
Copy link
Copy Markdown
Contributor

Summary

The Claude Code adapter wires stop.py to the per-turn Stop event instead of the per-session SessionEnd event. Per Claude Code's hook docs: Stop fires once per assistant response; SessionEnd fires once per session terminate. Result: every turn triggers an ingest spawn — the 20/hr budget + 2-process spawn cap prevent runaway, but produces visible ingest spam on chatty sessions, most of which then no-op via the size-dedup gate but still pay the python.exe spawn cost.

The Gemini adapter at truememory/hooks/adapters/gemini.py:27 already uses SessionEnd correctly — this brings the Claude adapter in line with that pattern. Codex (adapters/codex.py:30) and Kimi (adapters/kimi.py:30) intentionally untouched — they correctly use Stop per their own CLI specs.

Changes

File Change
truememory/ingest/cli.py:794 docstring narrative: Stop → SessionEnd
truememory/ingest/cli.py:812 installer event key: "Stop""SessionEnd" (the bug)
truememory/ingest/cli.py:1086 expected-events health check list
truememory/ingest/CLAUDE_TEMPLATE.md:36 user-facing narrative
docs/architecture.md:43 architecture doc + brief Stop-vs-SessionEnd clarification
install.sh:15 install-script comment listing events

Test plan

  • Fresh install on Claude Code → truememory-ingest status shows Hooks installed: SessionStart, UserPromptSubmit, SessionEnd, PreCompact
  • Verify ~/.claude/settings.json contains a "SessionEnd" block pointing at stop.py
  • Run multi-turn session in Claude Code → confirm NO ingest spawns mid-session (ps -ef | grep truememory.ingest.cli returns nothing during the conversation)
  • Quit the session → confirm exactly 1 ingest spawn fires
  • Verify Codex + Kimi installs unchanged (still wire on Stop per their CLI specs)

References

Co-Authored-By: claude-opus-4-7 wontreply@getfucked.ai

…tion

The Claude Code adapter installs the `stop.py` extraction hook on the
`Stop` event, which fires per assistant turn (once per response). The
intent — per the README and stop.py docstring — is session-end
extraction. The Gemini adapter at adapters/gemini.py:27 already uses
`SessionEnd` correctly; the Claude adapter was missed.

Per Claude Code docs (code.claude.com/docs/en/hooks):
- `Stop` fires once per turn ("when Claude finishes responding")
- `SessionEnd` fires once per session ("when a session terminates")

Net effect of the bug: every assistant turn triggers an ingest spawn.
The 20/hr budget + 2-process spawn cap prevent runaway, but produces
~1 ingest spawn every ~10s on chatty sessions — most then no-op via
the size-dedup gate but still cost the python.exe spawn cycle.

Fix is the trivial event-name swap on the Claude adapter only.
Codex (adapters/codex.py:30) and Kimi (adapters/kimi.py:30) adapters
intentionally untouched — they correctly use 'Stop' per their own
CLI specs.

Files changed:
- truememory/ingest/cli.py:794 docstring narrative
- truememory/ingest/cli.py:812 installer event key (the bug)
- truememory/ingest/cli.py:1086 expected-events health check
- truememory/ingest/CLAUDE_TEMPLATE.md user-facing narrative
- docs/architecture.md
- install.sh comment

Co-Authored-By: claude-opus-4-7 <wontreply@getfucked.ai>
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.

1 participant