Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

fix(windows): write the folder-trust key under the path Claude Code reads (#607)

himeshram75845a5bef30
diff --git a/src/main/config.ts b/src/main/config.ts
index c1092988..f66c854c 100644
--- a/src/main/config.ts
+++ b/src/main/config.ts
@@ -831,9 +831,23 @@ function ensureClaudeProjectTrust(home: string, cwd: string): void {
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return;
c = parsed as ClaudeConfig;
}
- if (c.projects?.[cwd]?.hasTrustDialogAccepted !== true) {
+ // Claude Code looks this entry up under a path normalised to FORWARD
+ // slashes — its own lookup walks parents with `o.startsWith(r + "/")`, and
+ // the entries it writes on Windows are keyed "C:/Users/…". Writing only the
+ // raw Windows path ("C:\Users\…") puts the flag somewhere Claude never
+ // reads, so the agent still hits the interactive "Accessing workspace /
+ // Quick safety check" dialog, which it cannot answer: god exits 1 and every
+ // message to it sits at "waiting".
+ //
+ // Both spellings are written — the normalised one is what current Claude
+ // reads, the raw one keeps older builds working. On macOS and Linux the two
+ // are identical, the Set collapses to one key, and this is a no-op.
+ const keys = Array.from(new Set([cwd.replace(/\\/g, '/'), cwd]));
+ if (keys.some((k) => c.projects?.[k]?.hasTrustDialogAccepted !== true)) {
c.projects = c.projects ?? {};
- c.projects[cwd] = { ...(c.projects[cwd] ?? {}), hasTrustDialogAccepted: true };
+ for (const k of keys) {
+ c.projects[k] = { ...(c.projects[k] ?? {}), hasTrustDialogAccepted: true };
+ }
writeFileSync(p, JSON.stringify(c, null, 2), 'utf8');
}
} catch (error) {
diff --git a/test/claude-permissions-config.test.cjs b/test/claude-permissions-config.test.cjs
index d6f294a3..499ecec2 100644
--- a/test/claude-permissions-config.test.cjs
+++ b/test/claude-permissions-config.test.cjs
@@ -32,6 +32,14 @@ const settingsPath = path.join(settingsDir, 'settings.json');
const projectConfigPath = path.join(home, '.claude.json');
const cwd = path.join(home, 'workspace', 'project');
+// Claude Code reads projects[] under a path normalised to forward slashes, so
+// the trust flag is written under every spelling it might look up. On Windows
+// that is two keys; on macOS and Linux the two are the same string and this
+// collapses to the single key these tests have always asserted.
+const cwdKeys = Array.from(new Set([cwd.replace(/\\/g, '/'), cwd]));
+const trustedCwd = (entry = { hasTrustDialogAccepted: true }) =>
+ Object.fromEntries(cwdKeys.map((k) => [k, k === cwd ? entry : { hasTrustDialogAccepted: true }]));
+
function writeSettings(contents) {
fs.mkdirSync(settingsDir, { recursive: true });
fs.writeFileSync(settingsPath, contents, 'utf8');
@@ -98,11 +106,11 @@ test('merges required fields into valid configs without losing unrelated data',
assert.deepEqual(JSON.parse(fs.readFileSync(projectConfigPath, 'utf8')), {
numStartups: 7,
projects: {
- [cwd]: {
+ ...trustedCwd({
allowedTools: ['Read'],
custom: 'keep',
hasTrustDialogAccepted: true
- },
+ }),
'/another/project': { hasTrustDialogAccepted: false }
}
});
@@ -116,7 +124,7 @@ test('creates minimal config files when they are missing', () => {
skipAutoPermissionPrompt: true
});
assert.deepEqual(JSON.parse(fs.readFileSync(projectConfigPath, 'utf8')), {
- projects: { [cwd]: { hasTrustDialogAccepted: true } }
+ projects: trustedCwd()
});
});
@@ -130,15 +138,13 @@ test('a malformed settings file does not prevent safe project trust updates', ()
assert.equal(fs.readFileSync(settingsPath, 'utf8'), malformedSettings);
assert.deepEqual(JSON.parse(fs.readFileSync(projectConfigPath, 'utf8')), {
custom: 'keep',
- projects: { [cwd]: { hasTrustDialogAccepted: true } }
+ projects: trustedCwd()
});
});
test('does not rewrite configs that already contain every required field', () => {
const settings = '{"skipDangerousModePermissionPrompt":true,"skipAutoPermissionPrompt":true}\n';
- const projectConfig = JSON.stringify({
- projects: { [cwd]: { hasTrustDialogAccepted: true } }
- }) + '\n';
+ const projectConfig = JSON.stringify({ projects: trustedCwd() }) + '\n';
writeSettings(settings);
fs.writeFileSync(projectConfigPath, projectConfig, 'utf8');
@@ -158,3 +164,19 @@ test('preserves existing config files with unsafe JSON root shapes', () => {
assert.equal(fs.readFileSync(settingsPath, 'utf8'), 'null\n');
assert.equal(fs.readFileSync(projectConfigPath, 'utf8'), '["keep"]\n');
});
+
+test('repairs a config trusted only under the raw path spelling', () => {
+ // The bug this guards: on Windows the raw path is "C:\…" while Claude Code
+ // looks the entry up as "C:/…". A config trusted only under the raw spelling
+ // left the folder untrusted as far as Claude was concerned, so the agent hit
+ // the interactive trust dialog it cannot answer and exited 1.
+ fs.writeFileSync(projectConfigPath, JSON.stringify({
+ projects: { [cwd]: { hasTrustDialogAccepted: true } }
+ }), 'utf8');
+
+ ensureClaudePermissionsAccepted(cwd);
+
+ const projects = JSON.parse(fs.readFileSync(projectConfigPath, 'utf8')).projects;
+ assert.equal(projects[cwd.replace(/\\/g, '/')]?.hasTrustDialogAccepted, true);
+ assert.equal(projects[cwd]?.hasTrustDialogAccepted, true);
+});