The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Windows: a Swarm worktree inherits its clone's folder trust (#1647)
0xken15d16e8f06ea2b
diff --git a/cli/src/engines/kit/folderTrust.spec.ts b/cli/src/engines/kit/folderTrust.spec.tsindex deeb05562..8a21ef33c 100644--- a/cli/src/engines/kit/folderTrust.spec.ts+++ b/cli/src/engines/kit/folderTrust.spec.ts@@ -175,6 +175,51 @@ describe('whether a source repo is already trusted (a worktree inherits only thaexpect(claudeTrusts('/work/repo', home)).toBe(false)})+ // Claude Code 2.1.309 walks up from the folder only as far as its Git repository's root (`E_` stops at the root `$_`+ // finds), so a repository cloned under an accepted folder asks again. A worktree pre-trusted from a folder above its+ // repository would skip the question Claude Code itself asks (review of #1647).+ it('inherits Claude trust only within the same Git repository', () => {+ const home = mkdtempSync(join(tmpdir(), 'trust-')), root = mkdtempSync(join(tmpdir(), 'trust-tree-'))+ const parent = join(root, 'parent'), clone = join(parent, 'clone'), plain = join(parent, 'plain')+ mkdirSync(join(clone, '.git'), { recursive: true })+ mkdirSync(join(clone, 'sub'))+ mkdirSync(plain)+ writeFileSync(join(home, '.claude.json'), JSON.stringify({ projects: { [parent]: { hasTrustDialogAccepted: true } } }))+ expect(claudeTrusts(plain, home)).toBe(true)+ expect(claudeTrusts(clone, home)).toBe(false)+ expect(claudeTrusts(join(clone, 'sub'), home)).toBe(false)+ writeFileSync(join(home, '.claude.json'), JSON.stringify({ projects: { [clone]: { hasTrustDialogAccepted: true } } }))+ expect(claudeTrusts(clone, home)).toBe(true)+ expect(claudeTrusts(join(clone, 'sub'), home)).toBe(true)+ })++ it('matches a stored folder on Mac and Linux by its text, as before', () => {+ const home = mkdtempSync(join(tmpdir(), 'trust-'))+ writeFileSync(join(home, '.claude.json'), JSON.stringify({ projects: { '/work/allow/..': { hasTrustDialogAccepted: true } } }))+ expect(claudeTrusts('/work/other', home)).toBe(false)+ expect(claudeTrusts('/work', home)).toBe(false)+ expect(claudeTrusts('/work/allow/../sub', home)).toBe(true)+ })++ // DESKTOP-0TFH0OJ, 2026-10-23: a Swarm worktree's source arrived as `C:\\…\\<tab>/<project>` (the Lead joins with "/")+ // while its trust was recorded as `C:\\…\\<tab>\\<project>`. Compared as text with "/" only, it never matched, so+ // every Swarm start on Windows stopped at Claude Code's trust prompt.+ it('compares Windows folders the way Windows does: any separator, any case, a folder above it', () => {+ const home = mkdtempSync(join(tmpdir(), 'trust-'))+ writeFileSync(join(home, '.claude.json'), JSON.stringify({ projects: { 'C:\\Users\\DELL\\swarm-projects\\tab\\project': { hasTrustDialogAccepted: true } } }))+ mkdirSync(join(home, '.codex'))+ writeFileSync(join(home, '.codex', 'config.toml'), '[projects.\'C:\\Users\\DELL\\swarm-projects\\tab\\project\']\ntrust_level = "trusted"\n')+ const platform = Object.getOwnPropertyDescriptor(process, 'platform')!+ try {+ Object.defineProperty(process, 'platform', { ...platform, value: 'win32' })+ expect(claudeTrusts('C:\\Users\\DELL\\swarm-projects\\tab/project', home)).toBe(true)+ expect(claudeTrusts('c:\\users\\dell\\swarm-projects\\tab\\project\\sub', home)).toBe(true)+ expect(claudeTrusts('C:\\Users\\DELL\\swarm-projects\\tab\\project-evil', home)).toBe(false)+ expect(codexTrusts('C:\\Users\\DELL\\swarm-projects\\tab/project', join(home, '.codex'))).toBe(true)+ expect(codexTrusts('C:\\Users\\DELL\\swarm-projects\\tab', join(home, '.codex'))).toBe(false)+ } finally { Object.defineProperty(process, 'platform', platform) }+ })+it('reads Codex trust from exactly that folder\'s table', () => {const home = mkdtempSync(join(tmpdir(), 'trust-'))expect(codexTrusts('/work/repo', join(home, '.codex'))).toBe(false)diff --git a/cli/src/engines/kit/folderTrust.ts b/cli/src/engines/kit/folderTrust.tsindex 0b50e77f0..139d98209 100644--- a/cli/src/engines/kit/folderTrust.ts+++ b/cli/src/engines/kit/folderTrust.ts@@ -15,6 +15,7 @@* file), when the file does not parse, or when it already says yes.*/import { existsSync, readFileSync, realpathSync, renameSync, writeFileSync } from 'node:fs'+import { posix, win32 } from 'node:path'import type { TrustContract } from '../facets/launch.js'type JsonTrust = Extract<TrustContract, { format: 'json' }>@@ -30,6 +31,29 @@ export function recordTrustIn(trust: TrustContract, file: string, cwd: string):return trust.format === 'json' ? recordJson(trust, file, cwd) : recordToml(trust, file, cwd)}+/** A folder as this platform compares it. DESKTOP-0TFH0OJ, 2026-10-23: a Swarm worktree's source came as+ * `C:\…\<tab>/<project>` (the Lead joins with "/") and its trust was recorded as `C:\…\<tab>\<project>`; compared as+ * text, every Swarm start on Windows stopped at the engine's trust prompt. On Windows any separator and any case is the+ * same folder; elsewhere the text is compared as it always was. Never resolved: an engine looks up keys as written. */+const windows = (): boolean => process.platform === 'win32'+const folderText = (path: string): string => windows() ? path.replace(/\//g, '\\').toLowerCase() : path+const sameFolder = (key: string, path: string): boolean => folderText(key) === folderText(path)+/** `path` is `base` or a folder under it. */+function within(base: string, path: string): boolean {+ const separator = windows() ? '\\' : '/', folder = folderText(base).replace(windows() ? /\\+$/ : /\/+$/, ''), target = folderText(path)+ return target === folder || target.startsWith(`${folder}${separator}`)+}+/** The root of the Git repository `path` is in, or null outside one: where Claude Code stops looking for an accepted folder+ * above it (2.1.309 walks up to the root its `$_` finds, no further), so a repository cloned under an accepted folder asks+ * again. */+function repositoryRoot(path: string): string | null {+ const paths = windows() ? win32 : posix+ for (let folder = path; ; folder = paths.dirname(folder)) {+ if (existsSync(paths.join(folder, '.git'))) return folder+ if (paths.dirname(folder) === folder) return null+ }+}+function isPlainObject(value: unknown): value is Record<string, unknown> {return typeof value === 'object' && value !== null && !Array.isArray(value)}@@ -68,17 +92,16 @@ function recordJson(trust: JsonTrust, file: string, cwd: string): 'trusted' | 'areturn 'trusted'}-/** Its own entry, or a folder above it, says yes: the inheritance Claude Code applies. Unreadable or absent+/** Its own entry, or a folder above it in the same Git repository, says yes: the inheritance Claude Code applies. Unreadable or absent* settings read as no. */function jsonTrusts(trust: JsonTrust, file: string, path: string): boolean {if (!existsSync(file)) return falselet config: unknowntry { config = JSON.parse(readFileSync(file, 'utf8')) } catch { return false }if (!isPlainObject(config) || !isPlainObject(config[trust.projects])) return false+ const root = repositoryRoot(path)for (const [key, entry] of Object.entries(config[trust.projects] as Record<string, unknown>)) {- if (!isPlainObject(entry) || entry[trust.accepted] !== true) continue- const base = key.replace(/\/+$/, '')- if (path === base || path.startsWith(`${base}/`)) return true+ if (isPlainObject(entry) && entry[trust.accepted] === true && within(key, path) && (root === null || within(root, key))) return true}return false}@@ -103,7 +126,8 @@ function tomlTrusts(trust: TomlTrust, file: string, path: string): boolean {if (!existsSync(file)) return falseconst text = readFileSync(file, 'utf8')for (const match of text.matchAll(headerPattern(trust))) {- if (tomlKey(match[1]) !== path) continue+ const key = tomlKey(match[1])+ if (key === null || !sameFolder(key, path)) continueconst rest = text.slice((match.index ?? 0) + match[0].length)const body = rest.split(/^[ \t]*\[/m)[0]return new RegExp(String.raw`^[ \t]*${escape(trust.key)}[ \t]*=[ \t]*["']${escape(trust.value)}["']`, 'm').test(body)