Skip to content

Commit ed9d75a

Browse files
feat(server,web,mobile): approvals in full access say why Claude asked
Claude Code still asks in bypass mode when one of its own safety checks or a user ask rule fires. The card looked like an ordinary approval, so a full-access thread seemed broken. The approval item now carries the CLI's reason and whether a user ask rule or Claude Code's own check forced it, and drops the standing grant when Claude Code forbids one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5d27ecd commit ed9d75a

8 files changed

Lines changed: 138 additions & 1 deletion

File tree

‎apps/mobile/src/features/threads/PendingApprovalCard.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
ProviderApprovalOption,
55
RuntimeRequestId,
66
} from "@t3tools/contracts";
7+
import { fullAccessOverrideLabel } from "@t3tools/client-runtime/state/thread-requests";
78
import { View } from "react-native";
89

910
import { AppText as Text } from "../../components/ui/AppText";
@@ -44,6 +45,18 @@ export function PendingApprovalCard(props: PendingApprovalCardProps) {
4445
{props.approval.detail}
4546
</Text>
4647
) : null}
48+
{props.approval.fullAccessOverride || props.approval.reason ? (
49+
<Text className="font-sans text-xs leading-normal text-warning-foreground">
50+
{[
51+
props.approval.fullAccessOverride
52+
? fullAccessOverrideLabel(props.approval.fullAccessOverride)
53+
: undefined,
54+
props.approval.reason,
55+
]
56+
.filter(Boolean)
57+
.join(": ")}
58+
</Text>
59+
) : null}
4760
{!canRespond ? (
4861
<Text className="font-sans text-sm leading-5 text-foreground-muted">
4962
The provider process for this request is no longer available. Interrupt or restart the run

‎apps/server/src/mcp/OrchestratorMcpService.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,9 @@ function turnItemText(item: OrchestrationV2TurnItem): string | null {
907907
case "web_search":
908908
return jsonText({ patterns: item.patterns, results: item.results });
909909
case "approval_request":
910-
return item.prompt ?? item.requestKind;
910+
return [item.prompt ?? item.requestKind, item.reason]
911+
.filter((line): line is string => line !== undefined)
912+
.join("\n");
911913
case "checkpoint":
912914
return jsonText(item.files);
913915
case "run_interrupt_request":

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,47 @@ describe("ClaudeAdapterV2 context usage", () => {
10281028
});
10291029
});
10301030

1031+
describe("ClaudeAdapterV2 approval presentation", () => {
1032+
it("marks asks that full access could not auto-allow and keeps the CLI's reason", () => {
1033+
const presentation = ClaudeAdapterV2.claudeApprovalPresentation({
1034+
permissionMode: "bypassPermissions",
1035+
prompt: 'Claude wants to run rm -r -- "$rr/$h"',
1036+
callbackOptions: {
1037+
decisionReason: "\u001b[33mDangerous rm on a path built from a variable\u001b[39m",
1038+
suppressAlwaysAllowRule: true,
1039+
},
1040+
});
1041+
assert.deepEqual(presentation, {
1042+
reason: "Dangerous rm on a path built from a variable",
1043+
fullAccessOverride: "provider_check",
1044+
options: [
1045+
{ decision: "decline", label: "Decline" },
1046+
{ decision: "accept", label: "Approve" },
1047+
],
1048+
});
1049+
});
1050+
1051+
it("attributes a bypass ask to the user's ask rule when one matched", () => {
1052+
const presentation = ClaudeAdapterV2.claudeApprovalPresentation({
1053+
permissionMode: "bypassPermissions",
1054+
prompt: "Claude wants to run git push",
1055+
callbackOptions: {
1056+
matchedAskRule: { source: "userSettings", toolName: "Bash", ruleContent: "git push:*" },
1057+
},
1058+
});
1059+
assert.deepEqual(presentation, { fullAccessOverride: "ask_rule" });
1060+
});
1061+
1062+
it("adds nothing to ordinary approvals outside full access", () => {
1063+
const presentation = ClaudeAdapterV2.claudeApprovalPresentation({
1064+
permissionMode: "default",
1065+
prompt: "Run make?",
1066+
callbackOptions: { decisionReason: "Run make?" },
1067+
});
1068+
assert.deepEqual(presentation, {});
1069+
});
1070+
});
1071+
10311072
describe("ClaudeAdapterV2 session permissions", () => {
10321073
it("keeps explicit user refusals classified as user_reject", () => {
10331074
const result = ClaudeAdapterV2.permissionResultFromDecision({

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import type {
5151
} from "@anthropic-ai/claude-agent-sdk/sdk-tools";
5252
// @effect-diagnostics-next-line nodeBuiltinImport:off -- the SDK takes a Node ChildProcess for the CLI.
5353
import * as NodeChildProcess from "node:child_process";
54+
import * as NodeUtil from "node:util";
5455
import { parseCliArgs } from "@t3tools/shared/cliArgs";
5556
import { fromLenientJson } from "@t3tools/shared/schemaJson";
5657
import { AgentScope } from "@t3tools/shared/AgentScope";
@@ -87,6 +88,8 @@ import {
8788
type OrchestrationV2TurnItem,
8889
type OrchestrationV2WebSearchResult,
8990
type ProviderApprovalDecision,
91+
type ProviderApprovalFullAccessOverride,
92+
type ProviderApprovalOption,
9093
ProviderDriverKind,
9194
type ProviderInstanceId,
9295
type ProviderRequestKind,
@@ -2794,6 +2797,45 @@ function parentToolUseIdFromSdkMessage(message: SDKMessage): string | null {
27942797
: null;
27952798
}
27962799

2800+
const CLAUDE_NO_STANDING_GRANT_OPTIONS = [
2801+
{ decision: "decline", label: "Decline" },
2802+
{ decision: "accept", label: "Approve" },
2803+
] satisfies ReadonlyArray<ProviderApprovalOption>;
2804+
2805+
export function claudeApprovalPresentation(input: {
2806+
readonly permissionMode: PermissionMode;
2807+
readonly prompt: string;
2808+
readonly callbackOptions: Pick<
2809+
Parameters<CanUseTool>[2],
2810+
"decisionReason" | "matchedAskRule" | "suppressAlwaysAllowRule"
2811+
>;
2812+
}): {
2813+
readonly reason?: string;
2814+
readonly fullAccessOverride?: ProviderApprovalFullAccessOverride;
2815+
readonly options?: ReadonlyArray<ProviderApprovalOption>;
2816+
} {
2817+
// The reason can carry terminal escapes from the CLI's own prompt renderer.
2818+
const reason = NodeUtil.stripVTControlCharacters(
2819+
input.callbackOptions.decisionReason ?? "",
2820+
).trim();
2821+
// Bypass auto-allows everything it can, so any ask that still reaches the
2822+
// callback is one bypass refused. The SDK drops the CLI's decision_reason_type,
2823+
// leaving the matched ask rule as the only way to tell the two causes apart.
2824+
const fullAccessOverride: ProviderApprovalFullAccessOverride | undefined =
2825+
input.permissionMode !== "bypassPermissions"
2826+
? undefined
2827+
: input.callbackOptions.matchedAskRule === undefined
2828+
? "provider_check"
2829+
: "ask_rule";
2830+
return {
2831+
...(reason === "" || reason === input.prompt ? {} : { reason }),
2832+
...(fullAccessOverride === undefined ? {} : { fullAccessOverride }),
2833+
...(input.callbackOptions.suppressAlwaysAllowRule === true
2834+
? { options: CLAUDE_NO_STANDING_GRANT_OPTIONS }
2835+
: {}),
2836+
};
2837+
}
2838+
27972839
export function permissionResultFromDecision(input: {
27982840
readonly toolName: string;
27992841
readonly decision: ProviderApprovalDecision;
@@ -6290,6 +6332,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
62906332
readonly nativeRequestId: string;
62916333
readonly requestKind: OrchestrationV2RuntimeRequest["kind"];
62926334
readonly prompt?: string;
6335+
readonly presentation?: ReturnType<typeof claudeApprovalPresentation>;
62936336
readonly questions?: ReadonlyArray<OrchestrationV2UserInputQuestion>;
62946337
}) {
62956338
const createdAt = yield* DateTime.now;
@@ -6374,6 +6417,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
63746417
requestId,
63756418
requestKind: input.requestKind as ProviderRequestKind,
63766419
...(input.prompt === undefined ? {} : { prompt: input.prompt }),
6420+
...input.presentation,
63776421
}
63786422
: {
63796423
type: "user_input_request" as const,
@@ -8861,6 +8905,11 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
88618905
nativeRequestId,
88628906
requestKind,
88638907
prompt,
8908+
presentation: claudeApprovalPresentation({
8909+
permissionMode: context.queryPolicy.permissionMode,
8910+
prompt,
8911+
callbackOptions,
8912+
}),
88648913
});
88658914
const decision = yield* Deferred.make<ProviderApprovalDecision, never>();
88668915
yield* Ref.update(pendingRuntimeRequests, (current) => {

‎apps/web/src/components/chat/ComposerPendingApprovalPanel.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { fullAccessOverrideLabel } from "@t3tools/client-runtime/state/thread-requests";
12
import { memo } from "react";
23
import { type PendingApproval } from "../../session-logic";
34
import { cn } from "~/lib/utils";
@@ -44,6 +45,11 @@ export const ComposerPendingApprovalPanel = memo(function ComposerPendingApprova
4445
<span className="flex w-full min-w-0 items-center gap-2 text-2xs text-muted-foreground">
4546
<span className="shrink-0 font-medium text-warning">{fallbackLabel}</span>
4647
{approval.appName ? <span className="min-w-0 truncate">{approval.appName}</span> : null}
48+
{approval.fullAccessOverride ? (
49+
<span className="min-w-0 truncate">
50+
{fullAccessOverrideLabel(approval.fullAccessOverride)}
51+
</span>
52+
) : null}
4753
{pendingCount > 1 ? (
4854
<span className="ml-auto shrink-0 tabular-nums">1/{pendingCount}</span>
4955
) : null}
@@ -63,6 +69,11 @@ export const ComposerPendingApprovalPanel = memo(function ComposerPendingApprova
6369
? "Provider process is gone — interrupt or restart the run to respond."
6470
: approval.detail || fallbackLabel}
6571
</Detail>
72+
{approval.reason ? (
73+
<span className="w-full min-w-0 text-2xs text-muted-foreground wrap-break-word">
74+
{approval.reason}
75+
</span>
76+
) : null}
6677
</span>
6778
);
6879
});

‎packages/client-runtime/src/state/threadRequests.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type {
22
OrchestrationV2ThreadProjection,
33
OrchestrationV2RuntimeRequest,
44
OrchestrationV2UserInputQuestion,
5+
ProviderApprovalFullAccessOverride,
56
ProviderApprovalOption,
67
ProviderRequestKind,
78
RuntimeRequestId,
@@ -13,11 +14,17 @@ export interface ThreadPendingApproval {
1314
readonly requestKind: ProviderRequestKind;
1415
readonly createdAt: string;
1516
readonly detail?: string;
17+
readonly reason?: string;
18+
readonly fullAccessOverride?: ProviderApprovalFullAccessOverride;
1619
readonly appName?: string;
1720
readonly options?: ReadonlyArray<ProviderApprovalOption>;
1821
readonly responseCapability: "live" | "not_resumable";
1922
}
2023

24+
export function fullAccessOverrideLabel(override: ProviderApprovalFullAccessOverride): string {
25+
return override === "ask_rule" ? "Your ask rule" : "Required even in full access";
26+
}
27+
2128
export interface ThreadUserInputQuestion extends Omit<
2229
OrchestrationV2UserInputQuestion,
2330
"multiSelect"
@@ -99,6 +106,10 @@ export function derivePendingThreadRequests(
99106
requestKind: request.kind,
100107
createdAt: DateTime.formatIso(request.createdAt),
101108
...(item?.type === "approval_request" && item.prompt ? { detail: item.prompt } : {}),
109+
...(item?.type === "approval_request" && item.reason ? { reason: item.reason } : {}),
110+
...(item?.type === "approval_request" && item.fullAccessOverride
111+
? { fullAccessOverride: item.fullAccessOverride }
112+
: {}),
102113
...(item?.type === "approval_request" && item.appName ? { appName: item.appName } : {}),
103114
...(item?.type === "approval_request" && item.options !== undefined
104115
? { options: item.options }

‎packages/contracts/src/orchestrationV2.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {
5555
} from "./threadPullRequest.ts";
5656
import {
5757
ProviderApprovalDecision,
58+
ProviderApprovalFullAccessOverride,
5859
ProviderApprovalOption,
5960
ProviderInteractionMode,
6061
ProviderRequestKind,
@@ -1429,6 +1430,8 @@ export const OrchestrationV2TurnItem = Schema.Union([
14291430
requestId: RuntimeRequestId,
14301431
requestKind: ProviderRequestKind,
14311432
prompt: Schema.optional(Schema.String),
1433+
reason: Schema.optional(Schema.String),
1434+
fullAccessOverride: Schema.optional(ProviderApprovalFullAccessOverride),
14321435
appName: Schema.optional(Schema.String),
14331436
options: Schema.optional(Schema.Array(ProviderApprovalOption)),
14341437
}),
@@ -2188,6 +2191,8 @@ export const OrchestrationV2TurnItemJson = Schema.Union([
21882191
requestId: RuntimeRequestId,
21892192
requestKind: ProviderRequestKind,
21902193
prompt: Schema.optional(Schema.String),
2194+
reason: Schema.optional(Schema.String),
2195+
fullAccessOverride: Schema.optional(ProviderApprovalFullAccessOverride),
21912196
appName: Schema.optional(Schema.String),
21922197
options: Schema.optional(Schema.Array(ProviderApprovalOption)),
21932198
}),

‎packages/contracts/src/providerPolicy.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ export const ProviderApprovalDecision = Schema.Literals([
5656
]);
5757
export type ProviderApprovalDecision = typeof ProviderApprovalDecision.Type;
5858

59+
// Why an approval reached the user although the thread runs with full access:
60+
// the user's own ask rule, or a check the provider enforces even when bypassed.
61+
export const ProviderApprovalFullAccessOverride = Schema.Literals(["ask_rule", "provider_check"]);
62+
export type ProviderApprovalFullAccessOverride = typeof ProviderApprovalFullAccessOverride.Type;
63+
5964
export const ProviderApprovalOption = Schema.Struct({
6065
decision: ProviderApprovalDecision,
6166
label: TrimmedNonEmptyString,

0 commit comments

Comments
 (0)