@devries-cameron20 / t3code-1 / commits / fd63914c77
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): show why Claude refuses full access as root (#23804)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 2, 2026 at 18:52 UTC fd63914c77c844df1e011eef26c1f12bb61ed944
3 files changed +107 -4
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+64 -4
@@ -123,6 +123,7 @@ import * as Context from "effect/Context";
123 import * as SecureRandom from "effect/crypto/SecureRandom";
124 import * as DateTime from "effect/DateTime";
125 import * as Deferred from "effect/Deferred";
126 +import * as Duration from "effect/Duration";
127 import * as Effect from "effect/Effect";
128 import * as Equal from "effect/Equal";
129 import * as Exit from "effect/Exit";
@@ -338,6 +339,13 @@ const WORKFLOW_MEMBER_TRANSCRIPT_FLUSH_MS = 500;
339 const BACKGROUND_MOVE_TIMEOUT_MS = 5_000;
340 // How long a Stop waits for the CLI to exit before the user is offered Force stop.
341 const CLAUDE_STOP_CONFIRM_TIMEOUT_MS = 10_000;
342 +// Matches the stderr tail the SDK keeps for a CLI it spawns itself.
343 +const CLAUDE_STDERR_TAIL_LENGTH = 2_048;
344 +// The process group is killed on exit, so its stderr closes promptly.
345 +const CLAUDE_STDERR_DRAIN_TIMEOUT = Duration.seconds(1);
346 +// Claude Code's refusal of bypassPermissions as root, which it explains only on stderr.
347 +const CLAUDE_ROOT_REFUSAL =
348 + "--dangerously-skip-permissions cannot be used with root/sudo privileges for security reasons";
349
350 const CLAUDE_GROUP_WATCH_SCRIPT = [
351 "{ trap '' TERM; read -r _ <&3; kill -TERM 0; sleep 5; kill -KILL 0; } </dev/null >/dev/null 2>&1 &",
@@ -352,6 +360,8 @@ const CLAUDE_GROUP_WATCH_SCRIPT = [
360 export function spawnClaudeProcessGroup(
361 options: ClaudeSpawnOptions,
362 onExit?: () => void,
363 + onStderr: (text: string) => void = () => {},
364 + onStderrClose: () => void = () => {},
365 ): ClaudeSpawnedProcess {
366 const child = NodeChildProcess.spawn(
367 "/bin/sh",
@@ -360,10 +370,12 @@ export function spawnClaudeProcessGroup(
370 cwd: options.cwd,
371 env: options.env,
372 signal: options.signal,
363 - stdio: ["pipe", "pipe", "ignore", "pipe"],
373 + stdio: ["pipe", "pipe", "pipe", "pipe"],
374 detached: true,
375 },
376 );
377 + // Always drained, so a chatty CLI never blocks on a full stderr pipe.
378 + child.stderr?.setEncoding("utf8").on("data", onStderr).once("close", onStderrClose);
379 child.once("exit", () => {
380 try {
381 signalProcessGroup(child.pid ?? 0, "SIGKILL");
@@ -558,6 +570,17 @@ export class ClaudeAgentSdkQueryRunnerError extends Schema.TaggedError<ClaudeAge
570 }
571 }
572
573 +export class ClaudeCodeRootRefusalError extends Schema.TaggedError<ClaudeCodeRootRefusalError>()(
574 + "ClaudeCodeRootRefusalError",
575 + {
576 + cause: Schema.Defect(),
577 + },
578 +) {
579 + override get message(): string {
580 + return `Claude Code exited before it started: ${CLAUDE_ROOT_REFUSAL}`;
581 + }
582 +}
583 +
584 class ClaudeMcpRegistrationTimeoutError extends Schema.TaggedError<ClaudeMcpRegistrationTimeoutError>()(
585 "ClaudeMcpRegistrationTimeoutError",
586 {},
@@ -1009,10 +1032,25 @@ export const layerQueryRunner: Layer.Layer<
1032 const unit = launch?.unit;
1033 const stopScope =
1034 unit === undefined ? undefined : () => void runFork(agentScope.stop(unit));
1035 + // Only a CLI that fails before its first message explains itself on
1036 + // stderr. The known root refusal becomes a curated failure; any other
1037 + // stderr can hold private text, so it stays out of turn failures.
1038 + let stderrTail = "";
1039 + let stderrClosed: Promise<void> = Promise.resolve();
1040 + let answered = false;
1041 + const appendStderr = (text: string) => {
1042 + if (answered) return;
1043 + stderrTail = (stderrTail + text).slice(-CLAUDE_STDERR_TAIL_LENGTH);
1044 + };
1045 const spawnProcess =
1046 options.spawnClaudeCodeProcess ??
1047 ((spawnOptions: ClaudeSpawnOptions) => {
1015 - if (platform !== "win32") return spawnClaudeProcessGroup(spawnOptions, stopScope);
1048 + if (platform !== "win32") {
1049 + // Node can report "exit" before it has read the stderr the CLI wrote.
1050 + let stderrDone = () => {};
1051 + stderrClosed = new Promise((resolve) => (stderrDone = resolve));
1052 + return spawnClaudeProcessGroup(spawnOptions, stopScope, appendStderr, stderrDone);
1053 + }
1054 const child = NodeChildProcess.spawn(spawnOptions.command, spawnOptions.args, {
1055 cwd: spawnOptions.cwd,
1056 env: spawnOptions.env,
@@ -1132,9 +1170,31 @@ export const layerQueryRunner: Layer.Layer<
1170 );
1171
1172 return {
1135 - messages: Stream.fromAsyncIterable(claudeQueryMessages(queryRuntime), (cause) =>
1136 - queryRunnerError(cause, "fromAsyncIterable"),
1173 + messages: Stream.fromAsyncIterable(
1174 + claudeQueryMessages(queryRuntime),
1175 + (cause) => cause,
1176 ).pipe(
1177 + Stream.catch((cause) =>
1178 + Stream.fromEffect(
1179 + Effect.gen(function* () {
1180 + if (!answered) {
1181 + yield* Effect.promise(() => stderrClosed).pipe(
1182 + Effect.timeoutOption(CLAUDE_STDERR_DRAIN_TIMEOUT),
1183 + );
1184 + }
1185 + const refusedRoot = !answered && stderrTail.includes(CLAUDE_ROOT_REFUSAL);
1186 + return yield* queryRunnerError(
1187 + refusedRoot ? new ClaudeCodeRootRefusalError({ cause }) : cause,
1188 + "fromAsyncIterable",
1189 + );
1190 + }),
1191 + ),
1192 + ),
1193 + Stream.tap(() =>
1194 + Effect.sync(() => {
1195 + answered = true;
1196 + }),
1197 + ),
1198 Stream.tap((message) =>
1199 logProtocolEvent({
1200 direction: "incoming",
apps/server/src/orchestration-v2/Adapters/ClaudeAgentSdkQueryRunner.test.ts
+42
@@ -17,6 +17,7 @@ import * as Fiber from "effect/Fiber";
17 import * as FileSystem from "effect/FileSystem";
18 import * as Layer from "effect/Layer";
19 import * as Path from "effect/Path";
20 +import * as Stream from "effect/Stream";
21 import * as TestClock from "effect/testing/TestClock";
22 import { vi } from "vite-plus/test";
23
@@ -546,6 +547,47 @@ describe.skipIf(HostProcess.Platform.defaultValue() === "win32")("Claude CLI pro
547 }),
548 );
549
550 + const rootRefusal =
551 + "--dangerously-skip-permissions cannot be used with root/sudo privileges for security reasons";
552 +
553 + const startupFailureMessage = (stderr: string) =>
554 + Effect.gen(function* () {
555 + const cli = fakeClaudeCli(`printf '%s\\n' '${stderr}' >&2\nexit 1`);
556 + yield* Effect.addFinalizer(() =>
557 + Effect.sync(() => NodeFS.rmSync(NodePath.dirname(cli), { recursive: true, force: true })),
558 + );
559 + const session = yield* openFakeCli(cli);
560 + const exit = yield* Stream.runDrain(session.messages).pipe(Effect.exit);
561 + assert.isTrue(Exit.isFailure(exit));
562 + return Exit.isFailure(exit)
563 + ? makeProviderFailure({ cause: exit.cause, class: "transport_error" }).message
564 + : "";
565 + });
566 +
567 + // Claude Code refuses bypassPermissions as root and explains why only on
568 + // stderr, so the turn failure has to carry that line.
569 + it.effect("reports the CLI's root refusal when it exits before answering", () =>
570 + Effect.gen(function* () {
571 + assert.include(yield* startupFailureMessage(rootRefusal), rootRefusal);
572 + }).pipe(Effect.provide(realQueryRunner)),
573 + );
574 +
575 + // Startup stderr can carry paths, tokens, or settings, so only the known
576 + // refusal reaches the failure the client shows.
577 + it.effect("keeps other startup stderr out of the turn failure", () =>
578 + Effect.gen(function* () {
579 + const surrounded = yield* startupFailureMessage(
580 + `token=sk-private-123\n${rootRefusal}\nat /home/private/settings.json`,
581 + );
582 + assert.include(surrounded, rootRefusal);
583 + assert.notInclude(surrounded, "sk-private-123");
584 + assert.notInclude(surrounded, "/home/private");
585 +
586 + const unknown = yield* startupFailureMessage("token=sk-private-123");
587 + assert.notInclude(unknown, "sk-private-123");
588 + }).pipe(Effect.provide(realQueryRunner)),
589 + );
590 +
591 // The CLI keeps running its turn after its pipes close, so a server that
592 // crashed would leave it working next to the session it resumes.
593 it.effect("stops the CLI when the server that started it goes away", () =>
packages/provider-core/src/server/failure.ts
+1
@@ -111,6 +111,7 @@ function curatedCauseMessages(cause: unknown): {
111 case "ClaudeAppendSystemPromptMissingValueError":
112 case "ClaudeSettingsLaunchArgError":
113 case "ClaudeMcpRegistrationTimeoutError":
114 + case "ClaudeCodeRootRefusalError":
115 case "CursorModelUnavailableError":
116 case "CodexGoalObjectiveTooLongError":
117 case "ProviderSetupError":