feat(core): auto-target CLAUDE.md for Claude Code, AGENTS.md otherwise#1163
Merged
Conversation
The managed knowledge section (and .lore.md pointer) was always written to AGENTS.md, but Claude Code's canonical memory file is CLAUDE.md. Default `agentsFile.path` to a new "auto" sentinel that resolves per agent: - Claude Code sessions (Tier-1 header x-claude-code-session-id) -> CLAUDE.md - every other agent -> AGENTS.md - an explicit `agentsFile.path` always overrides The idle exporter is the authoritative writer and feeds the session's client identity. Hint-less read paths (startup import, file watcher, `lore data export`) resolve "auto" via existing-file detection, and the watcher watches both candidates. On a target flip (AGENTS.md <-> CLAUDE.md) the stale managed section is stripped from the other candidate, preserving any hand-written content. Explicitly configured paths never have a counterpart touched. resolveAgentsFileName/otherAgentsFileCandidate/AGENTS_FILE_CANDIDATES added to @loreai/core; unit-tested plus an end-to-end idle-export flip test.
Contributor
Codecov Results 📊✅ Patch coverage is 93.02%. Project has 6488 uncovered lines. Files with missing lines (3)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 71.31% 71.33% +0.02%
==========================================
Files 135 135 —
Lines 22602 22632 +30
Branches 15945 15975 +30
==========================================
+ Hits 16117 16144 +27
- Misses 6485 6488 +3
- Partials 1643 1649 +6Generated by Codecov Action |
Contributor
|
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.
Problem
Lore always wrote its managed knowledge section (and the
.lore.mdpointer) to AGENTS.md. But Claude Code's canonical memory file is CLAUDE.md — AGENTS.md support in the CC binary is negligible (215CLAUDE.mdrefs vs 2 forAGENTS.md; most "AGENTS" tokens are the subagents feature). So Claude Code users didn't reliably pick up the pointer.Fix
Default
agentsFile.pathto a new"auto"sentinel that resolves the host filename per agent:x-claude-code-session-id) → CLAUDE.mdagentsFile.path(e.g."AGENTS.md","CLAUDE.md",".cursor/rules/lore.md") always overridesThe idle exporter is the authoritative writer and feeds the session's client identity (
state.headerName). Hint-less read paths — startup import (tryImportKnowledge), the file watcher, andlore data export— resolve"auto"via existing-file detection (prefer an existingCLAUDE.md, elseAGENTS.md); the watcher watches both candidates under"auto".On a target flip (AGENTS.md ⇄ CLAUDE.md), the stale managed section is stripped from the other candidate (via
removeLoreSectionFromFile), preserving any hand-written content. A file the user configured explicitly never has a counterpart touched.New core API:
resolveAgentsFileName,otherAgentsFileCandidate,AGENTS_FILE_CANDIDATES,AUTO_AGENTS_FILE.Tests
config.test.ts: defaultagentsFile.pathis now"auto"; explicit paths preserved.agents-file.test.ts:resolveAgentsFileNamematrix (explicit verbatim; auto+CC→CLAUDE.md; auto+non-CC→AGENTS.md; hint-less existing-file detection; hint beats detection) +otherAgentsFileCandidate.idle-work.test.ts: end-to-end flip — a non-CC session writes AGENTS.md, then a Claude Code session writes CLAUDE.md and strips the stale AGENTS.md section while preserving hand-written content. Mutation-verified (forcingisClaudeCode=falseor removing the strip both fail the test).No pointer-text change needed (it already references
.lore.mdgenerically). Typecheck + Biome clean; full core (2529) and gateway suites green except the pre-existingbundle-exportstests (require a built Bun bundle).Note
Intended migration: existing Claude Code users on the default move from AGENTS.md → CLAUDE.md on the next idle export, with the old AGENTS.md section removed. Mixed-agent projects (CC + another agent on the same repo) should pin an explicit
agentsFile.path.