Skip to content

feat(types): add PostCompact hook event support#691

Open
husniadil wants to merge 1 commit intoanthropics:mainfrom
husniadil:feat/post-compact-hook
Open

feat(types): add PostCompact hook event support#691
husniadil wants to merge 1 commit intoanthropics:mainfrom
husniadil:feat/post-compact-hook

Conversation

@husniadil
Copy link
Copy Markdown

Summary

Adds PostCompact hook event support to the Python SDK, matching the Claude Code CLI v2.1.76+ specification.

PostCompact fires after a compact operation completes, providing the trigger type (manual/auto) and compact_summary (the generated conversation summary).

Changes

  • Add "PostCompact" to HookEvent union type
  • Add PostCompactHookInput with trigger and compact_summary fields
  • Add PostCompactHookSpecificOutput with additionalContext field
  • Add to HookInput and HookSpecificOutput union types
  • Export new types from __init__.py

Tests

  • Type construction tests for PostCompactHookInput (auto + manual trigger)
  • Type construction test for PostCompactHookSpecificOutput
  • Behavioral callback test verifying end-to-end hook execution via MockTransport

Verified against Claude Code hooks docs and tested with live CLI v2.1.77.

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>
@husniadil husniadil force-pushed the feat/post-compact-hook branch from a0e70aa to 8f12409 Compare March 31, 2026 03:06
@km-anthropic
Copy link
Copy Markdown
Collaborator

@claude review

Copy link
Copy Markdown
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

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

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.

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.

2 participants