Skip to content

Commit a7b4ef0

Browse files
committed
feat: control Remote Control per-thread from the composer toolbar
Moves the Remote Control toggle out of the composer banner and into the toolbar next to the Build/Plan switch, and extends it to already-created threads (not just new drafts) via a new setClaudeThreadRemoteControl RPC. Since Remote Control is a claude process launch flag, applying it to a thread with an active session stops that session so it relaunches with the flag on its next turn. Also adds a dismiss control to the "resuming a previous session" banner so it can be hidden without cancelling the resume, and fixes bindSessionLaunchOptions to merge onto an existing resumeCursor instead of overwriting it (so setting remoteControl on a thread that already has a resume cursor doesn't strand its continuity).
1 parent 8224188 commit a7b4ef0

11 files changed

Lines changed: 281 additions & 43 deletions

File tree

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

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import {
3737
type ServerGetClaudeResumableSessionTranscriptResult,
3838
type ServerListClaudeResumableSessionsInput,
3939
type ServerListClaudeResumableSessionsResult,
40+
type ServerSetClaudeThreadRemoteControlInput,
41+
type ServerSetClaudeThreadRemoteControlResult,
4042
type ThreadId,
4143
} from "@t3tools/contracts";
4244
import * as Context from "effect/Context";
@@ -53,6 +55,7 @@ import { resolveClaudeConfigDirPath } from "../Drivers/ClaudeSkills.ts";
5355
import { ProviderValidationError } from "../Errors.ts";
5456
import { deriveProviderInstanceConfigMap } from "./ProviderInstanceRegistryHydration.ts";
5557
import * as ProviderInstanceRegistry from "../Services/ProviderInstanceRegistry.ts";
58+
import { ProviderService } from "../Services/ProviderService.ts";
5659
import * as ProviderSessionDirectory from "../Services/ProviderSessionDirectory.ts";
5760
import type { ProviderSessionDirectoryWriteError } from "../Services/ProviderSessionDirectory.ts";
5861

@@ -236,7 +239,11 @@ export interface ClaudeSessionHistoryBindSessionLaunchOptionsInput {
236239
readonly providerInstanceId: ProviderInstanceId;
237240
/** Resume a picked on-disk session's model context via `--resume <uuid>`. */
238241
readonly resumeExternalSessionId?: string;
239-
/** Start the session with Claude Code's Remote Control (`--remote-control`) enabled. */
242+
/**
243+
* Start the session with Claude Code's Remote Control (`--remote-control`)
244+
* enabled, or explicitly disabled. `undefined` leaves whatever was
245+
* previously bound untouched (e.g. a plain resume-only call).
246+
*/
240247
readonly remoteControl?: boolean;
241248
}
242249

@@ -265,6 +272,20 @@ export class ClaudeSessionHistory extends Context.Service<
265272
readonly bindSessionLaunchOptions: (
266273
input: ClaudeSessionHistoryBindSessionLaunchOptionsInput,
267274
) => Effect.Effect<void, ProviderValidationError | ProviderSessionDirectoryWriteError>;
275+
/**
276+
* Turns Remote Control on/off for an already-created thread. Unlike
277+
* `bindSessionLaunchOptions` (thread-creation time only), this can run
278+
* against a thread with an active running session — Remote Control is a
279+
* `claude` process launch flag, not something a running process can be
280+
* told to flip live, so this stops the thread's active session (if any)
281+
* after binding the choice, so it relaunches with the flag applied on
282+
* its next turn. Best-effort/non-fatal: `applied: false` on a bind
283+
* failure (e.g. non-Claude instance); a stop failure or no active
284+
* session never fails the call, since the bind itself already took.
285+
*/
286+
readonly setThreadRemoteControl: (
287+
input: ServerSetClaudeThreadRemoteControlInput,
288+
) => Effect.Effect<ServerSetClaudeThreadRemoteControlResult>;
268289
}
269290
>()("t3/provider/Layers/ClaudeSessionHistory") {}
270291

