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

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

fix(mobile): configure another Claude account from Providers (#28928)

Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

shivam committed Nov 5, 2026 at 06:54 UTC e4e3657344e5ed70afd671e8d0ff5c2573f90f52
11 files changed +546 -63
apps/mobile/src/features/settings/ClaudeAccounts.tsx new
+252
@@ -0,0 +1,252 @@
1 +import type { MenuAction } from "@react-native-menu/menu";
2 +import {
3 + isAtomCommandInterrupted,
4 + squashAtomCommandFailure,
5 +} from "@t3tools/client-runtime/state/runtime";
6 +import {
7 + isManagedSettingPath,
8 + type ProviderInstanceId,
9 + type ProviderInstanceMutation,
10 + type ServerProvider,
11 +} from "@t3tools/contracts";
12 +import { useRef, useState } from "react";
13 +import { TextInput, View } from "react-native";
14 +
15 +import * as Dialog from "../../components/ui/Dialog";
16 +import { AppText as Text } from "../../components/ui/AppText";
17 +import { ControlPill } from "../../components/ui/ControlPill";
18 +import { ListActionRow } from "../../components/ui/ListActionRow";
19 +import { Menu } from "../../components/ui/Menu";
20 +import { serverEnvironment } from "../../state/server";
21 +import { useAtomCommand } from "../../state/use-atom-command";
22 +import {
23 + claudeConfigDir,
24 + DEFAULT_CLAUDE_INSTANCE_ID,
25 + planClaudeAccountSave,
26 + type ClaudeAccountDraft,
27 +} from "./claude-accounts";
28 +import type { SettingsTarget } from "./settings-environment-filter";
29 +
30 +function useProviderInstanceMutation(environment: SettingsTarget) {
31 + const mutate = useAtomCommand(serverEnvironment.mutateProviderInstance, {
32 + reportFailure: false,
33 + reportDefect: false,
34 + });
35 + const pendingRef = useRef(false);
36 + const [pending, setPending] = useState(false);
37 + const [error, setError] = useState<string | null>(null);
38 + async function run(providerInstanceMutation: ProviderInstanceMutation) {
39 + if (pendingRef.current) return false;
40 + pendingRef.current = true;
41 + setPending(true);
42 + setError(null);
43 + const result = await mutate({
44 + environmentId: environment.environmentId,
45 + input: { patch: {}, providerInstanceMutation },
46 + });
47 + pendingRef.current = false;
48 + setPending(false);
49 + if (result._tag === "Success") return true;
50 + if (!isAtomCommandInterrupted(result)) {
51 + const failure = squashAtomCommandFailure(result);
52 + setError(failure instanceof Error ? failure.message : "Could not save the Claude account.");
53 + }
54 + return false;
55 + }
56 + return { run, pending, error, setError };
57 +}
58 +
59 +export function ClaudeAccount({
60 + environment,
61 + provider,
62 +}: {
63 + readonly environment: SettingsTarget;
64 + readonly provider: ServerProvider;
65 +}) {
66 + const [editing, setEditing] = useState(false);
67 + const { run, pending, error } = useProviderInstanceMutation(environment);
68 + const instance = environment.serverConfig.settings.providerInstances[provider.instanceId];
69 + const configDir = claudeConfigDir(instance);
70 + const name = provider.displayName ?? "Claude";
71 + const status = !provider.enabled
72 + ? "Turned off"
73 + : provider.auth.status === "authenticated"
74 + ? "Signed in"
75 + : provider.auth.status === "unauthenticated"
76 + ? "Not signed in"
77 + : !provider.installed
78 + ? "Not installed"
79 + : null;
80 + const removable =
81 + provider.instanceId !== DEFAULT_CLAUDE_INSTANCE_ID &&
82 + !isManagedSettingPath(
83 + environment.serverConfig.managedPolicy,
84 + `providerInstances.${provider.instanceId}`,
85 + );
86 + const actions: MenuAction[] = [
87 + { id: "edit", title: "Edit", image: "pencil" },
88 + ...(removable
89 + ? [
90 + {
91 + id: "remove",
92 + title: "Remove",
93 + image: "trash",
94 + attributes: { destructive: true },
95 + } satisfies MenuAction,
96 + ]
97 + : []),
98 + ];
99 + function remove() {
100 + Dialog.alert(
101 + `Remove ${name}?`,
102 + `It leaves the model picker on ${environment.label}. The config folder and its sign-in stay on the server.`,
103 + [
104 + { text: "Cancel", style: "cancel" },
105 + {
106 + text: "Remove",
107 + style: "destructive",
108 + onPress: () => {
109 + void run({ operation: "remove", instanceId: provider.instanceId });
110 + },
111 + },
112 + ],
113 + );
114 + }
115 + return (
116 + <View className="border-t border-border-subtle">
117 + <View className="min-h-16 flex-row items-center gap-3 px-4 py-3">
118 + <View className="min-w-0 shrink grow gap-0.5">
119 + <Text textRole="body" className="text-foreground" numberOfLines={1}>
120 + {name}
121 + </Text>
122 + <Text textRole="footnote" className="text-foreground-muted" numberOfLines={2}>
123 + {[status, configDir || "Default config folder"].filter(Boolean).join(" · ")}
124 + </Text>
125 + </View>
126 + {editing ? null : (
127 + <Menu
128 + accessible
129 + accessibilityRole="button"
130 + accessibilityLabel={`${name} options`}
131 + title={name}
132 + actions={actions}
133 + onPressAction={({ nativeEvent }) => {
134 + if (pending) return;
135 + if (nativeEvent.event === "edit") setEditing(true);
136 + else if (nativeEvent.event === "remove") remove();
137 + }}
138 + >
139 + <ControlPill
140 + icon="ellipsis"
141 + accessibilityLabel={`${name} options`}
142 + disabled={pending}
143 + />
144 + </Menu>
145 + )}
146 + </View>
147 + {editing ? (
148 + <ClaudeAccountForm
149 + environment={environment}
150 + instanceId={provider.instanceId}
151 + initial={{ name: instance?.displayName ?? "", configDir }}
152 + onDone={() => setEditing(false)}
153 + />
154 + ) : error ? (
155 + <Text accessibilityRole="alert" className="px-4 pb-3 text-danger-foreground">
156 + {error}
157 + </Text>
158 + ) : null}
159 + </View>
160 + );
161 +}
162 +
163 +export function AddClaudeAccount({ environment }: { readonly environment: SettingsTarget }) {
164 + const [adding, setAdding] = useState(false);
165 + return (
166 + <View className="border-t border-border-subtle">
167 + {adding ? (
168 + <ClaudeAccountForm
169 + environment={environment}
170 + instanceId={null}
171 + initial={{ name: "", configDir: "" }}
172 + onDone={() => setAdding(false)}
173 + />
174 + ) : (
175 + <ListActionRow
176 + icon="plus"
177 + label="Add Claude account"
178 + description="Use a Claude config folder that is already signed in on this server."
179 + onPress={() => setAdding(true)}
180 + />
181 + )}
182 + </View>
183 + );
184 +}
185 +
186 +function ClaudeAccountForm({
187 + environment,
188 + instanceId,
189 + initial,
190 + onDone,
191 +}: {
192 + readonly environment: SettingsTarget;
193 + readonly instanceId: ProviderInstanceId | null;
194 + readonly initial: ClaudeAccountDraft;
195 + readonly onDone: () => void;
196 +}) {
197 + const [draft, setDraft] = useState(initial);
198 + const { run, pending, error, setError } = useProviderInstanceMutation(environment);
199 + function save() {
200 + const plan = planClaudeAccountSave({
201 + providerInstances: environment.serverConfig.settings.providerInstances,
202 + policy: environment.serverConfig.managedPolicy,
203 + instanceId,
204 + draft,
205 + });
206 + if ("error" in plan) {
207 + setError(plan.error);
208 + return;
209 + }
210 + void run(plan.mutation).then((saved) => {
211 + if (saved) onDone();
212 + });
213 + }
214 + function field(key: keyof ClaudeAccountDraft, label: string, placeholder: string) {
215 + return (
216 + <TextInput
217 + accessibilityLabel={label}
218 + className="rounded-lg border border-border-subtle px-3 py-2 text-base text-foreground"
219 + placeholderTextColorClassName="accent-foreground-muted"
220 + placeholder={placeholder}
221 + autoCapitalize="none"
222 + autoCorrect={false}
223 + editable={!pending}
224 + value={draft[key]}
225 + onChangeText={(value) => setDraft((current) => ({ ...current, [key]: value }))}
226 + />
227 + );
228 + }
229 + return (
230 + <View className="gap-2 px-4 py-3">
231 + <Text textRole="footnote" className="text-foreground-muted">
232 + {`Point at a CLAUDE_CONFIG_DIR folder on ${environment.label} where Claude Code is already signed in. Sign in there with the Claude CLI first.`}
233 + </Text>
234 + {field("name", "Account name", "Name, e.g. Work")}
235 + {field("configDir", "Claude config folder", "Config folder, e.g. ~/.claude-work")}
236 + {error ? (
237 + <Text accessibilityRole="alert" className="text-danger-foreground">
238 + {error}
239 + </Text>
240 + ) : null}
241 + <View className="flex-row justify-end gap-2">
242 + <ControlPill variant="pill" label="Cancel" disabled={pending} onPress={onDone} />
243 + <ControlPill
244 + variant="primary"
245 + label={instanceId === null ? "Add" : "Save"}
246 + disabled={pending}
247 + onPress={save}
248 + />
249 + </View>
250 + </View>
251 + );
252 +}
apps/mobile/src/features/settings/SettingsProviderAccountsRouteScreen.tsx
+45 -19
@@ -34,6 +34,8 @@ import {
34 } from "./components/SettingsEnvironmentFilterHeader";
35 import { SettingsScreen } from "./components/SettingsScreen";
36 import { SettingsSection } from "./components/SettingsSection";
37 +import { AddClaudeAccount, ClaudeAccount } from "./ClaudeAccounts";
38 +import { CLAUDE_DRIVER } from "./claude-accounts";
39 import { useSettingsEnvironmentFilter, type SettingsTarget } from "./settings-environment-filter";
40
41 export function SettingsProviderAccountsRouteScreen() {
@@ -65,25 +67,10 @@ export function SettingsProviderAccountsRouteScreen() {
67 </Text>
68 </View>
69 ) : (
68 - <>
69 - {managedProviders(environment, providersByEnvironment)
70 - .filter(canManageProvider)
71 - .map((provider, index) => (
72 - <ProviderAccount
73 - key={provider.instanceId}
74 - environment={environment}
75 - provider={provider}
76 - divider={index > 0}
77 - />
78 - ))}
79 - {!managedProviders(environment, providersByEnvironment).some(
80 - canManageProvider,
81 - ) ? (
82 - <Text className="p-4 text-foreground-muted">
83 - Configure a provider with in-app sign-in in web or desktop Settings.
84 - </Text>
85 - ) : null}
86 - </>
70 + <EnvironmentProviders
71 + environment={environment}
72 + providers={managedProviders(environment, providersByEnvironment)}
73 + />
74 )}
75 </SettingsSection>
76 ))
@@ -94,6 +81,45 @@ export function SettingsProviderAccountsRouteScreen() {
81 );
82 }
83
84 +function EnvironmentProviders({
85 + environment,
86 + providers,
87 +}: {
88 + readonly environment: SettingsTarget;
89 + readonly providers: ReadonlyArray<ServerProvider>;
90 +}) {
91 + const accounts = providers.filter(canManageProvider);
92 + // Claude has no in-app sign-in; each account is its own instance on a signed-in config folder.
93 + const claudeAccounts = providers.filter(
94 + (provider) => provider.driver === CLAUDE_DRIVER && !canManageProvider(provider),
95 + );
96 + const canAddClaude = isManagedDriverAllowed(
97 + environment.serverConfig.managedPolicy,
98 + CLAUDE_DRIVER,
99 + );
100 + return (
101 + <>
102 + {accounts.map((provider, index) => (
103 + <ProviderAccount
104 + key={provider.instanceId}
105 + environment={environment}
106 + provider={provider}
107 + divider={index > 0}
108 + />
109 + ))}
110 + {accounts.length === 0 ? (
111 + <Text className="p-4 text-foreground-muted">
112 + Configure a provider with in-app sign-in in web or desktop Settings.
113 + </Text>
114 + ) : null}
115 + {claudeAccounts.map((provider) => (
116 + <ClaudeAccount key={provider.instanceId} environment={environment} provider={provider} />
117 + ))}
118 + {canAddClaude ? <AddClaudeAccount environment={environment} /> : null}
119 + </>
120 + );
121 +}
122 +
123 /** Providers the environment's managed policy allows; the rest cannot run or sign in. */
124 function managedProviders(
125 environment: SettingsTarget,
apps/mobile/src/features/settings/claude-accounts.test.ts new
+117
@@ -0,0 +1,117 @@
1 +import {
2 + ProviderDriverKind,
3 + ProviderInstanceId,
4 + type ManagedPolicySummary,
5 + type ServerSettings,
6 +} from "@t3tools/contracts";
7 +import { describe, expect, it } from "vite-plus/test";
8 +
9 +import { planClaudeAccountSave } from "./claude-accounts";
10 +
11 +const claude = ProviderDriverKind.make("claudeAgent");
12 +const work = ProviderInstanceId.make("claudeAgent_work");
13 +
14 +describe("planClaudeAccountSave", () => {
15 + it("adds a signed-in config folder as a new Claude instance with a free id", () => {
16 + const providerInstances: ServerSettings["providerInstances"] = {
17 + [work]: { driver: claude, config: { homePath: "~/.claude-work" } },
18 + };
19 + const plan = (name: string, configDir: string) =>
20 + planClaudeAccountSave({
21 + providerInstances,
22 + policy: undefined,
23 + instanceId: null,
24 + draft: { name, configDir },
25 + });
26 +
27 + expect(plan(" Work ", " ~/.claude-willy ")).toEqual({
28 + mutation: {
29 + operation: "create",
30 + instanceId: "claudeAgent_work_2",
31 + instance: {
32 + driver: "claudeAgent",
33 + enabled: true,
34 + displayName: "Work",
35 + config: { homePath: "~/.claude-willy" },
36 + },
37 + },
38 + });
39 + expect(plan("", "~/.claude-willy")).toHaveProperty("error");
40 + expect(plan("Willy", " ")).toHaveProperty("error");
41 + });
42 +
43 + it("edits the name and folder without dropping the instance's other settings", () => {
44 + const providerInstances: ServerSettings["providerInstances"] = {
45 + [work]: {
46 + driver: claude,
47 + displayName: "Work",
48 + accentColor: "#ff0000",
49 + enabled: false,
50 + environment: [{ name: "TOKEN", value: "", sensitive: true, valueRedacted: true }],
51 + config: { homePath: "~/.claude-work", binaryPath: "/opt/claude", launchArgs: "--chrome" },
52 + },
53 + };
54 + const edit = (name: string, configDir: string) =>
55 + planClaudeAccountSave({
56 + providerInstances,
57 + policy: undefined,
58 + instanceId: work,
59 + draft: { name, configDir },
60 + });
61 +
62 + expect(edit("Willy", "~/.claude-willy")).toEqual({
63 + mutation: {
64 + operation: "upsert",
65 + instanceId: work,
66 + instance: {
67 + ...providerInstances[work],
68 + displayName: "Willy",
69 + config: {
70 + binaryPath: "/opt/claude",
71 + launchArgs: "--chrome",
72 + homePath: "~/.claude-willy",
73 + },
74 + },
75 + },
76 + });
77 + // Clearing both falls back to the driver's label and the default ~/.claude folder.
78 + expect(edit("", "")).toEqual({
79 + mutation: {
80 + operation: "upsert",
81 + instanceId: work,
82 + instance: {
83 + driver: claude,
84 + accentColor: "#ff0000",
85 + enabled: false,
86 + environment: providerInstances[work]!.environment,
87 + config: { binaryPath: "/opt/claude", launchArgs: "--chrome" },
88 + },
89 + },
90 + });
91 + expect(
92 + planClaudeAccountSave({
93 + providerInstances: { [work]: { driver: claude, config: { homePath: "~/.claude-work" } } },
94 + policy: undefined,
95 + instanceId: work,
96 + draft: { name: "", configDir: "" },
97 + }),
98 + ).toEqual({
99 + mutation: { operation: "upsert", instanceId: work, instance: { driver: claude } },
100 + });
101 + });
102 +
103 + it("refuses instances the managed policy pins", () => {
104 + const policy: ManagedPolicySummary = {
105 + organization: "Example Corp",
106 + lockedSettings: ["providerInstances.claudeAgent_work.config.homePath"],
107 + };
108 + expect(
109 + planClaudeAccountSave({
110 + providerInstances: { [work]: { driver: claude } },
111 + policy,
112 + instanceId: work,
113 + draft: { name: "Work", configDir: "~/.claude-other" },
114 + }),
115 + ).toEqual({ error: "Managed by Example Corp." });
116 + });
117 +});
apps/mobile/src/features/settings/claude-accounts.ts new
+75
@@ -0,0 +1,75 @@
1 +import {
2 + deriveAvailableInstanceId,
3 + deriveInstanceId,
4 +} from "@t3tools/client-runtime/provider-instance-ids";
5 +import {
6 + defaultInstanceIdForDriver,
7 + isManagedSettingPath,
8 + ProviderDriverKind,
9 + ProviderInstanceId,
10 + type ManagedPolicySummary,
11 + type ProviderInstanceConfig,
12 + type ProviderInstanceMutation,
13 + type ServerSettings,
14 +} from "@t3tools/contracts";
15 +
16 +export const CLAUDE_DRIVER = ProviderDriverKind.make("claudeAgent");
17 +export const DEFAULT_CLAUDE_INSTANCE_ID = defaultInstanceIdForDriver(CLAUDE_DRIVER);
18 +
19 +export interface ClaudeAccountDraft {
20 + readonly name: string;
21 + readonly configDir: string;
22 +}
23 +
24 +function configRecord(instance: ProviderInstanceConfig | undefined): Record<string, unknown> {
25 + const config = instance?.config;
26 + return config !== null && typeof config === "object" ? (config as Record<string, unknown>) : {};
27 +}
28 +
29 +export function claudeConfigDir(instance: ProviderInstanceConfig | undefined): string {
30 + const homePath = configRecord(instance).homePath;
31 + return typeof homePath === "string" ? homePath : "";
32 +}
33 +
34 +/** Adds a Claude instance (`instanceId` null) or edits one, keeping every field the form doesn't show. */
35 +export function planClaudeAccountSave(input: {
36 + readonly providerInstances: ServerSettings["providerInstances"];
37 + readonly policy: ManagedPolicySummary | undefined;
38 + readonly instanceId: ProviderInstanceId | null;
39 + readonly draft: ClaudeAccountDraft;
40 +}): { readonly mutation: ProviderInstanceMutation } | { readonly error: string } {
41 + const name = input.draft.name.trim();
42 + const configDir = input.draft.configDir.trim();
43 + const adding = input.instanceId === null;
44 + if (adding && name.length === 0) return { error: "Enter a name for this account." };
45 + if (adding && configDir.length === 0) {
46 + return { error: "Enter the Claude config folder this account is signed in with." };
47 + }
48 + const instanceId =
49 + input.instanceId ??
50 + ProviderInstanceId.make(
51 + deriveAvailableInstanceId(
52 + (label) => deriveInstanceId(CLAUDE_DRIVER, label) || CLAUDE_DRIVER,
53 + name,
54 + new Set([DEFAULT_CLAUDE_INSTANCE_ID, ...Object.keys(input.providerInstances)]),
55 + ),
56 + );
57 + if (input.policy && isManagedSettingPath(input.policy, `providerInstances.${instanceId}`)) {
58 + return { error: `Managed by ${input.policy.organization}.` };
59 + }
60 + const current: ProviderInstanceConfig = Object.hasOwn(input.providerInstances, instanceId)
61 + ? input.providerInstances[instanceId]!
62 + : { driver: CLAUDE_DRIVER };
63 + const { displayName: _displayName, config: _config, ...rest } = current;
64 + const { homePath: _homePath, ...config } = configRecord(current);
65 + const nextConfig = configDir ? { ...config, homePath: configDir } : config;
66 + const instance: ProviderInstanceConfig = {
67 + ...rest,
68 + ...(adding ? { enabled: true } : {}),
69 + ...(name ? { displayName: name } : {}),
70 + ...(Object.keys(nextConfig).length > 0 ? { config: nextConfig } : {}),
71 + };
72 + return {
73 + mutation: { operation: adding ? "create" : "upsert", instanceId, instance },
74 + };
75 +}
apps/web/src/components/settings/AddProviderInstanceDialog.logic.ts
-15
@@ -39,21 +39,6 @@ export function updateProviderIdentityDraft(
39 };
40 }
41
42 -export function deriveAvailableInstanceId(
43 - derive: (label: string) => string,
44 - label: string,
45 - existing: ReadonlySet<string>,
46 -): string {
47 - const base = derive(label);
48 - if (!base || !existing.has(base)) return base;
49 -
50 - for (let suffix = 2; ; suffix += 1) {
51 - const suffixText = `_${suffix}`;
52 - const candidate = `${base.slice(0, 64 - suffixText.length)}${suffixText}`;
53 - if (!existing.has(candidate)) return candidate;
54 - }
55 -}
56 -
42 export function isConfiguredAcpRegistryAgent(
43 instances: Readonly<Record<string, { readonly driver: string; readonly config?: unknown }>>,
44 agentId: string,
apps/web/src/components/settings/AddProviderInstanceDialog.test.ts
-13
@@ -1,7 +1,6 @@
1 import { describe, expect, it } from "vite-plus/test";
2
3 import {
4 - deriveAvailableInstanceId,
4 getProviderIdentityDraft,
5 resolveAcpRegistryWizardNavigation,
6 resolveWizardNavigation,
@@ -50,18 +49,6 @@ describe("ACP Registry wizard", () => {
49 ).toEqual({ kind: "navigate", step: 1 });
50 });
51
53 - it("derives a collision-free instance id without exceeding the slug limit", () => {
54 - const derive = (label: string) => `acpRegistry_${label}`;
55 - const existing = new Set(["acpRegistry_gemini", "acpRegistry_gemini_2"]);
56 -
57 - expect(deriveAvailableInstanceId(derive, "gemini", existing)).toBe("acpRegistry_gemini_3");
58 -
59 - const longBase = `acpRegistry_${"a".repeat(48)}`;
60 - expect(deriveAvailableInstanceId(() => longBase, "ignored", new Set([longBase]))).toHaveLength(
61 - 62,
62 - );
63 - });
64 -
52 it("keeps registry-prefilled identity separate from other drivers", () => {
53 const registryDrafts = updateProviderIdentityDraft({}, "acpRegistry", {
54 label: "Gemini CLI",
apps/web/src/components/settings/AddProviderInstanceDialog.tsx
+4 -16
@@ -3,6 +3,10 @@ import { ProviderInstanceIcon } from "../chat/ProviderInstanceIcon";
3 import { Radio as RadioPrimitive } from "@base-ui/react/radio";
4 import { CheckIcon, ChevronDownIcon } from "lucide-react";
5 import { useState } from "react";
6 +import {
7 + deriveAvailableInstanceId,
8 + deriveInstanceId,
9 +} from "@t3tools/client-runtime/provider-instance-ids";
10 import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
11 import type { ProviderClientDefinition } from "@t3tools/provider-core/client";
12 import {
@@ -43,7 +47,6 @@ import {
47 ADD_PROVIDER_WIZARD_STEPS,
48 ACP_REGISTRY_WIZARD_STEPS,
49 LOCAL_ACP_WIZARD_STEPS,
46 - deriveAvailableInstanceId,
50 resolveAcpRegistryWizardNavigation,
51 resolveWizardNavigation,
52 updateProviderIdentityDraft,
@@ -59,21 +62,6 @@ import { MultipleAccountsNote } from "./MultipleAccountsNote";
62 import { ProviderEnvironmentSection } from "./ProviderInstanceCard";
63 import { useSecretSources } from "./SecretSourceInput";
64
62 -/** Limit the slug to 48 chars so the composed ProviderInstanceId fits its 64-char cap. */
63 -function slugifyLabel(value: string): string {
64 - return value
65 - .trim()
66 - .toLowerCase()
67 - .replace(/[^a-z0-9]+/g, "_")
68 - .replace(/^_+|_+$/g, "")
69 - .slice(0, 48);
70 -}
71 -
72 -function deriveInstanceId(driver: ProviderDriverKind, label: string): string {
73 - const slug = slugifyLabel(label);
74 - return slug ? `${driver}_${slug}` : "";
75 -}
76 -
65 const INSTANCE_ID_PATTERN = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
66 const DEFAULT_DRIVER_KIND = ProviderDriverKind.make("codex");
67 const ACP_REGISTRY_DRIVER_KIND = ProviderDriverKind.make("acpRegistry");
docs/user/providers-claude.md
+3
@@ -24,6 +24,9 @@ Add another Claude instance in **Settings > Providers**:
24 | Claude Work | `claude` | Leave empty |
25 | Claude Personal | `claude` | `~/.claude_personal` |
26
27 +On mobile, tap **Add Claude account** in **Settings > Providers** and enter a name and the
28 +config folder. The login itself still happens on the environment's machine.
29 +
30 An empty config-directory setting uses Claude Code's normal configuration. The
31 custom setting changes `CLAUDE_CONFIG_DIR`, leaving `HOME` and the system keychain
32 location intact. Use the same variable for the login command. Setting `HOME`
packages/client-runtime/package.json
+4
@@ -518,6 +518,10 @@
518 "./provider-clients": {
519 "types": "./src/providerClients.ts",
520 "default": "./src/providerClients.ts"
521 + },
522 + "./provider-instance-ids": {
523 + "types": "./src/providerInstanceIds.ts",
524 + "default": "./src/providerInstanceIds.ts"
525 }
526 },
527 "scripts": {
packages/client-runtime/src/providerInstanceIds.test.ts new
+17
@@ -0,0 +1,17 @@
1 +import { describe, expect, it } from "vite-plus/test";
2 +
3 +import { deriveAvailableInstanceId } from "./providerInstanceIds.ts";
4 +
5 +describe("deriveAvailableInstanceId", () => {
6 + it("derives a collision-free instance id without exceeding the slug limit", () => {
7 + const derive = (label: string) => `acpRegistry_${label}`;
8 + const existing = new Set(["acpRegistry_gemini", "acpRegistry_gemini_2"]);
9 +
10 + expect(deriveAvailableInstanceId(derive, "gemini", existing)).toBe("acpRegistry_gemini_3");
11 +
12 + const longBase = `acpRegistry_${"a".repeat(48)}`;
13 + expect(deriveAvailableInstanceId(() => longBase, "ignored", new Set([longBase]))).toHaveLength(
14 + 62,
15 + );
16 + });
17 +});
packages/client-runtime/src/providerInstanceIds.ts new
+29
@@ -0,0 +1,29 @@
1 +/** Limit the slug to 48 chars so the composed ProviderInstanceId fits its 64-char cap. */
2 +function slugifyLabel(value: string): string {
3 + return value
4 + .trim()
5 + .toLowerCase()
6 + .replace(/[^a-z0-9]+/g, "_")
7 + .replace(/^_+|_+$/g, "")
8 + .slice(0, 48);
9 +}
10 +
11 +export function deriveInstanceId(driver: string, label: string): string {
12 + const slug = slugifyLabel(label);
13 + return slug ? `${driver}_${slug}` : "";
14 +}
15 +
16 +export function deriveAvailableInstanceId(
17 + derive: (label: string) => string,
18 + label: string,
19 + existing: ReadonlySet<string>,
20 +): string {
21 + const base = derive(label);
22 + if (!base || !existing.has(base)) return base;
23 +
24 + for (let suffix = 2; ; suffix += 1) {
25 + const suffixText = `_${suffix}`;
26 + const candidate = `${base.slice(0, 64 - suffixText.length)}${suffixText}`;
27 + if (!existing.has(candidate)) return candidate;
28 + }
29 +}