From ec8329abc98f0ba03b54d40f9f461244fb974d57 Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Wed, 2 Dec 2026 21:59:13 +0530 Subject: [PATCH 1/8] Setup names a home folder spelled another way as the checkout's root does agent-instructions compared paths through the JavaScript realpathSync, which keeps a Windows 8.3 name and letter case, while the checkout root comes through realPath. A configuration folder or `~/` import spelled another way then missed, and setup wrote a CLAUDE.md holding only `@AGENTS.md`. Every comparison now goes through realPath, and the setup tests' scratch folders take its spelling. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lareb Zafar --- .../.claude-plugin/plugin.json | 2 +- .../lib/agent-instructions.mjs | 21 +++---- .../tests/agent-instructions.test.mjs | 55 +++++++++++++++---- .../codex-plugin/.codex-plugin/plugin.json | 2 +- .../codex-plugin/lib/agent-instructions.mjs | 21 +++---- 5 files changed, 60 insertions(+), 41 deletions(-) diff --git a/integrations/claude-code-plugin/.claude-plugin/plugin.json b/integrations/claude-code-plugin/.claude-plugin/plugin.json index f882a34cba..5e2cf2fb0e 100644 --- a/integrations/claude-code-plugin/.claude-plugin/plugin.json +++ b/integrations/claude-code-plugin/.claude-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "loom", "displayName": "ClickHouse Loom", - "version": "1.2.158", + "version": "1.2.162", "description": "Shared long-term memory and code intelligence for Claude Code, self-hosted on ClickHouse. MCP tools to save and recall decisions, preferences and corrections across sessions and teammates; lifecycle hooks that capture each session with no model call; a code index that answers where-is, who-calls and blast-radius questions with line-accurate units instead of whole-file reads.", "author": { "name": "ClickHouse" diff --git a/integrations/claude-code-plugin/lib/agent-instructions.mjs b/integrations/claude-code-plugin/lib/agent-instructions.mjs index 38f1c7ea21..83b6408f47 100644 --- a/integrations/claude-code-plugin/lib/agent-instructions.mjs +++ b/integrations/claude-code-plugin/lib/agent-instructions.mjs @@ -11,11 +11,11 @@ // which call reads several definitions at once, which tools answer for a // definition's callers and tests, where the index's answer to a prompt is // when the prompt hook brings one, that results need checking). -import { existsSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs"; +import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { homedir } from "node:os"; import { dirname, join, relative, resolve, sep } from "node:path"; -import { planeEnabled, pluginMode, promptPointersSetting } from "./loom-client.mjs"; +import { planeEnabled, pluginMode, promptPointersSetting, realPath } from "./loom-client.mjs"; import { cachedUnindexed } from "./repo-scope.mjs"; import { readJsonFile, tmpStatePath, writeJsonFile } from "./tmp-state.mjs"; @@ -159,15 +159,6 @@ function agentsFile(root) { return files.find(holdsBlock) || files[0]; } -/** `file` with its symbolic links resolved, as given where there is none. */ -function real(file) { - try { - return realpathSync(file); - } catch { - return file; - } -} - /** Whether a line of `file` imports `target`: `@` and the path, from the * file's folder, from the home folder (`~/`) or whole. A line inside a * fenced code block is none: Claude Code evaluates no import there. */ @@ -182,7 +173,9 @@ function imports(file, target) { if (mark && !fence) fence = mark; else if (mark?.startsWith(fence)) fence = ""; const to = !mark && !fence && /^@(\S+)$/.exec(text)?.[1]; - return Boolean(to) && real(resolve(dirname(file), to.replace(/^~(?=\/)/, homedir()))) === real(resolve(target)); + return ( + Boolean(to) && realPath(resolve(dirname(file), to.replace(/^~(?=\/)/, homedir()))) === realPath(resolve(target)) + ); }); } @@ -204,8 +197,8 @@ function agentsUnreadFor(root, agents) { dir = dirname(dir); files.push(...names.map((name) => join(dir, name))); } - const user = real(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); - const own = files.filter((file) => hasText(file) && real(file) !== user); + const user = realPath(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); + const own = files.filter((file) => hasText(file) && realPath(file) !== user); return own.some((file) => imports(file, agents)) ? undefined : own[0]; } diff --git a/integrations/claude-code-plugin/tests/agent-instructions.test.mjs b/integrations/claude-code-plugin/tests/agent-instructions.test.mjs index 5e6947f5ae..23d75197da 100644 --- a/integrations/claude-code-plugin/tests/agent-instructions.test.mjs +++ b/integrations/claude-code-plugin/tests/agent-instructions.test.mjs @@ -31,10 +31,9 @@ import { hostEnv } from "./host-env.mjs"; process.env.LOOM_HOOK_NO_MAIN = "1"; const { clientStatus } = await import("../bin/loom-client-status.mjs"); -const scratch = () => fs.mkdtempSync(path.join(os.tmpdir(), "loom-instructions-")); -// A scratch folder spelled as setup names a checkout (`realPath`, through `gitToplevel`), which -// expands a Windows 8.3 name such as RUNNER~1 that the temporary folder can carry. -const realScratch = () => realPath(scratch()); +// Spelled as setup names a checkout (`realPath`, through `gitToplevel`), which expands a +// Windows 8.3 name such as RUNNER~1 that the temporary folder can carry. +const scratch = () => realPath(fs.mkdtempSync(path.join(os.tmpdir(), "loom-instructions-"))); // Setup reads the folders above a checkout for a CLAUDE.md of the person's // own, and the scratch checkouts are under the temporary folder: a file with // text outside comments above it would change the layouts below, so it is @@ -785,7 +784,7 @@ const ASKED = { serverUrl: "http://localhost:7777", token: "" }; /** A checkout a session's lookup found in no index (`indexed` false), or * found its own repository indexed. */ function lookedUp(indexed, tmp = scratch()) { - const root = realScratch(); + const root = scratch(); execFileSync("git", ["init", "-q"], { cwd: root }); writeCache(root, { ts: Date.now(), indexed, own: indexed }, tmp, ASKED); return { root, tmp }; @@ -834,7 +833,7 @@ function setup(cwd, args = [], env = {}, home = scratch()) { } test("loom-setup: writes at the checkout's root, is idempotent, updates and removes", () => { - const root = realScratch(); + const root = scratch(); execFileSync("git", ["init", "-q"], { cwd: root }); fs.mkdirSync(path.join(root, "src")); const file = path.join(root, "CLAUDE.md"); @@ -861,7 +860,7 @@ test("loom-setup: writes at the checkout's root, is idempotent, updates and remo }); test("loom-setup in a repository with AGENTS.md and no CLAUDE.md writes there, and undoes a CLAUDE.md that held only the block", () => { - const root = realScratch(); + const root = scratch(); execFileSync("git", ["init", "-q"], { cwd: root }); const [agents, claude] = ["AGENTS.md", "CLAUDE.md"].map((f) => path.join(root, f)); fs.writeFileSync(agents, RULES); @@ -918,7 +917,7 @@ test("loom-setup in a repository with AGENTS.md and no CLAUDE.md writes there, a }); test("a CLAUDE.md in Claude Code's own configuration folder above the checkout leaves AGENTS.md read: setup adds no CLAUDE.md", () => { - const home = realScratch(); + const home = scratch(); const root = path.join(home, "work", "checkout"); const [agents, claude, mine] = [ path.join(root, "AGENTS.md"), @@ -942,8 +941,42 @@ test("a CLAUDE.md in Claude Code's own configuration folder above the checkout l assert.equal(fs.readFileSync(claude, "utf8"), "@AGENTS.md\n"); }); +test("a home folder spelled another way than the checkout's root still names the same files", (t) => { + const home = scratch(); + // Another spelling of the same folder, as an 8.3 name is on Windows: letter case, where the file + // system ignores it (macOS, Windows). + const other = home.toUpperCase(); + if (other === home || !fs.existsSync(other)) return t.skip("the file system tells letter case apart here"); + const root = path.join(home, "work", "checkout"); + const [agents, claude, mine] = [ + path.join(root, "AGENTS.md"), + path.join(root, "CLAUDE.md"), + path.join(home, ".claude", "CLAUDE.md"), + ]; + for (const dir of [root, path.dirname(mine)]) fs.mkdirSync(dir, { recursive: true }); + execFileSync("git", ["init", "-q"], { cwd: root }); + fs.writeFileSync(mine, "Mine.\n"); + // The configuration folder's CLAUDE.md, through HOME and through CLAUDE_CONFIG_DIR. + for (const [env, at] of [ + [{}, other], + [{ CLAUDE_CONFIG_DIR: path.join(other, ".claude") }, scratch()], + ]) { + fs.writeFileSync(agents, RULES); + const wrote = setup(root, [], { LOOM_MODE: "code", ...env }, at); + assert.equal(wrote.stdout, `loom: wrote the Loom block to ${agents}\n`, wrote.stderr); + assert.equal(fs.existsSync(claude), false); + } + // A CLAUDE.md above the checkout that imports AGENTS.md from the home folder. + fs.rmSync(path.dirname(mine), { recursive: true }); + fs.writeFileSync(path.join(home, "work", "CLAUDE.md"), "@~/work/checkout/AGENTS.md\n"); + fs.writeFileSync(agents, RULES); + const read = setup(root, [], { LOOM_MODE: "code" }, other); + assert.equal(read.stdout, `loom: wrote the Loom block to ${agents}\n`, read.stderr); + assert.equal(fs.existsSync(claude), false); +}); + test("loom-setup writes nothing where no code index answers, and still removes there", () => { - const root = realScratch(); + const root = scratch(); execFileSync("git", ["init", "-q"], { cwd: root }); const file = path.join(root, "CLAUDE.md"); const home = scratch(); @@ -1019,7 +1052,7 @@ test("loom-setup under auto writes the pointers block where the last lookup foun }); test("loom-setup writes the block for the prompt's pointers as the last session saved them, else as the environment says", () => { - const root = realScratch(); + const root = scratch(); execFileSync("git", ["init", "-q"], { cwd: root }); const file = path.join(root, "CLAUDE.md"); const written = () => fs.readFileSync(file, "utf8"); @@ -1062,7 +1095,7 @@ test("the integration page shows both blocks setup writes", () => { }); test("loom-setup under the Codex plugin writes AGENTS.md", () => { - const root = realScratch(); + const root = scratch(); execFileSync("git", ["init", "-q"], { cwd: root }); const script = fileURLToPath(new URL("../../codex-plugin/bin/loom-setup.mjs", import.meta.url)); const home = scratch(); diff --git a/integrations/codex-plugin/.codex-plugin/plugin.json b/integrations/codex-plugin/.codex-plugin/plugin.json index 33322e89d6..fe5001afb0 100644 --- a/integrations/codex-plugin/.codex-plugin/plugin.json +++ b/integrations/codex-plugin/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "loom", - "version": "1.2.158", + "version": "1.2.162", "description": "Shared long-term memory and code intelligence for Codex, self-hosted on ClickHouse. MCP tools to save and recall decisions, preferences and corrections across sessions and teammates; lifecycle hooks that capture each session with no model call; a code index that answers where-is, who-calls and blast-radius questions with line-accurate units instead of whole-file reads.", "author": { "name": "ClickHouse" diff --git a/integrations/codex-plugin/lib/agent-instructions.mjs b/integrations/codex-plugin/lib/agent-instructions.mjs index 38f1c7ea21..83b6408f47 100644 --- a/integrations/codex-plugin/lib/agent-instructions.mjs +++ b/integrations/codex-plugin/lib/agent-instructions.mjs @@ -11,11 +11,11 @@ // which call reads several definitions at once, which tools answer for a // definition's callers and tests, where the index's answer to a prompt is // when the prompt hook brings one, that results need checking). -import { existsSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs"; +import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { homedir } from "node:os"; import { dirname, join, relative, resolve, sep } from "node:path"; -import { planeEnabled, pluginMode, promptPointersSetting } from "./loom-client.mjs"; +import { planeEnabled, pluginMode, promptPointersSetting, realPath } from "./loom-client.mjs"; import { cachedUnindexed } from "./repo-scope.mjs"; import { readJsonFile, tmpStatePath, writeJsonFile } from "./tmp-state.mjs"; @@ -159,15 +159,6 @@ function agentsFile(root) { return files.find(holdsBlock) || files[0]; } -/** `file` with its symbolic links resolved, as given where there is none. */ -function real(file) { - try { - return realpathSync(file); - } catch { - return file; - } -} - /** Whether a line of `file` imports `target`: `@` and the path, from the * file's folder, from the home folder (`~/`) or whole. A line inside a * fenced code block is none: Claude Code evaluates no import there. */ @@ -182,7 +173,9 @@ function imports(file, target) { if (mark && !fence) fence = mark; else if (mark?.startsWith(fence)) fence = ""; const to = !mark && !fence && /^@(\S+)$/.exec(text)?.[1]; - return Boolean(to) && real(resolve(dirname(file), to.replace(/^~(?=\/)/, homedir()))) === real(resolve(target)); + return ( + Boolean(to) && realPath(resolve(dirname(file), to.replace(/^~(?=\/)/, homedir()))) === realPath(resolve(target)) + ); }); } @@ -204,8 +197,8 @@ function agentsUnreadFor(root, agents) { dir = dirname(dir); files.push(...names.map((name) => join(dir, name))); } - const user = real(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); - const own = files.filter((file) => hasText(file) && real(file) !== user); + const user = realPath(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); + const own = files.filter((file) => hasText(file) && realPath(file) !== user); return own.some((file) => imports(file, agents)) ? undefined : own[0]; } From e4e8a89c65a0a4035b1b6a9d68367ad2891b804f Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Wed, 2 Dec 2026 22:18:10 +0530 Subject: [PATCH 2/8] The home-folder spelling test runs on every platform, and imports() names its target once The test now runs setup with the home folder as created and with its upper- and lower-cased spellings where the file system holds them, so the ~/ import case runs on Linux too and a lowercase drive letter is covered on Windows. The check for a CLAUDE.md above the temporary folder walks the spelling the scratch folders use. imports() resolves its target before reading the lines. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lareb Zafar --- .../lib/agent-instructions.mjs | 5 +- .../tests/agent-instructions.test.mjs | 62 ++++++++++--------- .../codex-plugin/lib/agent-instructions.mjs | 5 +- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/integrations/claude-code-plugin/lib/agent-instructions.mjs b/integrations/claude-code-plugin/lib/agent-instructions.mjs index 83b6408f47..a0bdb6bb32 100644 --- a/integrations/claude-code-plugin/lib/agent-instructions.mjs +++ b/integrations/claude-code-plugin/lib/agent-instructions.mjs @@ -163,6 +163,7 @@ function agentsFile(root) { * file's folder, from the home folder (`~/`) or whole. A line inside a * fenced code block is none: Claude Code evaluates no import there. */ function imports(file, target) { + const want = realPath(target); let fence = ""; return read(file) .split(/\r?\n/) @@ -173,9 +174,7 @@ function imports(file, target) { if (mark && !fence) fence = mark; else if (mark?.startsWith(fence)) fence = ""; const to = !mark && !fence && /^@(\S+)$/.exec(text)?.[1]; - return ( - Boolean(to) && realPath(resolve(dirname(file), to.replace(/^~(?=\/)/, homedir()))) === realPath(resolve(target)) - ); + return Boolean(to) && realPath(resolve(dirname(file), to.replace(/^~(?=\/)/, homedir()))) === want; }); } diff --git a/integrations/claude-code-plugin/tests/agent-instructions.test.mjs b/integrations/claude-code-plugin/tests/agent-instructions.test.mjs index 23d75197da..264347d7b6 100644 --- a/integrations/claude-code-plugin/tests/agent-instructions.test.mjs +++ b/integrations/claude-code-plugin/tests/agent-instructions.test.mjs @@ -38,14 +38,12 @@ const scratch = () => realPath(fs.mkdtempSync(path.join(os.tmpdir(), "loom-instr // own, and the scratch checkouts are under the temporary folder: a file with // text outside comments above it would change the layouts below, so it is // named here. (The home folder is a scratch one: `temp-home.mjs`.) -for (const tmp of new Set([os.tmpdir(), fs.realpathSync(os.tmpdir())])) { - for (let dir = tmp, last = ""; dir !== last; last = dir, dir = path.dirname(dir)) { - for (const name of ["CLAUDE.md", path.join(".claude", "CLAUDE.md"), "CLAUDE.local.md"]) { - const file = path.join(dir, name); - const text = fs.existsSync(file) ? fs.readFileSync(file, "utf8") : ""; - const held = text.split(//).some((part) => part.trim()); - assert.equal(held, false, `${file} holds text: run these tests with a TMPDIR that has no such file above it`); - } +for (let dir = realPath(os.tmpdir()), last = ""; dir !== last; last = dir, dir = path.dirname(dir)) { + for (const name of ["CLAUDE.md", path.join(".claude", "CLAUDE.md"), "CLAUDE.local.md"]) { + const file = path.join(dir, name); + const text = fs.existsSync(file) ? fs.readFileSync(file, "utf8") : ""; + const held = text.split(//).some((part) => part.trim()); + assert.equal(held, false, `${file} holds text: run these tests with a TMPDIR that has no such file above it`); } } const words = (block) => @@ -941,38 +939,42 @@ test("a CLAUDE.md in Claude Code's own configuration folder above the checkout l assert.equal(fs.readFileSync(claude, "utf8"), "@AGENTS.md\n"); }); -test("a home folder spelled another way than the checkout's root still names the same files", (t) => { +test("a home folder spelled another way than the checkout's root still names the same files", () => { const home = scratch(); - // Another spelling of the same folder, as an 8.3 name is on Windows: letter case, where the file - // system ignores it (macOS, Windows). - const other = home.toUpperCase(); - if (other === home || !fs.existsSync(other)) return t.skip("the file system tells letter case apart here"); + // Other spellings of the same folder, as an 8.3 name is on Windows: letter case, where the file + // system ignores it (macOS, Windows; a lowercase drive letter there). Linux keeps `home` alone. + const spellings = [...new Set([home, home.toUpperCase(), home.toLowerCase()])].filter((at) => fs.existsSync(at)); const root = path.join(home, "work", "checkout"); - const [agents, claude, mine] = [ + const [agents, claude, mine, above] = [ path.join(root, "AGENTS.md"), path.join(root, "CLAUDE.md"), path.join(home, ".claude", "CLAUDE.md"), + path.join(home, "work", "CLAUDE.md"), ]; - for (const dir of [root, path.dirname(mine)]) fs.mkdirSync(dir, { recursive: true }); + fs.mkdirSync(root, { recursive: true }); execFileSync("git", ["init", "-q"], { cwd: root }); - fs.writeFileSync(mine, "Mine.\n"); - // The configuration folder's CLAUDE.md, through HOME and through CLAUDE_CONFIG_DIR. - for (const [env, at] of [ - [{}, other], - [{ CLAUDE_CONFIG_DIR: path.join(other, ".claude") }, scratch()], - ]) { + for (const at of spellings) { + // The configuration folder's CLAUDE.md, through HOME and through CLAUDE_CONFIG_DIR. + fs.mkdirSync(path.dirname(mine), { recursive: true }); + fs.writeFileSync(mine, "Mine.\n"); + for (const [env, tmp] of [ + [{}, at], + [{ CLAUDE_CONFIG_DIR: path.join(at, ".claude") }, scratch()], + ]) { + fs.writeFileSync(agents, RULES); + const wrote = setup(root, [], { LOOM_MODE: "code", ...env }, tmp); + assert.equal(wrote.stdout, `loom: wrote the Loom block to ${agents}\n`, `${at}: ${wrote.stderr}`); + assert.equal(fs.existsSync(claude), false); + } + // A CLAUDE.md above the checkout that imports AGENTS.md from the home folder. + fs.rmSync(path.dirname(mine), { recursive: true }); + fs.writeFileSync(above, "@~/work/checkout/AGENTS.md\n"); fs.writeFileSync(agents, RULES); - const wrote = setup(root, [], { LOOM_MODE: "code", ...env }, at); - assert.equal(wrote.stdout, `loom: wrote the Loom block to ${agents}\n`, wrote.stderr); + const read = setup(root, [], { LOOM_MODE: "code" }, at); + assert.equal(read.stdout, `loom: wrote the Loom block to ${agents}\n`, `${at}: ${read.stderr}`); assert.equal(fs.existsSync(claude), false); + fs.rmSync(above); } - // A CLAUDE.md above the checkout that imports AGENTS.md from the home folder. - fs.rmSync(path.dirname(mine), { recursive: true }); - fs.writeFileSync(path.join(home, "work", "CLAUDE.md"), "@~/work/checkout/AGENTS.md\n"); - fs.writeFileSync(agents, RULES); - const read = setup(root, [], { LOOM_MODE: "code" }, other); - assert.equal(read.stdout, `loom: wrote the Loom block to ${agents}\n`, read.stderr); - assert.equal(fs.existsSync(claude), false); }); test("loom-setup writes nothing where no code index answers, and still removes there", () => { diff --git a/integrations/codex-plugin/lib/agent-instructions.mjs b/integrations/codex-plugin/lib/agent-instructions.mjs index 83b6408f47..a0bdb6bb32 100644 --- a/integrations/codex-plugin/lib/agent-instructions.mjs +++ b/integrations/codex-plugin/lib/agent-instructions.mjs @@ -163,6 +163,7 @@ function agentsFile(root) { * file's folder, from the home folder (`~/`) or whole. A line inside a * fenced code block is none: Claude Code evaluates no import there. */ function imports(file, target) { + const want = realPath(target); let fence = ""; return read(file) .split(/\r?\n/) @@ -173,9 +174,7 @@ function imports(file, target) { if (mark && !fence) fence = mark; else if (mark?.startsWith(fence)) fence = ""; const to = !mark && !fence && /^@(\S+)$/.exec(text)?.[1]; - return ( - Boolean(to) && realPath(resolve(dirname(file), to.replace(/^~(?=\/)/, homedir()))) === realPath(resolve(target)) - ); + return Boolean(to) && realPath(resolve(dirname(file), to.replace(/^~(?=\/)/, homedir()))) === want; }); } From 5b6be8d81f3e35e0eea2ad102e76be296c287415 Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Wed, 2 Dec 2026 22:53:50 +0530 Subject: [PATCH 3/8] Setup keeps the client's own CLAUDE.md by the spelling it is given Claude Code knows its own CLAUDE.md by the spelling HOME or CLAUDE_CONFIG_DIR gives it. Under another spelling (other letter case on macOS) it reads that file as one above the checkout and leaves AGENTS.md unread, so the @AGENTS.md import setup writes there is the one the client needs. agentsUnreadFor compares that file by the spelling given again. An import is read under any spelling of its path, so imports() still names both sides as the file system does. The test pins both: another spelling of the configuration folder gets the import, and a ~/ import under any spelling counts as reading AGENTS.md. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lareb Zafar --- .../lib/agent-instructions.mjs | 22 ++++++++++++++---- .../tests/agent-instructions.test.mjs | 23 +++++++++++++------ .../codex-plugin/lib/agent-instructions.mjs | 22 ++++++++++++++---- 3 files changed, 52 insertions(+), 15 deletions(-) diff --git a/integrations/claude-code-plugin/lib/agent-instructions.mjs b/integrations/claude-code-plugin/lib/agent-instructions.mjs index a0bdb6bb32..0f1009fb39 100644 --- a/integrations/claude-code-plugin/lib/agent-instructions.mjs +++ b/integrations/claude-code-plugin/lib/agent-instructions.mjs @@ -11,7 +11,7 @@ // which call reads several definitions at once, which tools answer for a // definition's callers and tests, where the index's answer to a prompt is // when the prompt hook brings one, that results need checking). -import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { existsSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs"; import { homedir } from "node:os"; import { dirname, join, relative, resolve, sep } from "node:path"; @@ -159,9 +159,20 @@ function agentsFile(root) { return files.find(holdsBlock) || files[0]; } +/** `file` with its symbolic links resolved, as given where there is none. */ +function real(file) { + try { + return realpathSync(file); + } catch { + return file; + } +} + /** Whether a line of `file` imports `target`: `@` and the path, from the * file's folder, from the home folder (`~/`) or whole. A line inside a - * fenced code block is none: Claude Code evaluates no import there. */ + * fenced code block is none: Claude Code evaluates no import there. The + * client reads an import under any spelling of its path, so both sides are + * named as the file system names them. */ function imports(file, target) { const want = realPath(target); let fence = ""; @@ -196,8 +207,11 @@ function agentsUnreadFor(root, agents) { dir = dirname(dir); files.push(...names.map((name) => join(dir, name))); } - const user = realPath(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); - const own = files.filter((file) => hasText(file) && realPath(file) !== user); + // Claude Code knows its own CLAUDE.md by the spelling HOME or CLAUDE_CONFIG_DIR gives it: under another + // spelling, such as other letter case, it reads that file as one above the checkout and leaves AGENTS.md + // unread. So that spelling is kept here, where `realPath` would name the file as the checkout's root does. + const user = real(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); + const own = files.filter((file) => hasText(file) && real(file) !== user); return own.some((file) => imports(file, agents)) ? undefined : own[0]; } diff --git a/integrations/claude-code-plugin/tests/agent-instructions.test.mjs b/integrations/claude-code-plugin/tests/agent-instructions.test.mjs index 264347d7b6..2407d9fc7f 100644 --- a/integrations/claude-code-plugin/tests/agent-instructions.test.mjs +++ b/integrations/claude-code-plugin/tests/agent-instructions.test.mjs @@ -939,10 +939,10 @@ test("a CLAUDE.md in Claude Code's own configuration folder above the checkout l assert.equal(fs.readFileSync(claude, "utf8"), "@AGENTS.md\n"); }); -test("a home folder spelled another way than the checkout's root still names the same files", () => { +test("a home folder spelled another way: the client's own CLAUDE.md is known by that spelling, an import by any", () => { const home = scratch(); - // Other spellings of the same folder, as an 8.3 name is on Windows: letter case, where the file - // system ignores it (macOS, Windows; a lowercase drive letter there). Linux keeps `home` alone. + // Other spellings of the same folder: letter case, where the file system ignores it (macOS, Windows; a + // lowercase drive letter there). Linux keeps `home` alone. const spellings = [...new Set([home, home.toUpperCase(), home.toLowerCase()])].filter((at) => fs.existsSync(at)); const root = path.join(home, "work", "checkout"); const [agents, claude, mine, above] = [ @@ -954,7 +954,9 @@ test("a home folder spelled another way than the checkout's root still names the fs.mkdirSync(root, { recursive: true }); execFileSync("git", ["init", "-q"], { cwd: root }); for (const at of spellings) { - // The configuration folder's CLAUDE.md, through HOME and through CLAUDE_CONFIG_DIR. + // The configuration folder's CLAUDE.md, through HOME and through CLAUDE_CONFIG_DIR. Claude Code knows it as + // its own only by the spelling it is given: under another one it reads the file as one above the checkout + // and leaves AGENTS.md unread, so setup adds the import. fs.mkdirSync(path.dirname(mine), { recursive: true }); fs.writeFileSync(mine, "Mine.\n"); for (const [env, tmp] of [ @@ -963,10 +965,17 @@ test("a home folder spelled another way than the checkout's root still names the ]) { fs.writeFileSync(agents, RULES); const wrote = setup(root, [], { LOOM_MODE: "code", ...env }, tmp); - assert.equal(wrote.stdout, `loom: wrote the Loom block to ${agents}\n`, `${at}: ${wrote.stderr}`); - assert.equal(fs.existsSync(claude), false); + if (at === home) { + assert.equal(wrote.stdout, `loom: wrote the Loom block to ${agents}\n`, `${at}: ${wrote.stderr}`); + assert.equal(fs.existsSync(claude), false); + } else { + assert.equal(wrote.stdout.startsWith(`loom: ${claude} now holds the line \`@AGENTS.md\`: `), true, at); + assert.equal(fs.readFileSync(claude, "utf8"), "@AGENTS.md\n"); + fs.rmSync(claude); + } } - // A CLAUDE.md above the checkout that imports AGENTS.md from the home folder. + // A CLAUDE.md above the checkout that imports AGENTS.md from the home folder: the client reads an import + // under any spelling, so AGENTS.md is read and setup adds no CLAUDE.md. fs.rmSync(path.dirname(mine), { recursive: true }); fs.writeFileSync(above, "@~/work/checkout/AGENTS.md\n"); fs.writeFileSync(agents, RULES); diff --git a/integrations/codex-plugin/lib/agent-instructions.mjs b/integrations/codex-plugin/lib/agent-instructions.mjs index a0bdb6bb32..0f1009fb39 100644 --- a/integrations/codex-plugin/lib/agent-instructions.mjs +++ b/integrations/codex-plugin/lib/agent-instructions.mjs @@ -11,7 +11,7 @@ // which call reads several definitions at once, which tools answer for a // definition's callers and tests, where the index's answer to a prompt is // when the prompt hook brings one, that results need checking). -import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { existsSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs"; import { homedir } from "node:os"; import { dirname, join, relative, resolve, sep } from "node:path"; @@ -159,9 +159,20 @@ function agentsFile(root) { return files.find(holdsBlock) || files[0]; } +/** `file` with its symbolic links resolved, as given where there is none. */ +function real(file) { + try { + return realpathSync(file); + } catch { + return file; + } +} + /** Whether a line of `file` imports `target`: `@` and the path, from the * file's folder, from the home folder (`~/`) or whole. A line inside a - * fenced code block is none: Claude Code evaluates no import there. */ + * fenced code block is none: Claude Code evaluates no import there. The + * client reads an import under any spelling of its path, so both sides are + * named as the file system names them. */ function imports(file, target) { const want = realPath(target); let fence = ""; @@ -196,8 +207,11 @@ function agentsUnreadFor(root, agents) { dir = dirname(dir); files.push(...names.map((name) => join(dir, name))); } - const user = realPath(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); - const own = files.filter((file) => hasText(file) && realPath(file) !== user); + // Claude Code knows its own CLAUDE.md by the spelling HOME or CLAUDE_CONFIG_DIR gives it: under another + // spelling, such as other letter case, it reads that file as one above the checkout and leaves AGENTS.md + // unread. So that spelling is kept here, where `realPath` would name the file as the checkout's root does. + const user = real(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); + const own = files.filter((file) => hasText(file) && real(file) !== user); return own.some((file) => imports(file, agents)) ? undefined : own[0]; } From 4201571647fde7fe17fa124a944024add2724196 Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Thu, 3 Dec 2026 11:20:48 +0530 Subject: [PATCH 4/8] The integration page says the client knows its own CLAUDE.md by its spelling and follows a ~/ import Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lareb Zafar --- docs/features/integrations/claude-code.md | 7 +++++-- .../claude-code-plugin/lib/agent-instructions.mjs | 7 +++---- .../claude-code-plugin/tests/agent-instructions.test.mjs | 9 +++++---- integrations/codex-plugin/lib/agent-instructions.mjs | 7 +++---- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/docs/features/integrations/claude-code.md b/docs/features/integrations/claude-code.md index edf70e3b64..c68158a0c4 100644 --- a/docs/features/integrations/claude-code.md +++ b/docs/features/integrations/claude-code.md @@ -306,11 +306,14 @@ A file of your own ends the reading of `AGENTS.md` in the same way: a `CLAUDE.lo the repository, or a `CLAUDE.md`, `.claude/CLAUDE.md` or `CLAUDE.local.md` in a folder above it. The `CLAUDE.md` of Claude Code's own configuration folder (`~/.claude/CLAUDE.md`, or the folder `CLAUDE_CONFIG_DIR` names) is not such a file, also for a checkout under -your home folder: the client reads it in every checkout, and `AGENTS.md` beside it. +your home folder: the client reads it in every checkout, and `AGENTS.md` beside it. The +client knows that file by the spelling `HOME` or `CLAUDE_CONFIG_DIR` gives it, so under +another spelling, such as other letter case, it is one of yours above the checkout. Where one holds text, Claude Code reads the repository's `AGENTS.md` only through a file that imports it. Setup picks the block's file from the repository alone, so it names `AGENTS.md` on that machine too. Where a file of your own imports that `AGENTS.md` -(a line `@AGENTS.md`, the path from that file's folder, outside a fenced code block), +(a line `@` and its path, from that file's folder, from the home folder (`~/`) or whole, +outside a fenced code block), Claude Code reads it and setup adds nothing more. Where none does, setup adds the line `@AGENTS.md` to the `CLAUDE.md` at the root: it creates the file where there is none, and a `CLAUDE.md` that held only the block becomes that one line. Your sessions then read the repository's diff --git a/integrations/claude-code-plugin/lib/agent-instructions.mjs b/integrations/claude-code-plugin/lib/agent-instructions.mjs index 0f1009fb39..a882933557 100644 --- a/integrations/claude-code-plugin/lib/agent-instructions.mjs +++ b/integrations/claude-code-plugin/lib/agent-instructions.mjs @@ -159,7 +159,8 @@ function agentsFile(root) { return files.find(holdsBlock) || files[0]; } -/** `file` with its symbolic links resolved, as given where there is none. */ +/** `file` with its symbolic links resolved and its letter case and 8.3 names as given, as Claude Code + * tells its own CLAUDE.md (checked for letter case); as given where there is none. */ function real(file) { try { return realpathSync(file); @@ -207,9 +208,7 @@ function agentsUnreadFor(root, agents) { dir = dirname(dir); files.push(...names.map((name) => join(dir, name))); } - // Claude Code knows its own CLAUDE.md by the spelling HOME or CLAUDE_CONFIG_DIR gives it: under another - // spelling, such as other letter case, it reads that file as one above the checkout and leaves AGENTS.md - // unread. So that spelling is kept here, where `realPath` would name the file as the checkout's root does. + // Under another spelling of HOME or CLAUDE_CONFIG_DIR the client reads its own CLAUDE.md as one above the checkout. const user = real(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); const own = files.filter((file) => hasText(file) && real(file) !== user); return own.some((file) => imports(file, agents)) ? undefined : own[0]; diff --git a/integrations/claude-code-plugin/tests/agent-instructions.test.mjs b/integrations/claude-code-plugin/tests/agent-instructions.test.mjs index 2407d9fc7f..86cca29fb6 100644 --- a/integrations/claude-code-plugin/tests/agent-instructions.test.mjs +++ b/integrations/claude-code-plugin/tests/agent-instructions.test.mjs @@ -942,7 +942,7 @@ test("a CLAUDE.md in Claude Code's own configuration folder above the checkout l test("a home folder spelled another way: the client's own CLAUDE.md is known by that spelling, an import by any", () => { const home = scratch(); // Other spellings of the same folder: letter case, where the file system ignores it (macOS, Windows; a - // lowercase drive letter there). Linux keeps `home` alone. + // lowercase drive letter there). A Linux file system usually tells letter case apart, leaving `home` alone. const spellings = [...new Set([home, home.toUpperCase(), home.toLowerCase()])].filter((at) => fs.existsSync(at)); const root = path.join(home, "work", "checkout"); const [agents, claude, mine, above] = [ @@ -959,17 +959,18 @@ test("a home folder spelled another way: the client's own CLAUDE.md is known by // and leaves AGENTS.md unread, so setup adds the import. fs.mkdirSync(path.dirname(mine), { recursive: true }); fs.writeFileSync(mine, "Mine.\n"); - for (const [env, tmp] of [ + for (const [env, homeFolder] of [ [{}, at], [{ CLAUDE_CONFIG_DIR: path.join(at, ".claude") }, scratch()], ]) { fs.writeFileSync(agents, RULES); - const wrote = setup(root, [], { LOOM_MODE: "code", ...env }, tmp); + const wrote = setup(root, [], { LOOM_MODE: "code", ...env }, homeFolder); if (at === home) { assert.equal(wrote.stdout, `loom: wrote the Loom block to ${agents}\n`, `${at}: ${wrote.stderr}`); assert.equal(fs.existsSync(claude), false); } else { - assert.equal(wrote.stdout.startsWith(`loom: ${claude} now holds the line \`@AGENTS.md\`: `), true, at); + const added = `loom: ${claude} now holds the line \`@AGENTS.md\`: `; + assert.equal(wrote.stdout.startsWith(added), true, `${at}: ${wrote.stdout}${wrote.stderr}`); assert.equal(fs.readFileSync(claude, "utf8"), "@AGENTS.md\n"); fs.rmSync(claude); } diff --git a/integrations/codex-plugin/lib/agent-instructions.mjs b/integrations/codex-plugin/lib/agent-instructions.mjs index 0f1009fb39..a882933557 100644 --- a/integrations/codex-plugin/lib/agent-instructions.mjs +++ b/integrations/codex-plugin/lib/agent-instructions.mjs @@ -159,7 +159,8 @@ function agentsFile(root) { return files.find(holdsBlock) || files[0]; } -/** `file` with its symbolic links resolved, as given where there is none. */ +/** `file` with its symbolic links resolved and its letter case and 8.3 names as given, as Claude Code + * tells its own CLAUDE.md (checked for letter case); as given where there is none. */ function real(file) { try { return realpathSync(file); @@ -207,9 +208,7 @@ function agentsUnreadFor(root, agents) { dir = dirname(dir); files.push(...names.map((name) => join(dir, name))); } - // Claude Code knows its own CLAUDE.md by the spelling HOME or CLAUDE_CONFIG_DIR gives it: under another - // spelling, such as other letter case, it reads that file as one above the checkout and leaves AGENTS.md - // unread. So that spelling is kept here, where `realPath` would name the file as the checkout's root does. + // Under another spelling of HOME or CLAUDE_CONFIG_DIR the client reads its own CLAUDE.md as one above the checkout. const user = real(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); const own = files.filter((file) => hasText(file) && real(file) !== user); return own.some((file) => imports(file, agents)) ? undefined : own[0]; From 5fe8d5457e15059cee53180f75783f056951b335 Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Thu, 3 Dec 2026 16:25:32 +0530 Subject: [PATCH 5/8] Setup names the client's spelling of its own CLAUDE.md for what it is, on every platform clientSpelling (was real) keeps the spelling Claude Code knows its own CLAUDE.md by, and the comment and the integration page name USERPROFILE beside HOME. Both behaviour claims name the Claude Code version they were checked on, 2.1.335. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lareb Zafar --- docs/features/integrations/claude-code.md | 11 ++++++----- .../lib/agent-instructions.mjs | 17 ++++++++++------- .../codex-plugin/lib/agent-instructions.mjs | 17 ++++++++++------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/docs/features/integrations/claude-code.md b/docs/features/integrations/claude-code.md index c68158a0c4..2082a1dafc 100644 --- a/docs/features/integrations/claude-code.md +++ b/docs/features/integrations/claude-code.md @@ -307,14 +307,15 @@ the repository, or a `CLAUDE.md`, `.claude/CLAUDE.md` or `CLAUDE.local.md` in a above it. The `CLAUDE.md` of Claude Code's own configuration folder (`~/.claude/CLAUDE.md`, or the folder `CLAUDE_CONFIG_DIR` names) is not such a file, also for a checkout under your home folder: the client reads it in every checkout, and `AGENTS.md` beside it. The -client knows that file by the spelling `HOME` or `CLAUDE_CONFIG_DIR` gives it, so under -another spelling, such as other letter case, it is one of yours above the checkout. +client knows that file by the spelling of the home folder (`HOME`, `USERPROFILE` on +Windows) or of `CLAUDE_CONFIG_DIR`; where that spelling differs from the file system's +(other letter case, for one), the file counts as one of yours above the checkout. Where one holds text, Claude Code reads the repository's `AGENTS.md` only through a file that imports it. Setup picks the block's file from the repository alone, so it names `AGENTS.md` on that machine too. Where a file of your own imports that `AGENTS.md` -(a line `@` and its path, from that file's folder, from the home folder (`~/`) or whole, -outside a fenced code block), -Claude Code reads it and setup adds nothing more. Where none does, setup adds the line `@AGENTS.md` to the +(a line `@` and its path: from that file's folder, from the home folder as `~/`, or +absolute; not inside a fenced code block), Claude Code reads it and setup adds nothing +more. Where none does, setup adds the line `@AGENTS.md` to the `CLAUDE.md` at the root: it creates the file where there is none, and a `CLAUDE.md` that held only the block becomes that one line. Your sessions then read the repository's `AGENTS.md`, which they did not before. Every machine reads the two files, with or diff --git a/integrations/claude-code-plugin/lib/agent-instructions.mjs b/integrations/claude-code-plugin/lib/agent-instructions.mjs index a882933557..6484245909 100644 --- a/integrations/claude-code-plugin/lib/agent-instructions.mjs +++ b/integrations/claude-code-plugin/lib/agent-instructions.mjs @@ -159,9 +159,10 @@ function agentsFile(root) { return files.find(holdsBlock) || files[0]; } -/** `file` with its symbolic links resolved and its letter case and 8.3 names as given, as Claude Code - * tells its own CLAUDE.md (checked for letter case); as given where there is none. */ -function real(file) { +/** `file` with its symbolic links resolved and the rest of its spelling as given, unlike + * `realPath`: the spelling Claude Code knows its own CLAUDE.md by (letter case checked on + * Claude Code 2.1.335). As given where the file is missing. */ +function clientSpelling(file) { try { return realpathSync(file); } catch { @@ -172,7 +173,8 @@ function real(file) { /** Whether a line of `file` imports `target`: `@` and the path, from the * file's folder, from the home folder (`~/`) or whole. A line inside a * fenced code block is none: Claude Code evaluates no import there. The - * client reads an import under any spelling of its path, so both sides are + * client reads an import under any letter case of its path (checked on + * Claude Code 2.1.335 with `~/` under another case of HOME), so both sides are * named as the file system names them. */ function imports(file, target) { const want = realPath(target); @@ -208,9 +210,10 @@ function agentsUnreadFor(root, agents) { dir = dirname(dir); files.push(...names.map((name) => join(dir, name))); } - // Under another spelling of HOME or CLAUDE_CONFIG_DIR the client reads its own CLAUDE.md as one above the checkout. - const user = real(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); - const own = files.filter((file) => hasText(file) && real(file) !== user); + // The client knows its own CLAUDE.md by the spelling of the home folder (HOME, USERPROFILE on + // Windows) or of CLAUDE_CONFIG_DIR; where that differs from the file system's, the file is one above the checkout. + const user = clientSpelling(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); + const own = files.filter((file) => hasText(file) && clientSpelling(file) !== user); return own.some((file) => imports(file, agents)) ? undefined : own[0]; } diff --git a/integrations/codex-plugin/lib/agent-instructions.mjs b/integrations/codex-plugin/lib/agent-instructions.mjs index a882933557..6484245909 100644 --- a/integrations/codex-plugin/lib/agent-instructions.mjs +++ b/integrations/codex-plugin/lib/agent-instructions.mjs @@ -159,9 +159,10 @@ function agentsFile(root) { return files.find(holdsBlock) || files[0]; } -/** `file` with its symbolic links resolved and its letter case and 8.3 names as given, as Claude Code - * tells its own CLAUDE.md (checked for letter case); as given where there is none. */ -function real(file) { +/** `file` with its symbolic links resolved and the rest of its spelling as given, unlike + * `realPath`: the spelling Claude Code knows its own CLAUDE.md by (letter case checked on + * Claude Code 2.1.335). As given where the file is missing. */ +function clientSpelling(file) { try { return realpathSync(file); } catch { @@ -172,7 +173,8 @@ function real(file) { /** Whether a line of `file` imports `target`: `@` and the path, from the * file's folder, from the home folder (`~/`) or whole. A line inside a * fenced code block is none: Claude Code evaluates no import there. The - * client reads an import under any spelling of its path, so both sides are + * client reads an import under any letter case of its path (checked on + * Claude Code 2.1.335 with `~/` under another case of HOME), so both sides are * named as the file system names them. */ function imports(file, target) { const want = realPath(target); @@ -208,9 +210,10 @@ function agentsUnreadFor(root, agents) { dir = dirname(dir); files.push(...names.map((name) => join(dir, name))); } - // Under another spelling of HOME or CLAUDE_CONFIG_DIR the client reads its own CLAUDE.md as one above the checkout. - const user = real(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); - const own = files.filter((file) => hasText(file) && real(file) !== user); + // The client knows its own CLAUDE.md by the spelling of the home folder (HOME, USERPROFILE on + // Windows) or of CLAUDE_CONFIG_DIR; where that differs from the file system's, the file is one above the checkout. + const user = clientSpelling(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); + const own = files.filter((file) => hasText(file) && clientSpelling(file) !== user); return own.some((file) => imports(file, agents)) ? undefined : own[0]; } From 76e5a4c7c4cf0be27cca0df55560d818fae2110a Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Thu, 3 Dec 2026 16:39:21 +0530 Subject: [PATCH 6/8] Setup picks the block's file from the repository's own import as written imports() takes the spelling it compares by. The repository's CLAUDE.md compares its import as written (clientSpelling), so a file system that folds letter case no longer moves the block: `@agents.md` beside AGENTS.md keeps the block in CLAUDE.md on every machine. Files outside the checkout keep the file system's spelling (realPath), whose docstring now names letter case. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lareb Zafar --- .../lib/agent-instructions.mjs | 19 +++++++++++-------- .../claude-code-plugin/lib/loom-client.mjs | 4 ++-- .../tests/agent-instructions.test.mjs | 9 +++++++++ .../codex-plugin/lib/agent-instructions.mjs | 19 +++++++++++-------- integrations/codex-plugin/lib/loom-client.mjs | 4 ++-- 5 files changed, 35 insertions(+), 20 deletions(-) diff --git a/integrations/claude-code-plugin/lib/agent-instructions.mjs b/integrations/claude-code-plugin/lib/agent-instructions.mjs index 6484245909..b02ec16672 100644 --- a/integrations/claude-code-plugin/lib/agent-instructions.mjs +++ b/integrations/claude-code-plugin/lib/agent-instructions.mjs @@ -172,12 +172,14 @@ function clientSpelling(file) { /** Whether a line of `file` imports `target`: `@` and the path, from the * file's folder, from the home folder (`~/`) or whole. A line inside a - * fenced code block is none: Claude Code evaluates no import there. The - * client reads an import under any letter case of its path (checked on - * Claude Code 2.1.335 with `~/` under another case of HOME), so both sides are - * named as the file system names them. */ -function imports(file, target) { - const want = realPath(target); + * fenced code block is none: Claude Code evaluates no import there. Both + * sides are named by `spelling`. By default that is the file system's + * (`realPath`): the client reads an import under any letter case of its path + * where the file system ignores case (checked on Claude Code 2.1.335 with + * `~/` under another case of HOME), which is how this machine reads a file + * outside the repository. */ +function imports(file, target, spelling = realPath) { + const want = spelling(target); let fence = ""; return read(file) .split(/\r?\n/) @@ -188,7 +190,7 @@ function imports(file, target) { if (mark && !fence) fence = mark; else if (mark?.startsWith(fence)) fence = ""; const to = !mark && !fence && /^@(\S+)$/.exec(text)?.[1]; - return Boolean(to) && realPath(resolve(dirname(file), to.replace(/^~(?=\/)/, homedir()))) === want; + return Boolean(to) && spelling(resolve(dirname(file), to.replace(/^~(?=\/)/, homedir()))) === want; }); } @@ -236,7 +238,8 @@ export function instructionFile(root, client) { if (repoAgents) return repoAgents; return files.find((f) => existsSync(f)) || files[0]; } - const shared = [agents, join(root, ".claude", "AGENTS.md")].find((f) => imports(own, f)); + // The repository's own import as written: a file system that folds letter case must not pick another file. + const shared = [agents, join(root, ".claude", "AGENTS.md")].find((f) => imports(own, f, clientSpelling)); return [...files, ...(shared ? [shared] : [])].find(holdsBlock) || shared || own; } diff --git a/integrations/claude-code-plugin/lib/loom-client.mjs b/integrations/claude-code-plugin/lib/loom-client.mjs index a8d2bc9d96..b5c0bb1e2b 100644 --- a/integrations/claude-code-plugin/lib/loom-client.mjs +++ b/integrations/claude-code-plugin/lib/loom-client.mjs @@ -526,8 +526,8 @@ export function git(args, cwd, { timeoutMs = 1500, raw = false, maxBuffer = 16 * } } -/** `p` as the file system names it: symlinks resolved and, on Windows, - * long names, drive-letter case and backslashes. Two spellings of one place +/** `p` as the file system names it: symlinks resolved, letter case where the + * file system ignores it and, on Windows, long names and backslashes. Two spellings of one place * (macOS /tmp and /private/tmp, a Windows 8.3 temp path, git's C:/ form) * come out equal. The part of `p` that does not exist yet is kept as given. */ export function realPath(p) { diff --git a/integrations/claude-code-plugin/tests/agent-instructions.test.mjs b/integrations/claude-code-plugin/tests/agent-instructions.test.mjs index 86cca29fb6..25ff335f96 100644 --- a/integrations/claude-code-plugin/tests/agent-instructions.test.mjs +++ b/integrations/claude-code-plugin/tests/agent-instructions.test.mjs @@ -1169,3 +1169,12 @@ test("the status check warns about a checkout without the current block and pass "AGENTS.md; `/loom:loom-setup` moves the block into AGENTS.md", }); }); + +test("the repository's own import picks the block's file by its spelling, on every file system", () => { + // `@agents.md` reads AGENTS.md where the file system ignores letter case and nothing where it does not: + // the block stays in the CLAUDE.md, so every machine of the repository picks the same file. + const root = scratch(); + fs.writeFileSync(path.join(root, "AGENTS.md"), "# Rules\n"); + fs.writeFileSync(path.join(root, "CLAUDE.md"), "# Project\n\n@agents.md\n"); + assert.equal(instructionFile(root, "claude-code"), path.join(root, "CLAUDE.md")); +}); diff --git a/integrations/codex-plugin/lib/agent-instructions.mjs b/integrations/codex-plugin/lib/agent-instructions.mjs index 6484245909..b02ec16672 100644 --- a/integrations/codex-plugin/lib/agent-instructions.mjs +++ b/integrations/codex-plugin/lib/agent-instructions.mjs @@ -172,12 +172,14 @@ function clientSpelling(file) { /** Whether a line of `file` imports `target`: `@` and the path, from the * file's folder, from the home folder (`~/`) or whole. A line inside a - * fenced code block is none: Claude Code evaluates no import there. The - * client reads an import under any letter case of its path (checked on - * Claude Code 2.1.335 with `~/` under another case of HOME), so both sides are - * named as the file system names them. */ -function imports(file, target) { - const want = realPath(target); + * fenced code block is none: Claude Code evaluates no import there. Both + * sides are named by `spelling`. By default that is the file system's + * (`realPath`): the client reads an import under any letter case of its path + * where the file system ignores case (checked on Claude Code 2.1.335 with + * `~/` under another case of HOME), which is how this machine reads a file + * outside the repository. */ +function imports(file, target, spelling = realPath) { + const want = spelling(target); let fence = ""; return read(file) .split(/\r?\n/) @@ -188,7 +190,7 @@ function imports(file, target) { if (mark && !fence) fence = mark; else if (mark?.startsWith(fence)) fence = ""; const to = !mark && !fence && /^@(\S+)$/.exec(text)?.[1]; - return Boolean(to) && realPath(resolve(dirname(file), to.replace(/^~(?=\/)/, homedir()))) === want; + return Boolean(to) && spelling(resolve(dirname(file), to.replace(/^~(?=\/)/, homedir()))) === want; }); } @@ -236,7 +238,8 @@ export function instructionFile(root, client) { if (repoAgents) return repoAgents; return files.find((f) => existsSync(f)) || files[0]; } - const shared = [agents, join(root, ".claude", "AGENTS.md")].find((f) => imports(own, f)); + // The repository's own import as written: a file system that folds letter case must not pick another file. + const shared = [agents, join(root, ".claude", "AGENTS.md")].find((f) => imports(own, f, clientSpelling)); return [...files, ...(shared ? [shared] : [])].find(holdsBlock) || shared || own; } diff --git a/integrations/codex-plugin/lib/loom-client.mjs b/integrations/codex-plugin/lib/loom-client.mjs index a8d2bc9d96..b5c0bb1e2b 100644 --- a/integrations/codex-plugin/lib/loom-client.mjs +++ b/integrations/codex-plugin/lib/loom-client.mjs @@ -526,8 +526,8 @@ export function git(args, cwd, { timeoutMs = 1500, raw = false, maxBuffer = 16 * } } -/** `p` as the file system names it: symlinks resolved and, on Windows, - * long names, drive-letter case and backslashes. Two spellings of one place +/** `p` as the file system names it: symlinks resolved, letter case where the + * file system ignores it and, on Windows, long names and backslashes. Two spellings of one place * (macOS /tmp and /private/tmp, a Windows 8.3 temp path, git's C:/ form) * come out equal. The part of `p` that does not exist yet is kept as given. */ export function realPath(p) { From b24d1ef959586207b34a137c62c15e068a437177 Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Thu, 3 Dec 2026 16:47:04 +0530 Subject: [PATCH 7/8] Setup names each import comparison's spelling where it is made asWritten (was clientSpelling) says what it returns; imports() takes its spelling at both call sites, each with its reason. realPath folds letter case on macOS and Windows only, and the integration page names the Claude Code version the CLAUDE.md spelling was checked on. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lareb Zafar --- docs/features/integrations/claude-code.md | 3 +- .../lib/agent-instructions.mjs | 28 +++++++++---------- .../claude-code-plugin/lib/loom-client.mjs | 4 +-- .../codex-plugin/lib/agent-instructions.mjs | 28 +++++++++---------- integrations/codex-plugin/lib/loom-client.mjs | 4 +-- 5 files changed, 32 insertions(+), 35 deletions(-) diff --git a/docs/features/integrations/claude-code.md b/docs/features/integrations/claude-code.md index 2082a1dafc..d324497d71 100644 --- a/docs/features/integrations/claude-code.md +++ b/docs/features/integrations/claude-code.md @@ -309,7 +309,8 @@ or the folder `CLAUDE_CONFIG_DIR` names) is not such a file, also for a checkout your home folder: the client reads it in every checkout, and `AGENTS.md` beside it. The client knows that file by the spelling of the home folder (`HOME`, `USERPROFILE` on Windows) or of `CLAUDE_CONFIG_DIR`; where that spelling differs from the file system's -(other letter case, for one), the file counts as one of yours above the checkout. +(other letter case, for one), the file counts as one of yours above the checkout (checked on +Claude Code 2.1.335). Where one holds text, Claude Code reads the repository's `AGENTS.md` only through a file that imports it. Setup picks the block's file from the repository alone, so it names `AGENTS.md` on that machine too. Where a file of your own imports that `AGENTS.md` diff --git a/integrations/claude-code-plugin/lib/agent-instructions.mjs b/integrations/claude-code-plugin/lib/agent-instructions.mjs index b02ec16672..675872a140 100644 --- a/integrations/claude-code-plugin/lib/agent-instructions.mjs +++ b/integrations/claude-code-plugin/lib/agent-instructions.mjs @@ -159,10 +159,9 @@ function agentsFile(root) { return files.find(holdsBlock) || files[0]; } -/** `file` with its symbolic links resolved and the rest of its spelling as given, unlike - * `realPath`: the spelling Claude Code knows its own CLAUDE.md by (letter case checked on - * Claude Code 2.1.335). As given where the file is missing. */ -function clientSpelling(file) { +/** `file` with its symbolic links resolved and the rest of its spelling as written, unlike + * `realPath`; as written where the file is missing. */ +function asWritten(file) { try { return realpathSync(file); } catch { @@ -173,12 +172,8 @@ function clientSpelling(file) { /** Whether a line of `file` imports `target`: `@` and the path, from the * file's folder, from the home folder (`~/`) or whole. A line inside a * fenced code block is none: Claude Code evaluates no import there. Both - * sides are named by `spelling`. By default that is the file system's - * (`realPath`): the client reads an import under any letter case of its path - * where the file system ignores case (checked on Claude Code 2.1.335 with - * `~/` under another case of HOME), which is how this machine reads a file - * outside the repository. */ -function imports(file, target, spelling = realPath) { + * sides are named by `spelling`. */ +function imports(file, target, spelling) { const want = spelling(target); let fence = ""; return read(file) @@ -213,10 +208,13 @@ function agentsUnreadFor(root, agents) { files.push(...names.map((name) => join(dir, name))); } // The client knows its own CLAUDE.md by the spelling of the home folder (HOME, USERPROFILE on - // Windows) or of CLAUDE_CONFIG_DIR; where that differs from the file system's, the file is one above the checkout. - const user = clientSpelling(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); - const own = files.filter((file) => hasText(file) && clientSpelling(file) !== user); - return own.some((file) => imports(file, agents)) ? undefined : own[0]; + // Windows) or of CLAUDE_CONFIG_DIR, as written; where that differs from the file system's, the + // file is one above the checkout (letter case checked on Claude Code 2.1.335). + const user = asWritten(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); + const own = files.filter((file) => hasText(file) && asWritten(file) !== user); + // This machine's file system resolves an import of these files: the client reads one under any + // letter case where the file system ignores it (checked on Claude Code 2.1.335, `~/` under another case of HOME). + return own.some((file) => imports(file, agents, realPath)) ? undefined : own[0]; } /** The file the block belongs in, the same one on every machine: no file @@ -239,7 +237,7 @@ export function instructionFile(root, client) { return files.find((f) => existsSync(f)) || files[0]; } // The repository's own import as written: a file system that folds letter case must not pick another file. - const shared = [agents, join(root, ".claude", "AGENTS.md")].find((f) => imports(own, f, clientSpelling)); + const shared = [agents, join(root, ".claude", "AGENTS.md")].find((f) => imports(own, f, asWritten)); return [...files, ...(shared ? [shared] : [])].find(holdsBlock) || shared || own; } diff --git a/integrations/claude-code-plugin/lib/loom-client.mjs b/integrations/claude-code-plugin/lib/loom-client.mjs index b5c0bb1e2b..b072c42f2c 100644 --- a/integrations/claude-code-plugin/lib/loom-client.mjs +++ b/integrations/claude-code-plugin/lib/loom-client.mjs @@ -526,8 +526,8 @@ export function git(args, cwd, { timeoutMs = 1500, raw = false, maxBuffer = 16 * } } -/** `p` as the file system names it: symlinks resolved, letter case where the - * file system ignores it and, on Windows, long names and backslashes. Two spellings of one place +/** `p` as the file system names it: symlinks resolved, letter case on macOS + * and Windows and, on Windows, long names and backslashes. Two spellings of one place * (macOS /tmp and /private/tmp, a Windows 8.3 temp path, git's C:/ form) * come out equal. The part of `p` that does not exist yet is kept as given. */ export function realPath(p) { diff --git a/integrations/codex-plugin/lib/agent-instructions.mjs b/integrations/codex-plugin/lib/agent-instructions.mjs index b02ec16672..675872a140 100644 --- a/integrations/codex-plugin/lib/agent-instructions.mjs +++ b/integrations/codex-plugin/lib/agent-instructions.mjs @@ -159,10 +159,9 @@ function agentsFile(root) { return files.find(holdsBlock) || files[0]; } -/** `file` with its symbolic links resolved and the rest of its spelling as given, unlike - * `realPath`: the spelling Claude Code knows its own CLAUDE.md by (letter case checked on - * Claude Code 2.1.335). As given where the file is missing. */ -function clientSpelling(file) { +/** `file` with its symbolic links resolved and the rest of its spelling as written, unlike + * `realPath`; as written where the file is missing. */ +function asWritten(file) { try { return realpathSync(file); } catch { @@ -173,12 +172,8 @@ function clientSpelling(file) { /** Whether a line of `file` imports `target`: `@` and the path, from the * file's folder, from the home folder (`~/`) or whole. A line inside a * fenced code block is none: Claude Code evaluates no import there. Both - * sides are named by `spelling`. By default that is the file system's - * (`realPath`): the client reads an import under any letter case of its path - * where the file system ignores case (checked on Claude Code 2.1.335 with - * `~/` under another case of HOME), which is how this machine reads a file - * outside the repository. */ -function imports(file, target, spelling = realPath) { + * sides are named by `spelling`. */ +function imports(file, target, spelling) { const want = spelling(target); let fence = ""; return read(file) @@ -213,10 +208,13 @@ function agentsUnreadFor(root, agents) { files.push(...names.map((name) => join(dir, name))); } // The client knows its own CLAUDE.md by the spelling of the home folder (HOME, USERPROFILE on - // Windows) or of CLAUDE_CONFIG_DIR; where that differs from the file system's, the file is one above the checkout. - const user = clientSpelling(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); - const own = files.filter((file) => hasText(file) && clientSpelling(file) !== user); - return own.some((file) => imports(file, agents)) ? undefined : own[0]; + // Windows) or of CLAUDE_CONFIG_DIR, as written; where that differs from the file system's, the + // file is one above the checkout (letter case checked on Claude Code 2.1.335). + const user = asWritten(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); + const own = files.filter((file) => hasText(file) && asWritten(file) !== user); + // This machine's file system resolves an import of these files: the client reads one under any + // letter case where the file system ignores it (checked on Claude Code 2.1.335, `~/` under another case of HOME). + return own.some((file) => imports(file, agents, realPath)) ? undefined : own[0]; } /** The file the block belongs in, the same one on every machine: no file @@ -239,7 +237,7 @@ export function instructionFile(root, client) { return files.find((f) => existsSync(f)) || files[0]; } // The repository's own import as written: a file system that folds letter case must not pick another file. - const shared = [agents, join(root, ".claude", "AGENTS.md")].find((f) => imports(own, f, clientSpelling)); + const shared = [agents, join(root, ".claude", "AGENTS.md")].find((f) => imports(own, f, asWritten)); return [...files, ...(shared ? [shared] : [])].find(holdsBlock) || shared || own; } diff --git a/integrations/codex-plugin/lib/loom-client.mjs b/integrations/codex-plugin/lib/loom-client.mjs index b5c0bb1e2b..b072c42f2c 100644 --- a/integrations/codex-plugin/lib/loom-client.mjs +++ b/integrations/codex-plugin/lib/loom-client.mjs @@ -526,8 +526,8 @@ export function git(args, cwd, { timeoutMs = 1500, raw = false, maxBuffer = 16 * } } -/** `p` as the file system names it: symlinks resolved, letter case where the - * file system ignores it and, on Windows, long names and backslashes. Two spellings of one place +/** `p` as the file system names it: symlinks resolved, letter case on macOS + * and Windows and, on Windows, long names and backslashes. Two spellings of one place * (macOS /tmp and /private/tmp, a Windows 8.3 temp path, git's C:/ form) * come out equal. The part of `p` that does not exist yet is kept as given. */ export function realPath(p) { From 5bba5140a1977392de0f373610de9d666d5efbb5 Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Thu, 3 Dec 2026 16:59:36 +0530 Subject: [PATCH 8/8] Setup's own-file note names only the letter case checked on Claude Code Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lareb Zafar --- docs/features/integrations/claude-code.md | 6 +++--- .../claude-code-plugin/lib/agent-instructions.mjs | 10 ++++++---- integrations/codex-plugin/lib/agent-instructions.mjs | 10 ++++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/docs/features/integrations/claude-code.md b/docs/features/integrations/claude-code.md index d324497d71..9fe8d27d69 100644 --- a/docs/features/integrations/claude-code.md +++ b/docs/features/integrations/claude-code.md @@ -308,9 +308,9 @@ above it. The `CLAUDE.md` of Claude Code's own configuration folder (`~/.claude/ or the folder `CLAUDE_CONFIG_DIR` names) is not such a file, also for a checkout under your home folder: the client reads it in every checkout, and `AGENTS.md` beside it. The client knows that file by the spelling of the home folder (`HOME`, `USERPROFILE` on -Windows) or of `CLAUDE_CONFIG_DIR`; where that spelling differs from the file system's -(other letter case, for one), the file counts as one of yours above the checkout (checked on -Claude Code 2.1.335). +Windows) or of `CLAUDE_CONFIG_DIR`; in another letter case than the file system's, the file +counts as one of yours above the checkout (checked on Claude Code 2.1.335 on macOS). Setup +follows a symbolic link in that spelling. Where one holds text, Claude Code reads the repository's `AGENTS.md` only through a file that imports it. Setup picks the block's file from the repository alone, so it names `AGENTS.md` on that machine too. Where a file of your own imports that `AGENTS.md` diff --git a/integrations/claude-code-plugin/lib/agent-instructions.mjs b/integrations/claude-code-plugin/lib/agent-instructions.mjs index 675872a140..945c605629 100644 --- a/integrations/claude-code-plugin/lib/agent-instructions.mjs +++ b/integrations/claude-code-plugin/lib/agent-instructions.mjs @@ -208,12 +208,14 @@ function agentsUnreadFor(root, agents) { files.push(...names.map((name) => join(dir, name))); } // The client knows its own CLAUDE.md by the spelling of the home folder (HOME, USERPROFILE on - // Windows) or of CLAUDE_CONFIG_DIR, as written; where that differs from the file system's, the - // file is one above the checkout (letter case checked on Claude Code 2.1.335). + // Windows) or of CLAUDE_CONFIG_DIR, as written: in another letter case than the file system's, + // the file is one above the checkout (checked on Claude Code 2.1.335 on macOS). Setup follows a + // symbolic link in that spelling. const user = asWritten(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); const own = files.filter((file) => hasText(file) && asWritten(file) !== user); - // This machine's file system resolves an import of these files: the client reads one under any - // letter case where the file system ignores it (checked on Claude Code 2.1.335, `~/` under another case of HOME). + // An import line in these files is compared as this machine's file system names its path: the + // client follows one under any letter case where the file system ignores it (checked on Claude + // Code 2.1.335, `~/` under another case of HOME). return own.some((file) => imports(file, agents, realPath)) ? undefined : own[0]; } diff --git a/integrations/codex-plugin/lib/agent-instructions.mjs b/integrations/codex-plugin/lib/agent-instructions.mjs index 675872a140..945c605629 100644 --- a/integrations/codex-plugin/lib/agent-instructions.mjs +++ b/integrations/codex-plugin/lib/agent-instructions.mjs @@ -208,12 +208,14 @@ function agentsUnreadFor(root, agents) { files.push(...names.map((name) => join(dir, name))); } // The client knows its own CLAUDE.md by the spelling of the home folder (HOME, USERPROFILE on - // Windows) or of CLAUDE_CONFIG_DIR, as written; where that differs from the file system's, the - // file is one above the checkout (letter case checked on Claude Code 2.1.335). + // Windows) or of CLAUDE_CONFIG_DIR, as written: in another letter case than the file system's, + // the file is one above the checkout (checked on Claude Code 2.1.335 on macOS). Setup follows a + // symbolic link in that spelling. const user = asWritten(join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "CLAUDE.md")); const own = files.filter((file) => hasText(file) && asWritten(file) !== user); - // This machine's file system resolves an import of these files: the client reads one under any - // letter case where the file system ignores it (checked on Claude Code 2.1.335, `~/` under another case of HOME). + // An import line in these files is compared as this machine's file system names its path: the + // client follows one under any letter case where the file system ignores it (checked on Claude + // Code 2.1.335, `~/` under another case of HOME). return own.some((file) => imports(file, agents, realPath)) ? undefined : own[0]; }