claude-code - 💡(How to fix) Fix Feature request: support additionalContext in PreCompact/PostCompact hook output [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46191Fetched 2026-04-11 06:26:45
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
labeled ×2

PreCompact and PostCompact hook events do not support hookSpecificOutput.additionalContext, but they should. Currently the only valid output field for these events is systemMessage (a display-only notification). There's no way to inject context into the compaction summary or the post-compaction conversation.

Error Message

  • Observed in hook schema validation error output

Root Cause

PreCompact and PostCompact hook events do not support hookSpecificOutput.additionalContext, but they should. Currently the only valid output field for these events is systemMessage (a display-only notification). There's no way to inject context into the compaction summary or the post-compaction conversation.

Fix Action

Workaround

Currently using systemMessage only (display notification) plus a flag file on disk that downstream tools check. This is fragile and doesn't actually influence what the model includes in the compaction summary.

Code Example

Hook JSON output validation failed:
  - : Invalid input

---

{
  "hookSpecificOutput": {
    "hookEventName": "PreCompact",
    "additionalContext": "COMPACTION NOTICE: Before summarizing, include any unwritten action items labeled 'UNWRITTEN ACTION ITEM:' so they survive context loss."
  }
}
RAW_BUFFERClick to expand / collapse

Summary

PreCompact and PostCompact hook events do not support hookSpecificOutput.additionalContext, but they should. Currently the only valid output field for these events is systemMessage (a display-only notification). There's no way to inject context into the compaction summary or the post-compaction conversation.

Use case

When a session compacts, we want the model to:

  1. Before compaction (PreCompact): Be instructed to explicitly include any unwritten structured data (action items, decisions, open questions) in the compaction summary, so they survive context loss and can be written to a database at session end.

  2. After compaction (PostCompact): Be reminded to scan the compaction summary for labeled items and persist them.

This is exactly the kind of workflow that additionalContext enables for UserPromptSubmit — injecting instructions the user shouldn't have to type themselves.

Current behavior

Using hookSpecificOutput with hookEventName: "PreCompact" or "PostCompact" fails validation:

Hook JSON output validation failed:
  - : Invalid input

The schema only accepts "PreToolUse", "UserPromptSubmit", and "PostToolUse" in hookSpecificOutput.hookEventName.

Requested behavior

Extend hookSpecificOutput to support PreCompact and PostCompact event types, with at minimum an additionalContext field (same semantics as UserPromptSubmit):

{
  "hookSpecificOutput": {
    "hookEventName": "PreCompact",
    "additionalContext": "COMPACTION NOTICE: Before summarizing, include any unwritten action items labeled 'UNWRITTEN ACTION ITEM:' so they survive context loss."
  }
}

Workaround

Currently using systemMessage only (display notification) plus a flag file on disk that downstream tools check. This is fragile and doesn't actually influence what the model includes in the compaction summary.

Environment

  • Claude Code CLI (Mac, zsh)
  • Observed in hook schema validation error output

extent analysis

TL;DR

Extend the hookSpecificOutput schema to support PreCompact and PostCompact event types with an additionalContext field.

Guidance

  • Verify the current schema validation rules for hookSpecificOutput to confirm the limitation.
  • Consider modifying the schema to include PreCompact and PostCompact in the list of accepted hookEventName values.
  • Test the updated schema with the proposed JSON output format to ensure compatibility.
  • Evaluate the feasibility of adding additionalContext to the existing systemMessage field as a temporary workaround.

Example

{
  "hookSpecificOutput": {
    "hookEventName": "PreCompact",
    "additionalContext": "COMPACTION NOTICE: Before summarizing, include any unwritten action items labeled 'UNWRITTEN ACTION ITEM:' so they survive context loss."
  }
}

Notes

The proposed solution assumes that the schema can be modified to support the additional event types and field. If the schema is not modifiable, alternative workarounds may be necessary.

Recommendation

Apply workaround: Modify the schema to support PreCompact and PostCompact event types with an additionalContext field, as this will enable the desired functionality and improve the overall workflow.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING