Add size limits to prevent context overflow in large repos #19
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.
Summary
get_structureenforce 60KB max output (~15k tokens, <10% of context)Problem
Large repos (10k+ files like Rails monoliths) were outputting 1.3MB+ of tree structure on session start, consuming 250%+ of Claude Code's context window before any conversation even started.
Root Cause: Hook Output Goes to "Messages"
The critical insight is that hook output gets injected into the "Messages" portion of Claude's context, not into system prompt or tools. This means:
/cleardoesn't help because hooks re-run on session startWhy This Matters for Hook Architecture
Hooks need to be context-aware. A hook that's helpful for a 500-file project becomes destructive for a 10k-file project. Current hooks assume unlimited output is fine - it's not.
Principles for future hook design:
The Quick Fix (This PR)
get_structuretoolFuture Refactoring Ideas
.codemap/config.jsonto tune hook behaviorTest Results
codemapandcodemap-mcprebuild successfullyFiles Changed
cmd/hooks.go: Adaptive depth + size limit for session-start hookmcp/main.go: Size limit forget_structureMCP tool🤖 Generated with Claude Code