Skip to content

fix: map Claude Code 'stop' hook to TurnEnd instead of SessionEnd#22

Merged
malinosqui merged 1 commit intomainfrom
fix/stop-hook-mapping
Mar 9, 2026
Merged

fix: map Claude Code 'stop' hook to TurnEnd instead of SessionEnd#22
malinosqui merged 1 commit intomainfrom
fix/stop-hook-mapping

Conversation

@malinosqui
Copy link
Copy Markdown
Member

@malinosqui malinosqui commented Mar 9, 2026

Summary

  • The stop hook fires when Claude stops talking and waits for user input — that's a turn ending, not a session ending
  • This was mapped to SessionEnd, causing the API to trigger LLM classification before TurnEnd could capture rich transcript data (toolCalls, filesModified, filesRead, commands)
  • Result: LLM classifier received empty arrays and produced low-quality decisions

What changed

  • src/agents/claude-code.agent.ts: 'stop': 'SessionEnd''stop': 'TurnEnd'
  • Updated corresponding test

Impact

After this fix, stop events will correctly emit TurnEnd, 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 TurnEnd instead of SessionEnd.

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.

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-ai
Copy link
Copy Markdown

kody-ai bot commented Mar 9, 2026

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug
Performance
Security
Cross File
Business Logic

Access your configuration settings here.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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',
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@kody-ai
Copy link
Copy Markdown

kody-ai bot commented Mar 9, 2026

kody code-review Kody Rules critical

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

@malinosqui malinosqui merged commit 2e0e8b5 into main Mar 9, 2026
5 checks passed
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