feat(claudecode): add tool_result event and UserPromptSubmit hooks#460
Open
feat(claudecode): add tool_result event and UserPromptSubmit hooks#460
Conversation
This commit addresses two issues: 1. Issue #457: Execute UserPromptSubmit hooks in stream-json mode - Read hooks from .claude/settings.json - Execute before session.Send() with stdin format: {"message": "prompt"} - Default timeout 5s, configurable per-hook - Hook failures/timeouts do not block message sending 2. Issue #459: Emit EventToolResult for tool_result messages - Add toolIDMap to track tool_use_id -> tool_name mapping - Store mapping when receiving tool_use events in handleAssistant - Emit EventToolResult when receiving tool_result in handleUser - Handle both string and array content formats - Support error status for failed tool results Closes #457 Closes #459 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
chenhg5
commented
Apr 6, 2026
Owner
Author
chenhg5
left a comment
There was a problem hiding this comment.
LGTM. Code review passed:
Changes reviewed:
- UserPromptSubmit hooks execution in stream-json mode — matches CLI stdin format
- tool_result event handling with toolIDMap for tool name lookup
- Timeout handling for hooks (default 5s, configurable)
Tests: Comprehensive coverage for settings loading, hook execution, tool_result parsing.
Security: No issues — hooks are user-configured.
Ready for merge.
Owner
Author
|
QA Review: ✅ LGTM
Ready for self-approval or external reviewer. |
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses two issues:
Issue #457: UserPromptSubmit hooks in stream-json mode
.claude/settings.jsonbeforesession.Send(){"message": "prompt text"}Issue #459: EventToolResult for tool_result messages
toolIDMapto tracktool_use_id->tool_namemappingtool_useevents inhandleAssistantEventToolResultwhen receivingtool_resultinhandleUserTest plan
go build ./...passesgo vet ./...passesgo test ./...passesCloses #457
Closes #459
🤖 Generated with Claude Code