Skip to content

feat(B): PreCompact hook prunes superseded context (Claude bonus) - #112

Merged
Mibayy merged 1 commit into
mainfrom
feat/precompact-superseded
Jul 28, 2026
Merged

feat(B): PreCompact hook prunes superseded context (Claude bonus)#112
Mibayy merged 1 commit into
mainfrom
feat/precompact-superseded

Conversation

@Mibayy

@Mibayy Mibayy commented Jul 28, 2026

Copy link
Copy Markdown
Owner

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) (in discover/superseded.py): reads the session transcript, runs find_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, extracts transcript_path, appends the section. A stdin capture + one Python call; gated by the same TS_MEMORY_DISABLE as 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_report from 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).

…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>
@Mibayy
Mibayy merged commit f4e83a2 into main Jul 28, 2026
3 checks passed
@Mibayy
Mibayy deleted the feat/precompact-superseded branch July 28, 2026 17:39
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.

1 participant