@@ -273,6 +294,7 @@ export const make = Effect.gen(function* () {
273294
const path = yield* Path.Path;
274295
const providerInstanceRegistry = yield* ProviderInstanceRegistry.ProviderInstanceRegistry;
275296
const providerSessionDirectory = yield* ProviderSessionDirectory.ProviderSessionDirectory;
297+
const providerService = yield* ProviderService;
276298
const serverSettings = yield* ServerSettingsService;
277299

278300
// Claude instances can be configured with a custom `homePath` (keeping
@@ -400,7 +422,7 @@ export const make = Effect.gen(function* () {
400422

401423
const bindSessionLaunchOptions: ClaudeSessionHistory["Service"]["bindSessionLaunchOptions"] =
402424
Effect.fn("ClaudeSessionHistory.bindSessionLaunchOptions")(function* (input) {
403-
if (input.resumeExternalSessionId === undefined && !input.remoteControl) {
425+
if (input.resumeExternalSessionId === undefined && input.remoteControl === undefined) {
404426
return;
405427
}
406428
if (
@@ -425,20 +447,55 @@ export const make = Effect.gen(function* () {
425447
issue: `Resume/Remote Control are only supported for Claude Code provider instances; '${input.providerInstanceId}' is a '${instance.driverKind}' instance.`,
426448
});
427449
}
450+
// Merge onto whatever's already bound (rather than replacing
451+
// wholesale) — this can now be called on a thread that already has a
452+
// `resume` cursor from a prior turn (e.g. toggling Remote Control on
453+
// an existing, already-running thread), and clobbering that would
454+
// strand the thread's actual Claude session continuity.
455+
const existingBinding = yield* providerSessionDirectory.getBinding(input.threadId);
456+
const existingResumeCursor = Option.getOrUndefined(existingBinding)?.resumeCursor;
457+
const existingResumeCursorFields =
458+
existingResumeCursor !== null &&
459+
typeof existingResumeCursor === "object" &&
460+
existingResumeCursor !== undefined
461+
? (existingResumeCursor as Record<string, unknown>)
462+
: {};
428463
yield* providerSessionDirectory.upsert({
429464
threadId: input.threadId,
430465
provider: instance.driverKind,
431466
providerInstanceId: input.providerInstanceId,
432467
resumeCursor: {
468+
...existingResumeCursorFields,
433469
...(input.resumeExternalSessionId !== undefined
434470
? { resume: input.resumeExternalSessionId }
435471
: {}),
436-
...(input.remoteControl ? { remoteControl: true } : {}),
472+
...(input.remoteControl !== undefined ? { remoteControl: input.remoteControl } : {}),
437473
},
438474
});
439475
});
440476

441-
return ClaudeSessionHistory.of({ list, getTranscript, bindSessionLaunchOptions });
477+
const setThreadRemoteControl: ClaudeSessionHistory["Service"]["setThreadRemoteControl"] =
478+
Effect.fn("ClaudeSessionHistory.setThreadRemoteControl")(function* (input) {
479+
const bindResult = yield* bindSessionLaunchOptions({
480+
threadId: input.threadId,
481+
providerInstanceId: input.providerInstanceId,
482+
remoteControl: input.enabled,
483+
}).pipe(Effect.result);
484+
if (bindResult._tag === "Failure") {
485+
return { applied: false };
486+
}
487+
yield* providerService
488+
.stopSession({ threadId: input.threadId })
489+
.pipe(Effect.catch(() => Effect.void));
490+
return { applied: true };
491+
});
492+
493+
return ClaudeSessionHistory.of({
494+
list,
495+
getTranscript,
496+
bindSessionLaunchOptions,
497+
setThreadRemoteControl,
498+
});
442499
});
443500

444501
export const layer = Layer.effect(ClaudeSessionHistory, make);

‎apps/server/src/server.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ const buildAppUnderTest = (options?: {
614614
list: () => Effect.succeed({ sessions: [] }),
615615
getTranscript: () => Effect.succeed({ messages: [] }),
616616
bindSessionLaunchOptions: () => Effect.void,
617+
setThreadRemoteControl: () => Effect.succeed({ applied: true }),
617618
}),
618619
),
619620
),

‎apps/server/src/ws.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ const RPC_REQUIRED_SCOPE = new Map<string, AuthEnvironmentScope>([
309309
[WS_METHODS.serverGetProcessResourceHistory, AuthOrchestrationReadScope],
310310
[WS_METHODS.serverListClaudeResumableSessions, AuthOrchestrationReadScope],
311311
[WS_METHODS.serverGetClaudeResumableSessionTranscript, AuthOrchestrationReadScope],
312+
[WS_METHODS.serverSetClaudeThreadRemoteControl, AuthOrchestrationOperateScope],
312313
[WS_METHODS.serverSignalProcess, AuthOrchestrationOperateScope],
313314
[WS_METHODS.cloudGetRelayClientStatus, AuthRelayWriteScope],
314315
[WS_METHODS.cloudInstallRelayClient, AuthRelayWriteScope],
@@ -1583,6 +1584,14 @@ const makeWsRpcLayer = (
15831584
"rpc.aggregate": "server",
15841585
},
15851586
),
1587+
[WS_METHODS.serverSetClaudeThreadRemoteControl]: (input) =>
1588+
observeRpcEffect(
1589+
WS_METHODS.serverSetClaudeThreadRemoteControl,
1590+
claudeSessionHistory.setThreadRemoteControl(input),
1591+
{
1592+
"rpc.aggregate": "server",
1593+
},
1594+
),
15861595
[WS_METHODS.serverSignalProcess]: (input) =>
15871596
observeRpcEffect(WS_METHODS.serverSignalProcess, processDiagnostics.signal(input), {
15881597
"rpc.aggregate": "server",

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 83 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ import {
145145
ChevronDownIcon,
146146
GitBranchIcon,
147147
HistoryIcon,
148-
RadioTowerIcon,
149148
TriangleAlertIcon,
150149
WifiOffIcon,
151150
} from "lucide-react";
@@ -239,7 +238,6 @@ import {
239238
import { ThreadErrorBanner } from "./chat/ThreadErrorBanner";
240239
import { resolveThreadPr } from "./ThreadStatusIndicators";
241240
import { ComposerBannerStack, type ComposerBannerStackItem } from "./chat/ComposerBannerStack";
242-
import { Switch } from "./ui/switch";
243241
import {
244242
DRAFT_HERO_TRANSITION_ANIMATION_ID,
245243
DRAFT_HERO_TRANSITION_DURATION_MS,
@@ -1143,6 +1141,10 @@ function ChatViewContent(props: ChatViewProps) {
11431141
const upsertKeybinding = useAtomCommand(serverEnvironment.upsertKeybinding, {
11441142
reportFailure: false,
11451143
});
1144+
const setClaudeThreadRemoteControl = useAtomCommand(
1145+
serverEnvironment.setClaudeThreadRemoteControl,
1146+
{ reportFailure: false },
1147+
);
11461148
const openTerminal = useAtomCommand(terminalEnvironment.open, "terminal open");
11471149
const writeTerminal = useAtomCommand(terminalEnvironment.write, "terminal write");
11481150
const closeTerminalMutation = useAtomCommand(terminalEnvironment.close, "terminal close");
@@ -1289,11 +1291,17 @@ function ChatViewContent(props: ChatViewProps) {
12891291
>({});
12901292
const [pendingServerThreadEnvMode, setPendingServerThreadEnvMode] =
12911293
useState<DraftThreadEnvMode | null>(null);
1292-
// Remote Control can only be decided once, at thread creation — it's a
1293-
// launch flag for the session's underlying `claude` process, not
1294-
// something that can be toggled after it's already running. Reset
1295-
// whenever the viewed thread changes so it never leaks between drafts.
1296-
const [draftRemoteControlEnabled, setDraftRemoteControlEnabled] = useState(false);
1294+
// Remote Control is a launch flag for the session's underlying `claude`
1295+
// process, not something a running process can be told to flip live. For
1296+
// a draft thread this is just picked up at send time (see
1297+
// `bootstrap.createThread.remoteControl` below). For an existing thread
1298+
// it's applied via `setClaudeThreadRemoteControl`, which stops the
1299+
// thread's active session so it relaunches with the flag on its next
1300+
// turn. Local display state only — reset per thread since there's no
1301+
// read-path yet for whatever's actually bound server-side.
1302+
const [remoteControlEnabled, setRemoteControlEnabled] = useState(false);
1303+
const [remoteControlPending, setRemoteControlPending] = useState(false);
1304+
const [resumeBannerHidden, setResumeBannerHidden] = useState(false);
12971305
const [pendingServerThreadBranch, setPendingServerThreadBranch] = useState<string | null>();
12981306
const [
12991307
pendingServerThreadStartFromOriginByThreadId,
@@ -4134,6 +4142,45 @@ function ChatViewContent(props: ChatViewProps) {
41344142
}
41354143
void handleSwitchCheckoutToThread();
41364144
}, [gitStatusQuery.data?.hasWorkingTreeChanges, handleSwitchCheckoutToThread]);
4145+
const handleToggleRemoteControl = useCallback(
4146+
async (nextEnabled: boolean) => {
4147+
setRemoteControlEnabled(nextEnabled);
4148+
if (isLocalDraftThread || !activeThread) {
4149+
// Draft threads only pick this up at send time (see
4150+
// `bootstrap.createThread.remoteControl`) — nothing to call yet.
4151+
return;
4152+
}
4153+
setRemoteControlPending(true);
4154+
const result = await setClaudeThreadRemoteControl({
4155+
environmentId,
4156+
input: {
4157+
threadId: activeThread.id,
4158+
providerInstanceId: activeThread.modelSelection.instanceId,
4159+
enabled: nextEnabled,
4160+
},
4161+
});
4162+
setRemoteControlPending(false);
4163+
if (result._tag === "Failure") {
4164+
setRemoteControlEnabled(!nextEnabled);
4165+
toastManager.add(
4166+
stackedThreadToast({
4167+
type: "error",
4168+
title: "Couldn't update Remote Control",
4169+
description: "Something went wrong applying the change. Try again.",
4170+
}),
4171+
);
4172+
return;
4173+
}
4174+
toastManager.add(
4175+
stackedThreadToast({
4176+
type: "success",
4177+
title: nextEnabled ? "Remote Control enabled" : "Remote Control disabled",
4178+
description: "Applies the next time this thread's session starts.",
4179+
}),
4180+
);
4181+
},
4182+
[isLocalDraftThread, activeThread, environmentId, setClaudeThreadRemoteControl],
4183+
);
41374184
const pendingResumeSessionIntent = useResumeSessionIntentStore((store) =>
41384185
isLocalDraftThread && activeThread ? (store.intentByThreadId[activeThread.id] ?? null) : null,
41394186
);
@@ -4152,6 +4199,7 @@ function ChatViewContent(props: ChatViewProps) {
41524199
}, []);
41534200
const resumeSessionBannerItem = useMemo<ComposerBannerStackItem | null>(() => {
41544201
if (!pendingResumeSessionIntent || !isLocalDraftThread || !activeThread) return null;
4202+
if (resumeBannerHidden) return null;
41554203
const draftThreadId = activeThread.id;
41564204
return {
41574205
id: `resume-session:${pendingResumeSessionIntent.resumeExternalSessionId}`,
@@ -4164,43 +4212,31 @@ function ChatViewContent(props: ChatViewProps) {
41644212
Cancel
41654213
</Button>
41664214
),
4215+
// Hides the banner without cancelling the resume — the resume still
4216+
// happens on send. Kept separate from the `actions` Cancel button
4217+
// above (which does cancel) via the same deferred-animation path
4218+
// already used for the branch-mismatch banner below: unlike Cancel,
4219+
// hiding isn't correctness-critical, so the 220ms dismiss race is
4220+
// harmless here.
4221+
dismissLabel: "Hide (still resumes on send)",
4222+
onDismiss: () => setResumeBannerHidden(true),
41674223
};
4168-
}, [pendingResumeSessionIntent, isLocalDraftThread, activeThread, cancelResumeSessionIntent]);
4169-
const canOfferRemoteControlToggle =
4170-
isLocalDraftThread && selectedProvider === ProviderDriverKind.make("claudeAgent");
4171-
const remoteControlBannerItem = useMemo<ComposerBannerStackItem | null>(() => {
4172-
if (!canOfferRemoteControlToggle) return null;
4173-
return {
4174-
id: "draft-remote-control",
4175-
variant: "info",
4176-
icon: <RadioTowerIcon />,
4177-
title: "Remote Control",
4178-
description: "Attach to this session from claude.ai or the Claude mobile app once it starts.",
4179-
actions: (
4180-
<Switch
4181-
checked={draftRemoteControlEnabled}
4182-
onCheckedChange={(checked) => setDraftRemoteControlEnabled(Boolean(checked))}
4183-
aria-label="Enable Remote Control for this session"
4184-
/>
4185-
),
4186-
};
4187-
}, [canOfferRemoteControlToggle, draftRemoteControlEnabled]);
4224+
}, [
4225+
pendingResumeSessionIntent,
4226+
isLocalDraftThread,
4227+
activeThread,
4228+
resumeBannerHidden,
4229+
cancelResumeSessionIntent,
4230+
]);
41884231
const composerBannerItems = useMemo<ComposerBannerStackItem[]>(() => {
41894232
const parkedThreadItems = parkedThreadBannerItem === null ? [] : [parkedThreadBannerItem];
41904233
const resumeSessionItems = resumeSessionBannerItem === null ? [] : [resumeSessionBannerItem];
4191-
const remoteControlItems = remoteControlBannerItem === null ? [] : [remoteControlBannerItem];
41924234
if (!localCheckoutBranchMismatch || !showBranchMismatchBanner || !activeBranchMismatchKey) {
4193-
return [
4194-
...systemComposerBannerItems,
4195-
...resumeSessionItems,
4196-
...remoteControlItems,
4197-
...parkedThreadItems,
4198-
];
4235+
return [...systemComposerBannerItems, ...resumeSessionItems, ...parkedThreadItems];
41994236
}
42004237
return [
42014238
...systemComposerBannerItems,
42024239
...resumeSessionItems,
4203-
...remoteControlItems,
42044240
{
42054241
id: `branch-mismatch:${activeBranchMismatchKey}`,
42064242
variant: "info",
@@ -4245,7 +4281,6 @@ function ChatViewContent(props: ChatViewProps) {
42454281
}, [
42464282
activeBranchMismatchKey,
42474283
resumeSessionBannerItem,
4248-
remoteControlBannerItem,
42494284
handleRestoreThreadBranch,
42504285
isRestoringThreadBranch,
42514286
localCheckoutBranchMismatch,
@@ -4260,7 +4295,11 @@ function ChatViewContent(props: ChatViewProps) {
42604295
}, [activeThread?.id]);
42614296

42624297
useEffect(() => {
4263-
setDraftRemoteControlEnabled(false);
4298+
setRemoteControlEnabled(false);
4299+
}, [activeThread?.id]);
4300+
4301+
useEffect(() => {
4302+
setResumeBannerHidden(false);
42644303
}, [activeThread?.id]);
42654304

42664305
useEffect(() => {
@@ -4843,7 +4882,7 @@ function ChatViewContent(props: ChatViewProps) {
48434882
worktreePath: activeThread.worktreePath,
48444883
createdAt: activeThread.createdAt,
48454884
...(resumeExternalSessionId ? { resumeExternalSessionId } : {}),
4846-
...(draftRemoteControlEnabled ? { remoteControl: true } : {}),
4885+
...(remoteControlEnabled ? { remoteControl: true } : {}),
48474886
},
48484887
}
48494888
: {}),
@@ -5933,6 +5972,12 @@ function ChatViewContent(props: ChatViewProps) {
59335972
planSidebarOpen={planSidebarOpen}
59345973
runtimeMode={runtimeMode}
59355974
interactionMode={interactionMode}
5975+
showRemoteControlToggle={
5976+
selectedProvider === ProviderDriverKind.make("claudeAgent")
5977+
}
5978+
remoteControlEnabled={remoteControlEnabled}
5979+
remoteControlPending={remoteControlPending}
5980+
onToggleRemoteControl={handleToggleRemoteControl}
59365981
lockedProvider={lockedProvider}
59375982
providerStatuses={providerStatuses as ServerProvider[]}
59385983
activeProjectDefaultModelSelection={

0 commit comments

Comments
 (0)