perf(mcp): slim SERVER_INSTRUCTIONS ~35%; pin marker literals + size budget with a test - #1529
Open
zyrill wants to merge 1 commit into
Open
perf(mcp): slim SERVER_INSTRUCTIONS ~35%; pin marker literals + size budget with a test#1529zyrill wants to merge 1 commit into
zyrill wants to merge 1 commit into
Conversation
…rkers + size budget with a test The initialize instructions are injected into the system prompt of EVERY session of EVERY MCP client — the file's own header asks to keep them tight, but the explore-over-Read directive was stated ~6 times and the tool's return-shape description ~4 times. This rewrite removes only repetition: - every operative rule survives (explore-first, flow-by-endpoints, treat-returned-source-as-Read, all three staleness banners with their exact literal wording, the already-sent-dedup pointer semantics, the not-indexed/stop + 'codegraph init' etiquette, best-effort resolution, no-correctness-validation); - the four literal marker strings agents pattern-match on are now pinned by __tests__/server-instructions.test.ts, alongside a 4000-char size budget so the block cannot silently re-inflate, and a guard that no hidden tool name (anything beyond codegraph_explore) leaks into the text. Co-Authored-By: Claude Fable 5 <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.
Why
The
initializeinstructions land in the agent's system prompt on every session of every MCP client — the header ofserver-instructions.tsitself says "Keep it tight. The agent reads this every session — long instructions burn tokens." Measured on v1.5.0,SERVER_INSTRUCTIONSis 5,890 chars (~1.5k tokens), and much of that is repetition: the explore-over-Read directive appears ~6 times and the return-shape description ("verbatim line-numbered source + call path + blast radius") ~4 times.For context on how this compounds: we run codegraph in a multi-agent repo where every session, subagent, and cache rewrite re-pays the block — it was the single largest non-configurable item left after dieting everything else in our always-on context.
What
Rewrote the block to 3,814 chars (−35%), removing only repetition — every operative rule survives:
mutateElement renderSceneexample), treat-returned-source-as-Read, overloaded-name behaviorcodegraph initetiquette (mention, don't run), best-effort cross-file resolution, no-correctness-validationSERVER_INSTRUCTIONS_NO_ROOT_INDEXis untouched (already tight).Guarding against re-inflation
New
__tests__/server-instructions.test.ts(matches the existing root-__tests__/vitest layout):codegraph_explore) leaks into the text, per the header's own ruleSERVER_INSTRUCTIONS(1,500 for the no-root variant) — the same ratchet pattern that keeps our own agent contract from regrowingTesting
npx vitest run __tests__/server-instructions.test.ts— 3/3 (the size case fails on v1.5.0's text, passes after the rewrite)npm run build— clean🤖 Generated with Claude Code