Skip to content

feat(agents): deduplicate CLAUDE.md and AGENTS.md in agent context#1189

Merged
aaight merged 1 commit intodevfrom
feature/deduplicate-context-files
Apr 24, 2026
Merged

feat(agents): deduplicate CLAUDE.md and AGENTS.md in agent context#1189
aaight merged 1 commit intodevfrom
feature/deduplicate-context-files

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Apr 24, 2026

Summary

  • Deduplicates CLAUDE.md and AGENTS.md in the agent context — when both files exist and contain identical content (same bytes, or one is a symlink of the other), only injects the content once into the agent prompt
  • Detection strategy — symlink fast-path via lstatSync/readlinkSync, falling back to trimmed-content string comparison for copy-paste duplicates or when filesystem calls fail
  • CLAUDE.md kept as canonical — when deduplicating, the CLAUDE.md entry is retained (it's the more widely referenced name across prompts/docs)
  • Single production file changed — only src/agents/utils/setup.ts (readContextFiles + new areDuplicateContextFiles helper)

Card: https://trello.com/c/H7YTaJag/628-right-now-we-put-agentsmd-and-claudemd-into-the-context-sometimes-they-have-exact-same-contents-checksum-wise-sometimes-one-is-a

Test plan

  • New unit tests in tests/unit/agents/utils/setup.test.ts covering:
    • Identical content deduplication keeps CLAUDE.md (content match)
    • Different content → both files retained
    • AGENTS.md is a symlink to CLAUDE.md → deduplicated
    • CLAUDE.md is a symlink to AGENTS.md → deduplicated
    • lstat throws → falls back to content comparison correctly
    • Only 1 file exists → no dedup attempt (lstatSync never called)
  • All 31 tests in setup.test.ts pass (25 original + 6 new)
  • All 715 agent unit tests pass
  • Lint passes (biome check: 0 issues)
  • Type check passes (tsc --noEmit: 0 errors)

🤖 Generated with Claude Code

🕵️ claude-code · claude-sonnet-4-6 · run details

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/agents/utils/setup.ts 90.90% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

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

LGTM — clean, focused change. The dedup logic is sound: symlink fast-path via lstatSync/readlinkSync correctly avoids following symlinks, content equality fallback handles copy-paste duplicates and permission errors gracefully. The results.length === 2 guard ensures no unnecessary filesystem calls when only one file exists. Existing tests remain correct because unmocked lstatSync throws → caught → falls to content comparison → different content → both files kept. Six new tests provide solid coverage of the key scenarios (content match, content mismatch, symlink in both directions, lstat failure fallback, single-file short-circuit).

🕵️ claude-code · claude-opus-4-6 · run details

@aaight aaight merged commit 54c1406 into dev Apr 24, 2026
9 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