Implement the following plan: Plan: Fix hook response format and add wingman warning…
Private research annotation
Sign in to add a private research label or note.
- User
Implement the following plan:
Plan: Fix hook response format and add wingman warning message
Context
The wingman review injection via
additionalContextisn't working because the hook response JSON format is wrong. The code outputs{"additionalContext": "..."}at the top level, but Claude Code expects it nested underhookSpecificOutput:json{ "hookSpecificOutput": { "hookEventName": "UserPromptSubmit", "additionalContext": "..." } }This also affects
SessionStartwhich usessystemMessageat the top level for context injection, but should usehookSpecificOutput.additionalContextto inject context Claude can see.The user also wants a
systemMessagewarning (universal field, shown to user) when a wingman review is about to be injected on prompt submit.Ref: https://code.claude.com/docs/en/hooks
Changes
1. Update
hookResponsestruct and output functionsFile:
cmd/entire/cli/hooks.go(lines 302-331)Replace the current
hookResponsestruct and functions:go// Current (broken): type hookResponse struct { SystemMessage string `json:"systemMessage,omitempty"` AdditionalContext string `json:"additionalContext,omitempty"` }New struct matching Claude Code's expected format:
gotype hookSpecificOutput struct { HookEventName string `json:"hookEventName"` AdditionalContext string `json:"additionalContext,omitempty"` } type hookResponse struct { SystemMessage string `json:"systemMessage,omitempty"` HookSpecificOutput *hookSpecificOutput `json:"hookSpecificOutput,omitempty"` }Update
outputHookResponse(SessionStart) to use with instead of top-level , since the goal is to inject context Claude can see. Assistant
I'll start by reading the relevant files to understand the current code before making changes.
Assistant
Let me read the test file and check for other callers of these output functions.
Assistant
Let me check if the Gemini handler also uses these functions, and look at the wingman instruction content.
Assistant
Good. The Gemini handler doesn't use these functions — only Claude Code does. Now I have a clear picture. Let me create tasks and start implementing.
Assistant
Now let me update the
hookResponsestruct and both output functions inhooks.go.Assistant
Now update the wingman injection in
captureInitialState()to use the new combined function.Assistant
Now let me add tests for the hook response functions. I need to make the output functions testable by accepting a writer, or test them via capturing stdout. Since the functions write to
os.Stdout, the cleanest approach is to add tests that verify the JSON structure. Let me check the approach used in the existing tests.The existing output functions use
os.Stdoutdirectly, which makes them hard to test. I'll add tests that use a writer-based approach. But first, let me check if there's a pattern for testing stdout output in this codebase.Assistant
I'll add tests that verify the JSON structure by testing the struct marshaling directly. Let me add tests to
hooks_test.go.Assistant
Now add the tests at the end of the file.
Assistant
Now let me also check if there's a
bytesimport that's still used (it should be, from the existing tests).Good,
bytesis used in existing tests. Let me also addt.Parallel()to the existing tests that are missing it (per CLAUDE.md guidelines). Actually, that's outside the scope of this change. Let me just verify the existingbytesimport is still valid and then run CI.Assistant
The
outputHookResponseWithContextfunction is now unused since the only caller was switched tooutputHookResponseWithContextAndMessage. Let me check ifoutputHookResponseWithContextis still needed for future use or if I should remove it.Looking at the callers: the only place it was used was the wingman injection which now uses
outputHookResponseWithContextAndMessage. I should remove the unused function.Assistant
Lint passes. Now run the full test suite.
Assistant
All tests pass. Let me update the task.
Assistant
All done. Here's a summary of the changes:
cmd/entire/cli/hooks.go:- Replaced flat
hookResponsestruct with proper nested structure:hookSpecificOutputstruct (withhookEventNameandadditionalContext) nested underhookResponse.HookSpecificOutput - Updated
outputHookResponse()(SessionStart) to emithookSpecificOutput.additionalContextinstead of top-levelsystemMessage - Removed
outputHookResponseWithContext()(was the only caller, now unused) - Added
outputHookResponseWithContextAndMessage()which sets bothsystemMessage(user-visible warning) andhookSpecificOutput.additionalContext(agent context)
cmd/entire/cli/hooks_claudecode_handlers.go:- Changed wingman review injection to use
outputHookResponseWithContextAndMessage(), passing both the review instruction as context and"[Wingman] A code review is pending and will be addressed before your request."as a user-visible system message
- Replaced flat
- User
commit this
Assistant
The diff shows some unrelated changes in the strategy files (removing
//nolint:ireturncomments) and.entire/settings.json. I'll only stage the files relevant to this change.Assistant
Committed as
5fddc49c. The remaining unstaged changes are unrelated to this task.