fix(context-budget): stop double-counting home skills and CLAUDE.md - #911
Merged
Merged
Conversation
When the project directory IS the home directory, countSkills pushed both ~/.claude/skills and <project>/.claude/skills - the same path - and counted every skill twice, and scanMemoryFiles read ~/.claude/CLAUDE.md twice, inflating the context-budget estimate. Dedupe both by resolved path. Mutation-checked: a single home skill counts 2 before the fix, 1 after.
iamtoruk
approved these changes
Aug 4, 2026
iamtoruk
left a comment
Member
There was a problem hiding this comment.
Reviewed on the merged tree. Correct accuracy fix: when the project dir is the home dir, countSkills built the same skills path twice and scanMemoryFiles read ~/.claude/CLAUDE.md twice, inflating the context-budget token estimate. Both now dedupe by path (path.join already normalizes trailing slashes and .. segments, so the identical strings collapse). Dedup fires only on identical paths, so it can only remove a double-count, never under-count a genuinely distinct project skill. Mutation-checked: reverting the skills dedup makes the one-home-skill case count 2 instead of 1; the sibling test confirms a distinct project skill still counts separately. tsc clean. Good to merge.
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.
Context-budget accuracy fix from the systematic audit (find -> verify -> adversarial -> manual confirmation + mutation check).
When the project directory IS the home directory,
countSkillsbuilt[~/.claude/skills, <project>/.claude/skills]- the same path twice - and counted every skill twice;scanMemoryFileslikewise read~/.claude/CLAUDE.mdtwice. The context-budget token estimate (skills + memory) was inflated for anyone running from their home dir. Both are now deduped by resolved path.Mutation-checked: a single home skill counts 2 before the fix and 1 after; the second test confirms a genuinely distinct project skill still counts separately.
tsc --noEmitclean.