Skip to content

nudge full-body Gortex reads toward compress_bodies (#40)#43

Merged
zzet merged 1 commit into
mainfrom
fix/issue-40-context-read-nudge
Jun 3, 2026
Merged

nudge full-body Gortex reads toward compress_bodies (#40)#43
zzet merged 1 commit into
mainfrom
fix/issue-40-context-read-nudge

Conversation

@zzet
Copy link
Copy Markdown
Owner

@zzet zzet commented Jun 2, 2026

Issue #40: Claude Code burns context reading whole files via Gortex's own read tools.

The PreToolUse hook redirects native Read/Grep/Glob to graph tools, but its matcher (Read|Grep|Glob|Task|Bash|Edit|Write) never matched mcp__gortex__read_file — once the agent was inside a Gortex read tool, nothing guarded how it was called, and read_file defaults to compress_bodies:false. So the expensive path was the default path with no forcing function.

Close the gap:

  • Add mcp__gortex__read_file and mcp__gortex__get_editing_context to the PreToolUse matcher; existing installs upgrade in place (the previous matcher joins the legacy set).
  • enrichGortexRead nudges a full-body read on a source file toward search_text (locate sites, no bodies) or compress_bodies:true (+keep). Soft additionalContext by default; hard deny behind GORTEX_HOOK_FORCE_COMPRESS, mirroring GORTEX_HOOK_BLOCK_EDIT. The decision is made purely from the tool input — no daemon round-trip — so the hook stays sub-millisecond. Already-economical calls (compressed, size-capped, non-source) pass silently. The nudge also rides along with the permissive-mode auto-approve as soft context.
  • Derive the marketplace plugin's hooks.json matcher from the constant so it can't drift from gortex init.

Adds bench/issue40_context_repro.py, which drives the live daemon to measure the full-vs-compressed read gap (~2x)

bench/issue40_context_repro.py — drives the real tools through the running daemon (gortex mcp --proxy) and measures actual wire bytes for the three access patterns.

python3 bench/issue40_context_repro.py

What it shows (4 mid-size Go files ≈ reporter's 16–20KB C++ files)

┌────────────────────────────────┬──────────────┬────────────────────────────────────────────────────────────────────┐
│            Pattern             │     Cost     │                                Note                                │
├────────────────────────────────┼──────────────┼────────────────────────────────────────────────────────────────────┤
│ read_file (full)               │ ~17.3k tok   │ the "eats context" path                                            │
├────────────────────────────────┼──────────────┼────────────────────────────────────────────────────────────────────┤
│ read_file compress_bodies:true │ ~8.6k tok    │ 50% less aggregate, up to 75% per file — same signatures/structure │
├────────────────────────────────┼──────────────┼────────────────────────────────────────────────────────────────────┤
│ search_text (locate sites)     │ ~41 tok/site │ line-precise file:line, zero bodies read                           │
└────────────────────────────────┴──────────────┴────────────────────────────────────────────────────────────────────┘

Issue #40: Claude Code burns context reading whole files via Gortex's
own read tools. The PreToolUse hook redirects native Read/Grep/Glob to
graph tools, but its matcher (Read|Grep|Glob|Task|Bash|Edit|Write) never
matched mcp__gortex__read_file — once the agent was inside a Gortex read
tool, nothing guarded how it was called, and read_file defaults to
compress_bodies:false. So the expensive path was the default path with
no forcing function.

Close the gap:
- Add mcp__gortex__read_file and mcp__gortex__get_editing_context to the
  PreToolUse matcher; existing installs upgrade in place (the previous
  matcher joins the legacy set).
- enrichGortexRead nudges a full-body read on a source file toward
  search_text (locate sites, no bodies) or compress_bodies:true (+keep).
  Soft additionalContext by default; hard deny behind
  GORTEX_HOOK_FORCE_COMPRESS, mirroring GORTEX_HOOK_BLOCK_EDIT. The
  decision is made purely from the tool input — no daemon round-trip —
  so the hook stays sub-millisecond. Already-economical calls
  (compressed, size-capped, non-source) pass silently. The nudge also
  rides along with the permissive-mode auto-approve as soft context.
- Derive the marketplace plugin's hooks.json matcher from the constant
  so it can't drift from gortex init.

Adds bench/issue40_context_repro.py, which drives the live daemon to
measure the full-vs-compressed read gap (~2x) that motivates the fix.
@zzet zzet added the bug Something isn't working label Jun 2, 2026
@zzet zzet merged commit bf9b456 into main Jun 3, 2026
10 checks passed
@zzet zzet deleted the fix/issue-40-context-read-nudge branch June 3, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant