Skip to content

Precompact hook saves session knowledge but can't prevent token re-inflation from re-injected file reads #70

@Bobyfil94

Description

@Bobyfil94

Summary

Gortex's precompact hook correctly fires distill_session before context compaction, preserving decisions and pinned notes across sessions. However, it has no authority over what Claude Code's harness re-injects as system-reminder blocks into the new context window after compaction. When the tail of the pre-compaction session included raw Read tool results on large indexed files, those full file contents are replayed verbatim — bypassing gortex enforcement hooks and re-inflating the context with content that gortex could have served at 30–40% of the tokens.

Observed behavior

After a session compaction, the resumed context contained system-reminder blocks replaying:

  • CosmosCommands.cpp (~10 KB, full file) — readable via get_symbol_source + compress_bodies: true at ~3–4 KB
  • Three Python helper scripts written during the session

The gortex pre-tool enforcement hooks (which deny Read on indexed source) do not fire on auto-injected system-reminder content, so there is no interception point.

Root cause

The precompact hook fires before summarization — at that point the Read results are already in context. The harness's decision about what to carry forward into the new window happens after the hook returns, outside gortex's reach.

Proposed fix

One or more of:

  1. Postcompact hook — a hook that fires after the new context window is initialized, receiving a list of re-injected tool results. Gortex could replace any re-injected Read result for an indexed file with a get_symbol_source / get_file_summary compressed equivalent, emitted as a leaner system-reminder substitute.

  2. Precompact content advisory — gortex emits a structured hint during precompact (e.g. a session_files_accessed note) that Claude Code's harness can use to decide not to re-inject raw file content for those paths, trusting the agent to re-fetch via graph tools.

  3. resume_context MCP tool — a dedicated tool the agent calls at session start (prompted by distill_session output) that takes a list of previously-accessed paths/symbols and returns them in compressed form, allowing the agent to explicitly swap injected content for a cheaper equivalent.

Environment

  • OS: Windows 11
  • Gortex daemon: vv0.41.0+29a0849
  • Host: Claude Code (claude-sonnet-4-6)

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions