feat(types): add PostCompact hook event support#691
feat(types): add PostCompact hook event support#691husniadil wants to merge 1 commit intoanthropics:mainfrom
Conversation
Add PostCompact hook event type, input, and specific output types to match Claude Code CLI v2.1.76+. PostCompact fires after compact operations complete, providing trigger type and compact summary. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
a0e70aa to
8f12409
Compare
|
@claude review |
There was a problem hiding this comment.
LGTM — straightforward addition of PostCompact hook event types following the established pattern.
Extended reasoning...
Overview
This PR adds PostCompact hook event support across four files: new PostCompactHookInput and PostCompactHookSpecificOutput TypedDict classes in types.py, their addition to the HookEvent, HookInput, and HookSpecificOutput union types, exports in __init__.py, and corresponding tests in test_types.py and test_tool_callbacks.py.
Security risks
None. The changes are purely additive type definitions and test code. No auth, crypto, or permission logic is modified.
Level of scrutiny
Low scrutiny is appropriate. The new types follow the exact same pattern as the existing hook events (PreCompact, Notification, SubagentStart, PermissionRequest). The PostCompactHookInput has hook_event_name, trigger, and compact_summary fields — mirroring PreCompactHookInput which has trigger and custom_instructions. The output type follows the standard hookEventName + additionalContext pattern.
Other factors
Tests are thorough: type construction tests for both auto and manual triggers, output type construction, and a behavioral callback test using MockTransport that verifies the full hook execution flow. No CODEOWNERS concerns, no outstanding reviewer comments, and no bugs found by the automated bug hunting system.
Summary
Adds
PostCompacthook event support to the Python SDK, matching the Claude Code CLI v2.1.76+ specification.PostCompactfires after a compact operation completes, providing thetriggertype (manual/auto) andcompact_summary(the generated conversation summary).Changes
"PostCompact"toHookEventunion typePostCompactHookInputwithtriggerandcompact_summaryfieldsPostCompactHookSpecificOutputwithadditionalContextfieldHookInputandHookSpecificOutputunion types__init__.pyTests
PostCompactHookInput(auto + manual trigger)PostCompactHookSpecificOutputMockTransportVerified against Claude Code hooks docs and tested with live CLI v2.1.77.