Skip to content

Commit 0808725

Browse files
maria-rcksclaude
andcommitted
fix(server): let Claude launch args override the derived permission mode
A `--dangerously-skip-permissions` or `--permission-mode` set in Claude provider launch args was appended after T3's own `--permission-mode`, and the CLI resolves its permission inputs together rather than by argv order, so the user's flag was silently inert. The adapter now reads a permission flag out of the parsed launch args, uses it as the session's permission mode, and drops it from `extraArgs` so the CLI receives the flag once. Threads without such a flag keep deriving the mode from their runtime mode. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent b7b3ef1 commit 0808725

2 files changed

Lines changed: 79 additions & 2 deletions

File tree

‎apps/server/src/provider/Layers/ClaudeAdapter.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,29 @@ describe("ClaudeAdapterLive", () => {
422422
);
423423
});
424424

425+
it.effect("lets a launch-arg permission flag win over the thread runtime mode", () => {
426+
const harness = makeHarness({
427+
claudeConfig: { launchArgs: "--dangerously-skip-permissions --verbose" },
428+
});
429+
return Effect.gen(function* () {
430+
const adapter = yield* ClaudeAdapter;
431+
yield* adapter.startSession({
432+
threadId: THREAD_ID,
433+
provider: ProviderDriverKind.make("claudeAgent"),
434+
runtimeMode: "auto-accept-edits",
435+
});
436+
437+
const createInput = harness.getLastCreateQueryInput();
438+
assert.equal(createInput?.options.permissionMode, "bypassPermissions");
439+
assert.equal(createInput?.options.allowDangerouslySkipPermissions, true);
440+
// The honored flag is dropped from extraArgs so the CLI sees it once.
441+
assert.deepEqual(createInput?.options.extraArgs, { verbose: null });
442+
}).pipe(
443+
Effect.provideService(Random.Random, makeDeterministicRandomService()),
444+
Effect.provide(harness.layer),
445+
);
446+
});
447+
425448
it.effect("loads Claude filesystem settings sources for SDK sessions", () => {
426449
const harness = makeHarness();
427450
return Effect.gen(function* () {

‎apps/server/src/provider/Layers/ClaudeAdapter.ts‎

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,51 @@ const CLAUDE_SETTING_SOURCES = [
14191419
"local",
14201420
] as const satisfies ReadonlyArray<SettingSource>;
14211421

1422+
const CLAUDE_PERMISSION_MODES = [
1423+
"default",
1424+
"acceptEdits",
1425+
"bypassPermissions",
1426+
"plan",
1427+
"dontAsk",
1428+
"auto",
1429+
] as const satisfies ReadonlyArray<PermissionMode>;
1430+
1431+
/**
1432+
* Launch-arg flag names that ask the Claude CLI for a permission mode. The CLI
1433+
* treats `--dangerously-skip-permissions` as a request for `bypassPermissions`,
1434+
* so it collides with the `--permission-mode` the SDK emits for the thread's
1435+
* runtime mode.
1436+
*/
1437+
const CLAUDE_PERMISSION_LAUNCH_ARGS: ReadonlySet<string> = new Set([
1438+
"permission-mode",
1439+
"dangerously-skip-permissions",
1440+
]);
1441+
1442+
/**
1443+
* Permission mode a user pinned through provider launch args, if any.
1444+
*
1445+
* The CLI resolves the mode from all of its inputs at once rather than from
1446+
* argv order, so appending the user's flag after ours left it inert. Reading it
1447+
* here lets the explicit arg win, and keeps the mode in one place: the SDK
1448+
* emits `--permission-mode` once (see the caller dropping these keys from
1449+
* `extraArgs`), `session.configured` reports the real mode, and leaving plan
1450+
* mode restores it.
1451+
*/
1452+
function readLaunchArgPermissionMode(
1453+
flags: Record<string, string | null>,
1454+
): PermissionMode | undefined {
1455+
const explicit = flags["permission-mode"];
1456+
if (typeof explicit === "string") {
1457+
const mode = explicit.trim();
1458+
// An unrecognized value stays in `extraArgs` so the CLI rejects it, rather
1459+
// than being silently swapped for the runtime mode's own flag.
1460+
return (CLAUDE_PERMISSION_MODES as ReadonlyArray<string>).includes(mode)
1461+
? (mode as PermissionMode)
1462+
: undefined;
1463+
}
1464+
return "dangerously-skip-permissions" in flags ? "bypassPermissions" : undefined;
1465+
}
1466+
14221467
function buildPromptText(
14231468
input: ProviderSendTurnInput,
14241469
boundInstanceId: ProviderInstanceId,
@@ -4608,7 +4653,13 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
46084653
) => runPromise(handleResumeDialog(request, callbackOptions));
46094654

46104655
const claudeBinaryPath = claudeSdkExecutablePath;
4611-
const extraArgs = parseCliArgs(claudeSettings.launchArgs).flags;
4656+
const launchArgs = parseCliArgs(claudeSettings.launchArgs).flags;
4657+
const launchArgPermissionMode = readLaunchArgPermissionMode(launchArgs);
4658+
const extraArgs = launchArgPermissionMode
4659+
? Object.fromEntries(
4660+
Object.entries(launchArgs).filter(([flag]) => !CLAUDE_PERMISSION_LAUNCH_ARGS.has(flag)),
4661+
)
4662+
: launchArgs;
46124663
const selectedModel =
46134664
input.modelSelection?.instanceId === boundInstanceId ? input.modelSelection : undefined;
46144665
const modelSelection = selectedModel
@@ -4649,7 +4700,10 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (
46494700
auto: "auto",
46504701
"full-access": "bypassPermissions",
46514702
};
4652-
const permissionMode = runtimeModeToPermission[input.runtimeMode];
4703+
// An explicit launch arg wins over the thread's runtime mode: the CLI
4704+
// would otherwise resolve the two conflicting inputs on its own and leave
4705+
// the user's flag inert.
4706+
const permissionMode = launchArgPermissionMode ?? runtimeModeToPermission[input.runtimeMode];
46534707
const settings = {
46544708
...(typeof thinking === "boolean" ? { alwaysThinkingEnabled: thinking } : {}),
46554709
...(fastMode ? { fastMode: true } : {}),

0 commit comments

Comments
 (0)