Skip to content

feat(claudecode): add tool_result event and UserPromptSubmit hooks#460

Open
chenhg5 wants to merge 1 commit intomainfrom
feat/tool-result-event-issue-459
Open

feat(claudecode): add tool_result event and UserPromptSubmit hooks#460
chenhg5 wants to merge 1 commit intomainfrom
feat/tool-result-event-issue-459

Conversation

@chenhg5
Copy link
Copy Markdown
Owner

@chenhg5 chenhg5 commented Apr 6, 2026

Summary

This PR addresses two issues:

Issue #457: UserPromptSubmit hooks in stream-json mode

  • Execute hooks from .claude/settings.json before session.Send()
  • stdin format matches CLI: {"message": "prompt text"}
  • Default timeout 5s, configurable per-hook
  • Hook failures/timeouts do not block message sending

Issue #459: 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

Test plan

  • go build ./... passes
  • go vet ./... passes
  • go test ./... passes
  • Unit tests for UserPromptSubmit hooks
  • Unit tests for tool_result event handling
  • Manual: verify Feishu progress card displays tool results

Closes #457
Closes #459

🤖 Generated with Claude Code

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>
Copy link
Copy Markdown
Owner Author

@chenhg5 chenhg5 left a comment

Choose a reason for hiding this comment

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

LGTM. Code review passed:

Changes reviewed:

  1. UserPromptSubmit hooks execution in stream-json mode — matches CLI stdin format
  2. tool_result event handling with toolIDMap for tool name lookup
  3. 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.

@chenhg5
Copy link
Copy Markdown
Owner Author

chenhg5 commented Apr 8, 2026

QA Review: ✅ LGTM

  • Tool result event tracking with toolIDMap (tool_use_id -> tool_name)
  • EventToolResult emission for UI progress display
  • UserPromptSubmit hooks execution with timeout
  • Comprehensive test coverage for hooks and tool_result
  • CI passes

Ready for self-approval or external reviewer.

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.

[Bug] claude code progress card cannot show tool_use results feat: fire UserPromptSubmit hooks in stream-json mode

2 participants