The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 10:45 UTC
fix(server): accept explicit false in Claude managed policy (#24402)
Co-authored-by: Zayd <iam@zayd.wtf> Co-authored-by: maria-rcks <maria@kuuro.net>
zayd / cold committed
Oct 30, 2026 at 14:05 UTC
e0464a71c4ae0e4b6ca928b328501094f717281d
2 files changed
+140
-6
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+97
@@ -3566,6 +3566,32 @@ describe("ClaudeAdapterV2 background wake turns", () => {
3566
const restricted = yield* open;
3567
assert.equal(restricted.permissionMode, "default");
3568
assert.isUndefined(restricted.allowDangerouslySkipPermissions);
3569
+ yield* fileSystem.writeFileString(
3570
+ remoteFile,
3571
+ JSON.stringify({
3572
+ permissions: { disableBypassPermissionsMode: false, disableAutoMode: false },
3573
+ disableAutoMode: false,
3574
+ managedSourcesBehavior: "merge",
3575
+ }),
3576
+ );
3577
+ const unrestricted = yield* open;
3578
+ assert.equal(unrestricted.permissionMode, "bypassPermissions");
3579
+ assert.equal(unrestricted.allowDangerouslySkipPermissions, true);
3580
+ yield* fileSystem.writeFileString(
3581
+ remoteFile,
3582
+ JSON.stringify({
3583
+ permissions: { disableBypassPermissionsMode: "disable", disableAutoMode: "disable" },
3584
+ disableAutoMode: false,
3585
+ }),
3586
+ );
3587
+ const mixed = yield* open;
3588
+ assert.equal(mixed.permissionMode, "default");
3589
+ assert.isUndefined(mixed.allowDangerouslySkipPermissions);
3590
+ yield* fileSystem.writeFileString(
3591
+ remoteFile,
3592
+ JSON.stringify({ permissions: { disableBypassPermissionsMode: true } }),
3593
+ );
3594
+ assert.equal((yield* open).permissionMode, "auto");
3595
yield* fileSystem.remove(remoteFile);
3596
assert.equal((yield* open).permissionMode, "bypassPermissions");
3597
const launchRestricted = yield* openWith(
@@ -3585,6 +3611,77 @@ describe("ClaudeAdapterV2 background wake turns", () => {
3611
),
3612
);
3613
3614
+ it.effect("drops false bypass switches from --settings before they reach the SDK", () =>
3615
+ Effect.gen(function* () {
3616
+ const fileSystem = yield* FileSystem.FileSystem;
3617
+ const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-launch-" });
3618
+ const cwd = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-launch-cwd-" });
3619
+ const sdk = yield* Effect.promise(() =>
3620
+ vi.importActual<typeof ClaudeSdk>("@anthropic-ai/claude-agent-sdk"),
3621
+ );
3622
+ vi.mocked(ClaudeSdk.resolveSettings).mockImplementation(sdk.resolveSettings);
3623
+ const openWith = (settings: Record<string, unknown>) =>
3624
+ Effect.scoped(
3625
+ Effect.gen(function* () {
3626
+ const harness = yield* makeWakeHarnessWithOptions({
3627
+ settings: {
3628
+ ...DEFAULT_CLAUDE_SETTINGS,
3629
+ homePath: home,
3630
+ launchArgs: `--settings '${JSON.stringify(settings)}'`,
3631
+ },
3632
+ });
3633
+ yield* harness.runtime.startTurn(
3634
+ makeClaudeTestTurnInput({
3635
+ threadId: harness.threadId,
3636
+ providerThread: harness.providerThread,
3637
+ now: yield* DateTime.now,
3638
+ attemptId: RunAttemptId.make("attempt-launch-arg-settings"),
3639
+ text: "Run git status.",
3640
+ attachments: [],
3641
+ runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
3642
+ runtimeMode: "full-access",
3643
+ interactionMode: "default",
3644
+ cwd,
3645
+ }),
3646
+ }),
3647
+ );
3648
+ const options = harness.getOpenedOptions()!;
3649
+ return {
3650
+ permissionMode: options.permissionMode,
3651
+ settings: options.settings as {
3652
+ disableAutoMode?: unknown;
3653
+ permissions?: Record<string, unknown>;
3654
+ env?: Record<string, unknown>;
3655
+ },
3656
+ };
3657
+ }),
3658
+ );
3659
+ const unrestricted = yield* openWith({
3660
+ disableAutoMode: false,
3661
+ permissions: { disableBypassPermissionsMode: false, disableAutoMode: false, allow: [] },
3662
+ env: { KEPT: "1" },
3663
+ });
3664
+ assert.equal(unrestricted.permissionMode, "bypassPermissions");
3665
+ assert.notProperty(unrestricted.settings, "disableAutoMode");
3666
+ assert.deepEqual(unrestricted.settings.permissions, { allow: [] });
3667
+ assert.equal(unrestricted.settings.env?.KEPT, "1");
3668
+ const restricted = yield* openWith({
3669
+ disableAutoMode: false,
3670
+ permissions: { disableBypassPermissionsMode: "disable", disableAutoMode: "disable" },
3671
+ });
3672
+ assert.equal(restricted.permissionMode, "default");
3673
+ assert.notProperty(restricted.settings, "disableAutoMode");
3674
+ assert.deepEqual(restricted.settings.permissions, {
3675
+ disableBypassPermissionsMode: "disable",
3676
+ disableAutoMode: "disable",
3677
+ });
3678
+ }).pipe(
3679
+ Effect.provide(
3680
+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
3681
+ ),
3682
+ ),
3683
+ );
3684
+
3685
it.effect("asks before restricted Full access tools and follows policy across turns", () =>
3686
Effect.gen(function* () {
3687
const resolveSettings = vi
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+43
-6
@@ -2596,12 +2596,12 @@ export function claudeRuntimeQueryPolicyForRuntimePolicy(
2596
2597
const ClaudeBypassSettings = Schema.StructWithRest(
2598
Schema.Struct({
2599
- disableAutoMode: Schema.optionalKey(Schema.Literal("disable")),
2599
+ disableAutoMode: Schema.optionalKey(Schema.Literals(["disable", false])),
2600
permissions: Schema.optionalKey(
2601
Schema.StructWithRest(
2602
Schema.Struct({
2603
- disableBypassPermissionsMode: Schema.optionalKey(Schema.Literal("disable")),
2604
- disableAutoMode: Schema.optionalKey(Schema.Literal("disable")),
2603
+ disableBypassPermissionsMode: Schema.optionalKey(Schema.Literals(["disable", false])),
2604
+ disableAutoMode: Schema.optionalKey(Schema.Literals(["disable", false])),
2605
}),
2606
[Schema.Record(Schema.String, Schema.Unknown)],
2607
),
@@ -2614,6 +2614,39 @@ const decodeClaudeBypassSettings = Schema.decodeUnknownEffect(
2614
);
2615
const decodeClaudeLaunchArgBypassSettings = Schema.decodeUnknownEffect(ClaudeBypassSettings);
2616
2617
+function claudeSdkBypassSettings(settings: typeof ClaudeBypassSettings.Type) {
2618
+ const { disableAutoMode, permissions, ...rest } = settings;
2619
+ const {
2620
+ disableBypassPermissionsMode,
2621
+ disableAutoMode: nestedAutoMode,
2622
+ ...permissionRest
2623
+ } = permissions ?? {};
2624
+ return {
2625
+ ...rest,
2626
+ ...(disableAutoMode === "disable" ? { disableAutoMode } : {}),
2627
+ ...(permissions
2628
+ ? {
2629
+ permissions: {
2630
+ ...permissionRest,
2631
+ ...(disableBypassPermissionsMode === "disable" ? { disableBypassPermissionsMode } : {}),
2632
+ ...(nestedAutoMode === "disable" ? { disableAutoMode: nestedAutoMode } : {}),
2633
+ },
2634
+ }
2635
+ : {}),
2636
+ };
2637
+}
2638
+
2639
+// --settings travels to the SDK as options.settings, whose type only allows "disable".
2640
+// Shapes the schema rejects keep their current pass-through; resolveBypassAvailability
2641
+// already treats them as a bypass failure.
2642
+const decodeClaudeLaunchArgBypassSettingsOption = Schema.decodeUnknownOption(ClaudeBypassSettings);
2643
+function claudeSdkLaunchArgSettings(settings: ClaudeSdkSettings): ClaudeSdkSettings {
2644
+ const decoded = decodeClaudeLaunchArgBypassSettingsOption(settings);
2645
+ return Option.isNone(decoded)
2646
+ ? settings
2647
+ : (claudeSdkBypassSettings(decoded.value) as ClaudeSdkSettings);
2648
+}
2649
+
2650
const ClaudePromptCacheTtl = Schema.Literals(["5m", "1h"]);
2651
const decodeClaudePromptCacheTtl = Schema.decodeUnknownOption(ClaudePromptCacheTtl);
2652
const decodeClaudeSubagentCacheSettings = Schema.decodeUnknownEffect(
@@ -4481,7 +4514,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
4514
const readBypassSettings = (filePath: string) =>
4515
fileSystem.readFileString(filePath).pipe(
4516
Effect.flatMap(decodeClaudeBypassSettings),
4484
- Effect.catchReason("PlatformError", "NotFound", () => Effect.succeed({})),
4517
+ Effect.catchReason("PlatformError", "NotFound", () =>
4518
+ Effect.succeed({} as typeof ClaudeBypassSettings.Type),
4519
+ ),
4520
);
4521
const resolveBypassAvailability = Effect.fn("ClaudeAdapterV2.resolveBypassAvailability")(
4522
function* (cwd: string | null) {
@@ -4495,7 +4530,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
4530
resolveClaudeSettings({
4531
...(cwd === null ? {} : { cwd }),
4532
settingSources: customHome ? ["project", "local"] : ["user", "project", "local"],
4498
- serverManagedSettings: remote,
4533
+ serverManagedSettings: claudeSdkBypassSettings(remote),
4534
}),
4535
);
4536
const launchArgSettings = yield* readClaudeLaunchArgSettings({
@@ -10173,7 +10208,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
10208
cwd: turnInput.runtimePolicy.cwd,
10209
attachmentsDir,
10210
settings: adapterOptions.settings,
10176
- ...(launchArgSettings === undefined ? {} : { sdkSettings: launchArgSettings }),
10211
+ ...(launchArgSettings === undefined
10212
+ ? {}
10213
+ : { sdkSettings: claudeSdkLaunchArgSettings(launchArgSettings) }),
10214
environment: claudeQueryEnvironment(
10215
adapterOptions.environment,
10216
turnInput.appThread,