Skip to content

feat(core): auto-target CLAUDE.md for Claude Code, AGENTS.md otherwise#1163

Merged
BYK merged 2 commits into
mainfrom
feat/claude-md-auto-target
Jul 4, 2026
Merged

feat(core): auto-target CLAUDE.md for Claude Code, AGENTS.md otherwise#1163
BYK merged 2 commits into
mainfrom
feat/claude-md-auto-target

Conversation

@BYK

@BYK BYK commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Problem

Lore always wrote its managed knowledge section (and the .lore.md pointer) to AGENTS.md. But Claude Code's canonical memory file is CLAUDE.md — AGENTS.md support in the CC binary is negligible (215 CLAUDE.md refs vs 2 for AGENTS.md; most "AGENTS" tokens are the subagents feature). So Claude Code users didn't reliably pick up the pointer.

Fix

Default agentsFile.path to a new "auto" sentinel that resolves the host filename per agent:

  • Claude Code sessions (Tier-1 header x-claude-code-session-id) → CLAUDE.md
  • every other agent → AGENTS.md
  • an explicit agentsFile.path (e.g. "AGENTS.md", "CLAUDE.md", ".cursor/rules/lore.md") always overrides

The 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, and lore data export — resolve "auto" via existing-file detection (prefer an existing CLAUDE.md, else AGENTS.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: default agentsFile.path is now "auto"; explicit paths preserved.
  • agents-file.test.ts: resolveAgentsFileName matrix (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 (forcing isClaudeCode=false or removing the strip both fail the test).

No pointer-text change needed (it already references .lore.md generically). Typecheck + Biome clean; full core (2529) and gateway suites green except the pre-existing bundle-exports tests (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.

BYK added 2 commits July 4, 2026 01:24
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.
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 93.02%. Project has 6488 uncovered lines.
✅ Project coverage is 71.33%. Comparing base (base) to head (head).

Files with missing lines (3)
File Patch % Lines
packages/gateway/src/cli/data.ts 92.86% ⚠️ 1 Missing and 4 partials
packages/gateway/src/idle.ts 88.89% ⚠️ 1 Missing and 2 partials
packages/gateway/src/pipeline.ts 90.91% ⚠️ 1 Missing and 1 partials
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        +6

Generated by Codecov Action

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-04 08:30 UTC

@BYK BYK merged commit b186e57 into main Jul 4, 2026
23 checks passed
@BYK BYK deleted the feat/claude-md-auto-target branch July 4, 2026 08:30
@craft-deployer craft-deployer Bot mentioned this pull request Jul 4, 2026
7 tasks
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.

1 participant