fix: map Claude Code 'stop' hook to TurnEnd instead of SessionEnd#22
fix: map Claude Code 'stop' hook to TurnEnd instead of SessionEnd#22malinosqui merged 1 commit intomainfrom
Conversation
The 'stop' hook fires every time Claude stops talking (waiting for user input), not when the session ends. Mapping it to SessionEnd caused premature session classification and missing turn_end data (tool calls, files modified, token usage). Now only 'session-end' maps to SessionEnd. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7e358004e5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| 'session-start': 'SessionStart', | ||
| 'session-end': 'SessionEnd', | ||
| 'stop': 'SessionEnd', | ||
| 'stop': 'TurnEnd', |
There was a problem hiding this comment.
Prevent duplicate TurnEnd emissions for TodoWrite turns
Mapping stop to TurnEnd means Claude/Cursor sessions that use TodoWrite now emit TurnEnd twice for the same turn, because installSessionHooks still wires both Stop -> ... stop and PostToolUse(TodoWrite) -> ... post-todo, and both hooks map to TurnEnd (src/commands/memory/session-hooks-install.ts and this map). lifecycleService.handleTurnEnd has no deduplication and sends a turn_end event on every call, so these turns can trigger duplicate extraction/classification and extra API traffic with the same turnId.
Useful? React with 👍 / 👎.
|
To improve tracking and context, please link this pull request to the issue it resolves by adding a closing keyword like 'Closes #issue-number' or 'Fixes #issue-number' to the description. If no specific issue is being closed, consider referencing any related issues. Kody Rule violation: Ensure PR closes referenced issues |
Summary
stophook fires when Claude stops talking and waits for user input — that's a turn ending, not a session endingSessionEnd, causing the API to trigger LLM classification beforeTurnEndcould capture rich transcript data (toolCalls, filesModified, filesRead, commands)What changed
src/agents/claude-code.agent.ts:'stop': 'SessionEnd'→'stop': 'TurnEnd'Impact
After this fix,
stopevents will correctly emitTurnEnd, which triggers transcript parsing to extract tool calls, modified files, commands, and token usage before sending to the API. This gives the LLM classifier much better context for decision extraction.🤖 Generated with Claude Code
Refactor: Map the Claude Code 'stop' hook to
TurnEndinstead ofSessionEnd.This change updates the internal mapping for Claude Code agent events, ensuring that the 'stop' hook is correctly interpreted as the end of a turn rather than the end of a session. The corresponding test case has also been updated to reflect this new mapping.