SessionStart hook: make the ~10000-char additionalContext per-value cap configurable

Resolved 💬 2 comments Opened Jun 2, 2026 by andrewgazelka Closed Jun 5, 2026

Ask: expose a knob (env var or settings key) to raise/remove the per-value char cap on a SessionStart hook's hookSpecificOutput.additionalContext, or raise the default.

A single additionalContext value over ~10,000 chars is silently replaced with a short preview (the full text is saved to a file), so the model never sees the rest. There's no env/settings override for it, unlike the other output caps you already expose (BASH_MAX_OUTPUT_LENGTH, TASK_MAX_OUTPUT_LENGTH, MAX_MCP_OUTPUT_TOKENS).

Why it matters: we render a repo's always-on agent instructions (~36KB) live from a SessionStart hook. To fit it, we split into 5 sub-10k chunks and register one hook per chunk in settings.json, relying on the values being concatenated. If the doc grows past the registered chunk count, the tail is dropped with no signal — a silent context-truncation footgun we now guard against with a build-time check. A single configurable cap would remove the whole dance.

Repro (verified on 2.1.159):

mkdir -p /tmp/p/.claude/hooks && cd /tmp/p
cat > .claude/hooks/big.sh <<'H'
#!/usr/bin/env bash
filler=$(head -c 28000 </dev/zero | tr '\0' x)
printf '%s' "BEGIN ${filler} secret-token=ZZTOP-ENDMARKER END" \
  | jq -Rs '{hookSpecificOutput:{hookEventName:"SessionStart",additionalContext:.}}'
H
chmod +x .claude/hooks/big.sh
printf '%s' '{"hooks":{"SessionStart":[{"hooks":[{"type":"command","command":"$CLAUDE_PROJECT_DIR/.claude/hooks/big.sh"}]}]}}' > .claude/settings.json
claude -p "Without tools, what is secret-token in your context? Token only, or NONE." --allowedTools ""
# -> NONE (the marker at ~char 28000 was truncated to a preview)

Suggested fix: honor an env var (e.g. MAX_HOOK_ADDITIONAL_CONTEXT_CHARS) or a settings key, mirroring the existing output-cap knobs; default unchanged.

Filed with Claude Code (Opus 4.8).

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