Skip to content

fix(prompt-hook): cap the injection under Claude Code's 10k inline hook-output limit - #1695

Open
bompus wants to merge 1 commit into
colbymchenry:mainfrom
bompus:fix/prompt-hook-cap-under-claude-inline-limit
Open

fix(prompt-hook): cap the injection under Claude Code's 10k inline hook-output limit#1695
bompus wants to merge 1 commit into
colbymchenry:mainfrom
bompus:fix/prompt-hook-cap-under-claude-inline-limit

Conversation

@bompus

@bompus bompus commented Sep 4, 2026

Copy link
Copy Markdown

Fixes #1694.

codegraph prompt-hook capped its <codegraph_context> injection at 16,000 characters. Claude Code shows hook stdout inline only up to 10,000 characters; above that it persists the output to tool-results/hook-<id>-stdout.txt and the model sees a 2 KB preview plus the path. So on any repo where explore filled the cap, the hook delivered a file reference instead of the context (measured in #1694: 9,871 characters inline, 10,031 persisted, on Claude Code 2.1.261).

Change

  • MAX 16000 → 9000 in src/bin/codegraph.ts, with a comment naming the host limit. 9,000 leaves ~1,000 characters for the <codegraph_context> wrapper and the projectPath nudge lines that are appended after the cap is applied.
  • CHANGELOG entry under Unreleased › Fixes.

The existing "…(truncated; call codegraph_explore for the rest)" notice is unchanged, so a capped payload still tells the model where the rest is. The blast-radius list leads the explore output, so the part that survives the cap is the part the model acts on.

Not in this PR

An env var to set the cap per host. Happy to add one if you want other hosts to be able to raise it.

@danusha2345

Copy link
Copy Markdown
Contributor

Confirmed the symptom and the fix on a live setup. The installed prompt-hook (1.6.0-era build, 787-file TS repo) returned 16,360 characters on ordinary prompts — every session got the persisted-file preview, exactly as #1694 describes. With this change merged into a local integration build of current main the same prompt returns 9,348 characters and lands inline. Full suite 252 files / 4349 passed with it in.

@bompus

bompus commented Sep 6, 2026

Copy link
Copy Markdown
Author

Measured this one end to end on a real repo (vite, indexed at 9,354 nodes / 27,778 edges) rather than a fixture. It holds up.

The premise is documented, not inferred. From the Claude Code hooks reference:

Hook output strings, including additionalContext, systemMessage, and plain stdout, are capped at 10,000 characters. Output that exceeds this limit is saved to a file and replaced with a preview and file path.

So the old MAX = 16000 was above the cap by design, and every prompt that filled the budget got the file-and-preview treatment — which is exactly the failure mode where the model sees a 2 KB stub instead of the context.

Measurement. I drove codegraph prompt-hook directly (JSON {prompt, cwd} on stdin) against vite with five structural prompts, and counted stdout characters:

arm stdout chars over the 10,000 cap
base (MAX = 16000) 16,223 on all five prompts 5 / 5
this PR (MAX = 9000) 9,223 on all five prompts 0 / 5

Both arms are pinned at the ceiling on every prompt, which is the point — on a repo this size the budget is always the binding constraint, so the old value wasn't an occasional overflow, it was overflowing every time.

The 223-char delta over MAX in both arms is the wrapper plus the projectPath nudge lines, and it's constant. That leaves 777 characters of headroom under the cap, which is enough room for the wrapper to grow without another silent truncation.

No concerns. LGTM.

bompus added a commit to bompus/codegraph that referenced this pull request Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants