feat(B): PreCompact hook prunes superseded context (Claude bonus) - #112
Merged
Conversation
…onus) The PreCompact hook now reads the event's transcript_path and appends a 'Superseded context (safe to drop)' section built from find_superseded — the one place TS can actually shrink context, since compaction is where the window is rewritten. Logic lives in tested Python (precompact_report); the hook change is a stdin capture + one call. Best-effort, gated by the same TS_MEMORY_DISABLE as the rest of the hook. Everywhere else, ts_stale_context stays the advisory cross-agent path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Completes feature B.
ts_stale_context(merged in #111) surfaces superseded tool results as advice on any MCP agent; this adds the one place TS can actually remove them — the Claude Code PreCompact hook, which runs exactly when the conversation window is rewritten.precompact_report(transcript_path)(indiscover/superseded.py): reads the session transcript, runsfind_superseded, returns a compact 'Superseded context (safe to drop from the summary)' markdown section — or '' when there's nothing to prune. Best-effort, never raises.hooks/memory-precompact.sh: captures the PreCompact event payload from stdin, extractstranscript_path, appends the section. A stdin capture + one Python call; gated by the sameTS_MEMORY_DISABLEas the rest of the hook.Verified end-to-end: a transcript with a re-read of a file yields the section flagging that file. Tested:
precompact_reportfrom a real transcript file + the empty-on-missing case. ruff clean, bash -n clean.Honest scope: this is the Claude-only lever (compaction isn't exposed by other harnesses). Cross-agent prevention stays the pointer-returning tools (#110) + the advisory
ts_stale_context(#111).