Skip to content

fix(context-budget): stop double-counting home skills and CLAUDE.md - #911

Merged
iamtoruk merged 1 commit into
getagentseal:mainfrom
ozymandiashh:fix/swarm-context-budget
Aug 4, 2026
Merged

fix(context-budget): stop double-counting home skills and CLAUDE.md#911
iamtoruk merged 1 commit into
getagentseal:mainfrom
ozymandiashh:fix/swarm-context-budget

Conversation

@ozymandiashh

Copy link
Copy Markdown
Collaborator

Context-budget accuracy fix from the systematic audit (find -> verify -> adversarial -> manual confirmation + mutation check).

When the project directory IS the home directory, countSkills built [~/.claude/skills, <project>/.claude/skills] - the same path twice - and counted every skill twice; scanMemoryFiles likewise read ~/.claude/CLAUDE.md twice. 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 --noEmit clean.

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 iamtoruk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@iamtoruk
iamtoruk merged commit 9372fb5 into getagentseal:main Aug 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants