Open History to see the last commit
1import {
2 type ClaudeSettings,
3 type ModelCapabilities,
4 type ModelSelection,
5 ProviderDriverKind,
6 type ServerProviderModel,
7 type ServerProviderSlashCommand,
8} from "@t3tools/contracts";
9import * as DateTime from "effect/DateTime";
10import * as Effect from "effect/Effect";
11import * as Option from "effect/Option";
12import * as Path from "effect/Path";
13import * as Result from "effect/Result";
14import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
15import {
16 createModelCapabilities,
17 getModelSelectionStringOptionValue,
18 getProviderOptionCurrentValue,
19 getProviderOptionDescriptors,
20} from "@t3tools/shared/model";
21import { resolveSpawnCommand } from "@t3tools/shared/shell";
22import { compareSemverVersions } from "@t3tools/shared/semver";
23import {
24 query as claudeQuery,
25 type SlashCommand as ClaudeSlashCommand,
26 type SDKUserMessage,
27} from "@anthropic-ai/claude-agent-sdk";
28
29import {
30 buildBooleanOptionDescriptor,
31 buildSelectOptionDescriptor,
32 buildServerProvider,
33 DEFAULT_TIMEOUT_MS,
34 isCommandMissingCause,
35 parseGenericCliVersion,
36 providerModelsFromSettings,
37 spawnAndCollect,
38 type ServerProviderDraft,
39} from "../providerSnapshot.ts";
40import { makeClaudeEnvironment } from "../Drivers/ClaudeHome.ts";
41
42const DEFAULT_CLAUDE_MODEL_CAPABILITIES: ModelCapabilities = createModelCapabilities({
43 optionDescriptors: [],
44});
45
46const PROVIDER = ProviderDriverKind.make("claudeAgent");
47const CLAUDE_PRESENTATION = {
48 displayName: "Claude",
49 showInteractionModeToggle: true,
50} as const;
51const MINIMUM_CLAUDE_FABLE_5_VERSION = "2.1.169";
52const MINIMUM_CLAUDE_OPUS_4_8_VERSION = "2.1.154";
53const MINIMUM_CLAUDE_OPUS_4_7_VERSION = "2.1.111";
54
55const BUILT_IN_MODELS: ReadonlyArray<ServerProviderModel> = [
56 {
57 slug: "claude-fable-5",
58 name: "Claude Fable 5",
59 isCustom: false,
60 capabilities: createModelCapabilities({
61 optionDescriptors: [
62 buildSelectOptionDescriptor({
63 id: "effort",
64 label: "Reasoning",
65 options: [
66 { value: "low", label: "Low" },
67 { value: "medium", label: "Medium" },
68 { value: "high", label: "High", isDefault: true },
69 { value: "xhigh", label: "Extra High" },
70 { value: "max", label: "Max" },
71 { value: "ultracode", label: "Ultracode" },
72 { value: "ultrathink", label: "Ultrathink" },
73 ],
74 promptInjectedValues: ["ultrathink"],
75 }),
76 buildSelectOptionDescriptor({
77 id: "contextWindow",
78 label: "Context Window",
79 options: [
80 { value: "200k", label: "200k", isDefault: true },
81 { value: "1m", label: "1M" },
82 ],
83 }),
84 ],
85 }),
86 },
87 {
88 slug: "claude-opus-4-8",
89 name: "Claude Opus 4.8",
90 isCustom: false,
91 capabilities: createModelCapabilities({
92 optionDescriptors: [
93 buildSelectOptionDescriptor({
94 id: "effort",
95 label: "Reasoning",
96 options: [
97 { value: "low", label: "Low" },
98 { value: "medium", label: "Medium" },
99 { value: "high", label: "High", isDefault: true },
100 { value: "xhigh", label: "Extra High" },
101 { value: "max", label: "Max" },
102 { value: "ultracode", label: "Ultracode" },
103 { value: "ultrathink", label: "Ultrathink" },
104 ],
105 promptInjectedValues: ["ultrathink"],
106 }),
107 buildBooleanOptionDescriptor({
108 id: "fastMode",
109 label: "Fast Mode",
110 }),
111 ],
112 }),
113 },
114 {
115 slug: "claude-opus-4-7",
116 name: "Claude Opus 4.7",
117 isCustom: false,
118 capabilities: createModelCapabilities({
119 optionDescriptors: [
120 buildSelectOptionDescriptor({
121 id: "effort",
122 label: "Reasoning",
123 options: [
124 { value: "low", label: "Low" },
125 { value: "medium", label: "Medium" },
126 { value: "high", label: "High" },
127 { value: "xhigh", label: "Extra High", isDefault: true },
128 { value: "max", label: "Max" },
129 { value: "ultrathink", label: "Ultrathink" },
130 ],
131 promptInjectedValues: ["ultrathink"],
132 }),
133 buildBooleanOptionDescriptor({
134 id: "fastMode",
135 label: "Fast Mode",
136 }),
137 ],
138 }),
139 },
140 {
141 slug: "claude-opus-4-6",
142 name: "Claude Opus 4.6",
143 isCustom: false,
144 capabilities: createModelCapabilities({
145 optionDescriptors: [
146 buildSelectOptionDescriptor({
147 id: "effort",
148 label: "Reasoning",
149 options: [
150 { value: "low", label: "Low" },
151 { value: "medium", label: "Medium" },
152 { value: "high", label: "High", isDefault: true },
153 { value: "max", label: "Max" },
154 { value: "ultrathink", label: "Ultrathink" },
155 ],
156 promptInjectedValues: ["ultrathink"],
157 }),
158 buildBooleanOptionDescriptor({
159 id: "fastMode",
160 label: "Fast Mode",
161 }),
162 buildSelectOptionDescriptor({
163 id: "contextWindow",
164 label: "Context Window",
165 options: [
166 { value: "200k", label: "200k", isDefault: true },
167 { value: "1m", label: "1M" },
168 ],
169 }),
170 ],
171 }),
172 },
173 {
174 slug: "claude-opus-4-5",
175 name: "Claude Opus 4.5",
176 isCustom: false,
177 capabilities: createModelCapabilities({
178 optionDescriptors: [
179 buildSelectOptionDescriptor({
180 id: "effort",
181 label: "Reasoning",
182 options: [
183 { value: "low", label: "Low" },
184 { value: "medium", label: "Medium" },
185 { value: "high", label: "High", isDefault: true },
186 { value: "max", label: "Max" },
187 ],
188 }),
189 buildBooleanOptionDescriptor({
190 id: "fastMode",
191 label: "Fast Mode",
192 }),
193 ],
194 }),
195 },
196 {
197 slug: "claude-sonnet-4-6",
198 name: "Claude Sonnet 4.6",
199 isCustom: false,
200 capabilities: createModelCapabilities({
201 optionDescriptors: [
202 buildSelectOptionDescriptor({
203 id: "effort",
204 label: "Reasoning",
205 options: [
206 { value: "low", label: "Low" },
207 { value: "medium", label: "Medium" },
208 { value: "high", label: "High", isDefault: true },
209 { value: "max", label: "Max" },
210 { value: "ultrathink", label: "Ultrathink" },
211 ],
212 promptInjectedValues: ["ultrathink"],
213 }),
214 buildSelectOptionDescriptor({
215 id: "contextWindow",
216 label: "Context Window",
217 options: [
218 { value: "200k", label: "200k", isDefault: true },
219 { value: "1m", label: "1M" },
220 ],
221 }),
222 ],
223 }),
224 },
225 {
226 slug: "claude-haiku-4-5",
227 name: "Claude Haiku 4.5",
228 isCustom: false,
229 capabilities: createModelCapabilities({
230 optionDescriptors: [
231 buildBooleanOptionDescriptor({
232 id: "thinking",
233 label: "Thinking",
234 }),
235 ],
236 }),
237 },
238];
239
240function supportsClaudeFable5(version: string | null | undefined): boolean {
241 return version ? compareSemverVersions(version, MINIMUM_CLAUDE_FABLE_5_VERSION) >= 0 : false;
242}
243
244function supportsClaudeOpus48(version: string | null | undefined): boolean {
245 return version ? compareSemverVersions(version, MINIMUM_CLAUDE_OPUS_4_8_VERSION) >= 0 : false;
246}
247
248function supportsClaudeOpus47(version: string | null | undefined): boolean {
249 return version ? compareSemverVersions(version, MINIMUM_CLAUDE_OPUS_4_7_VERSION) >= 0 : false;
250}
251
252function getBuiltInClaudeModelsForVersion(
253 version: string | null | undefined,
254): ReadonlyArray<ServerProviderModel> {
255 return BUILT_IN_MODELS.filter((model) => {
256 if (model.slug === "claude-fable-5") {
257 return supportsClaudeFable5(version);
258 }
259 if (model.slug === "claude-opus-4-8") {
260 return supportsClaudeOpus48(version);
261 }
262 if (model.slug === "claude-opus-4-7") {
263 return supportsClaudeOpus47(version);
264 }
265 return true;
266 });
267}
268
269function formatClaudeFable5UpgradeMessage(version: string | null): string {
270 const versionLabel = version ? `v${version}` : "the installed version";
271 return `Claude Code ${versionLabel} is too old for Claude Fable 5. Upgrade to v${MINIMUM_CLAUDE_FABLE_5_VERSION} or newer to access it.`;
272}
273
274function formatClaudeOpus48UpgradeMessage(version: string | null): string {
275 const versionLabel = version ? `v${version}` : "the installed version";
276 return `Claude Code ${versionLabel} is too old for Claude Opus 4.8. Upgrade to v${MINIMUM_CLAUDE_OPUS_4_8_VERSION} or newer to access it.`;
277}
278
279function formatClaudeOpus47UpgradeMessage(version: string | null): string {
280 const versionLabel = version ? `v${version}` : "the installed version";
281 return `Claude Code ${versionLabel} is too old for Claude Opus 4.7. Upgrade to v${MINIMUM_CLAUDE_OPUS_4_7_VERSION} or newer to access it.`;
282}
283
284export function getClaudeModelCapabilities(model: string | null | undefined): ModelCapabilities {
285 const slug = model?.trim();
286 return (
287 BUILT_IN_MODELS.find((candidate) => candidate.slug === slug)?.capabilities ??
288 DEFAULT_CLAUDE_MODEL_CAPABILITIES
289 );
290}
291
292export function resolveClaudeEffort(
293 caps: ModelCapabilities,
294 raw: string | null | undefined,
295): string | undefined {
296 const descriptors = getProviderOptionDescriptors({
297 caps,
298 ...(raw ? { selections: [{ id: "effort", value: raw }] } : {}),
299 });
300 const effortDescriptor = descriptors.find((descriptor) => descriptor.id === "effort");
301 const value = getProviderOptionCurrentValue(effortDescriptor);
302 return typeof value === "string" ? value : undefined;
303}
304
305/**
306 * Normalize a resolved Claude effort value into one suitable for the Claude
307 * CLI's `--effort` flag.
308 *
309 * Mirrors the mapping used when invoking the Claude Agent SDK
310 * ({@link getEffectiveClaudeAgentEffort} in ClaudeAdapter): `ultracode` is a
311 * Claude Code setting that pairs with `xhigh`, `ultrathink` is filtered out
312 * because it is a prompt-prefix mode, and older model compatibility mappings
313 * are preserved for current Claude Code behavior.
314 */
315export function normalizeClaudeCliEffort(
316 effort: string | null | undefined,
317 model: string | null | undefined,
318): string | undefined {
319 if (!effort || effort === "ultrathink") {
320 return undefined;
321 }
322 if (effort === "ultracode") {
323 return "xhigh";
324 }
325 if (effort === "xhigh" && model !== "claude-fable-5" && model !== "claude-opus-4-8") {
326 return "max";
327 }
328 if (effort === "max" && model === "claude-sonnet-4-6") {
329 return "high";
330 }
331 return effort;
332}
333
334export function isClaudeUltracodeEffort(effort: string | null | undefined): boolean {
335 return effort === "ultracode";
336}
337
338export function resolveClaudeApiModelId(modelSelection: ModelSelection): string {
339 switch (getModelSelectionStringOptionValue(modelSelection, "contextWindow")) {
340 case "1m":
341 return `${modelSelection.model}[1m]`;
342 default:
343 return modelSelection.model;
344 }
345}
346
347function toTitleCaseWords(value: string): string {
348 const parts: Array<string> = [];
349 for (const part of value.split(/[\s_-]+/g)) {
350 if (part.length > 0) {
351 parts.push(part[0]!.toUpperCase() + part.slice(1).toLowerCase());
352 }
353 }
354 return parts.join(" ");
355}
356
357function claudeSubscriptionLabel(subscriptionType: string | undefined): string | undefined {
358 const normalized = subscriptionType?.toLowerCase().replace(/[\s_-]+/g, "");
359 if (!normalized) return undefined;
360
361 switch (normalized) {
362 case "claudemaxsubscription":
363 return "Max";
364 case "claudemax5xsubscription":
365 return "Max 5x";
366 case "claudemax20xsubscription":
367 return "Max 20x";
368 case "claudeenterprisesubscription":
369 return "Enterprise";
370 case "claudeteamsubscription":
371 return "Team";
372 case "claudeprosubscription":
373 return "Pro";
374 case "claudefreesubscription":
375 return "Free";
376 case "max":
377 case "maxplan":
378 return "Max";
379 case "max5":
380 return "Max 5x";
381 case "max20":
382 return "Max 20x";
383 case "enterprise":
384 return "Enterprise";
385 case "team":
386 return "Team";
387 case "pro":
388 return "Pro";
389 case "free":
390 return "Free";
391 default:
392 return toTitleCaseWords(subscriptionType!);
393 }
394}
395
396function normalizeClaudeAuthMethod(authMethod: string | undefined): string | undefined {
397 const normalized = authMethod?.toLowerCase().replace(/[\s_-]+/g, "");
398 if (!normalized) return undefined;
399 if (
400 normalized === "apikey" ||
401 normalized === "anthropicapikey" ||
402 normalized === "anthropicauthtoken"
403 ) {
404 return "apiKey";
405 }
406 return undefined;
407}
408
409function formatClaudeSubscriptionAuthLabel(subscriptionType: string): string {
410 const subscriptionLabel =
411 claudeSubscriptionLabel(subscriptionType) ?? toTitleCaseWords(subscriptionType);
412 const normalized = subscriptionLabel.toLowerCase().replace(/[\s_-]+/g, "");
413
414 if (normalized.startsWith("claude") && normalized.endsWith("subscription")) {
415 return subscriptionLabel;
416 }
417 if (normalized.startsWith("claude")) {
418 return `${subscriptionLabel} Subscription`;
419 }
420 if (normalized.endsWith("subscription")) {
421 return `Claude ${subscriptionLabel}`;
422 }
423 return `Claude ${subscriptionLabel} Subscription`;
424}
425
426function claudeAuthMetadata(input: {
427 readonly subscriptionType: string | undefined;
428 readonly authMethod: string | undefined;
429}): { readonly type: string; readonly label: string } | undefined {
430 if (normalizeClaudeAuthMethod(input.authMethod) === "apiKey") {
431 return {
432 type: "apiKey",
433 label: "Claude API Key",
434 };
435 }
436
437 if (input.subscriptionType) {
438 return {
439 type: input.subscriptionType,
440 label: formatClaudeSubscriptionAuthLabel(input.subscriptionType),
441 };
442 }
443
444 return undefined;
445}
446
447// ── SDK capability probe ────────────────────────────────────────────
448
449const CAPABILITIES_PROBE_TIMEOUT_MS = 8_000;
450
451function nonEmptyProbeString(value: string): string | undefined {
452 const candidate = value.trim();
453 return candidate ? candidate : undefined;
454}
455
456type ClaudeCapabilitiesProbe = {
457 readonly email: string | undefined;
458 readonly subscriptionType: string | undefined;
459 readonly tokenSource: string | undefined;
460 readonly slashCommands: ReadonlyArray<ServerProviderSlashCommand>;
461};
462
463function parseClaudeInitializationCommands(
464 commands: ReadonlyArray<ClaudeSlashCommand> | undefined,
465): ReadonlyArray<ServerProviderSlashCommand> {
466 return dedupeSlashCommands(
467 (commands ?? []).flatMap((command) => {
468 const name = nonEmptyProbeString(command.name);
469 if (!name) {
470 return [];
471 }
472
473 const description = nonEmptyProbeString(command.description);
474 const argumentHint = nonEmptyProbeString(command.argumentHint);
475
476 return [
477 {
478 name,
479 ...(description ? { description } : {}),
480 ...(argumentHint ? { input: { hint: argumentHint } } : {}),
481 } satisfies ServerProviderSlashCommand,
482 ];
483 }),
484 );
485}
486
487function dedupeSlashCommands(
488 commands: ReadonlyArray<ServerProviderSlashCommand>,
489): ReadonlyArray<ServerProviderSlashCommand> {
490 const commandsByName = new Map<string, ServerProviderSlashCommand>();
491
492 for (const command of commands) {
493 const name = nonEmptyProbeString(command.name);
494 if (!name) {
495 continue;
496 }
497
498 const key = name.toLowerCase();
499 const existing = commandsByName.get(key);
500 if (!existing) {
501 commandsByName.set(key, {
502 ...command,
503 name,
504 });
505 continue;
506 }
507
508 commandsByName.set(key, {
509 ...existing,
510 ...(existing.description
511 ? {}
512 : command.description
513 ? { description: command.description }
514 : {}),
515 ...(existing.input?.hint
516 ? {}
517 : command.input?.hint
518 ? { input: { hint: command.input.hint } }
519 : {}),
520 });
521 }
522
523 return [...commandsByName.values()];
524}
525
526function waitForAbortSignal(signal: AbortSignal): Promise<void> {
527 if (signal.aborted) {
528 return Promise.resolve();
529 }
530 return new Promise((resolve) => {
531 signal.addEventListener("abort", () => resolve(), { once: true });
532 });
533}
534
535/**
536 * Probe account information by spawning a lightweight Claude Agent SDK
537 * session and reading the initialization result.
538 *
539 * We pass a never-yielding AsyncIterable as the prompt so that no user
540 * message is ever written to the subprocess stdin. This means the Claude
541 * Code subprocess completes its local initialization IPC (returning
542 * account info and slash commands) but never starts an API request to
543 * Anthropic. We read the init data and then abort the subprocess.
544 *
545 * This is used as a fallback when `claude auth status` does not include
546 * subscription type information.
547 */
548const probeClaudeCapabilities = (
549 claudeSettings: ClaudeSettings,
550 environment?: NodeJS.ProcessEnv,
551) => {
552 const abort = new AbortController();
553 return Effect.gen(function* () {
554 const claudeEnvironment = yield* makeClaudeEnvironment(claudeSettings, environment);
555 return yield* Effect.tryPromise(async () => {
556 const q = claudeQuery({
557 // Never yield — we only need initialization data, not a conversation.
558 // This prevents any prompt from reaching the Anthropic API.
559 // oxlint-disable-next-line require-yield
560 prompt: (async function* (): AsyncGenerator<SDKUserMessage> {
561 await waitForAbortSignal(abort.signal);
562 })(),
563 options: {
564 persistSession: false,
565 pathToClaudeCodeExecutable: claudeSettings.binaryPath,
566 abortController: abort,
567 settingSources: ["user", "project", "local"],
568 allowedTools: [],
569 env: claudeEnvironment,
570 stderr: () => {},
571 },
572 });
573 const init = await q.initializationResult();
574 const account = init.account as
575 | {
576 readonly email?: string;
577 readonly subscriptionType?: string;
578 readonly tokenSource?: string;
579 }
580 | undefined;
581 return {
582 email: account?.email,
583 subscriptionType: account?.subscriptionType,
584 tokenSource: account?.tokenSource,
585 slashCommands: parseClaudeInitializationCommands(init.commands),
586 } satisfies ClaudeCapabilitiesProbe;
587 });
588 }).pipe(
589 Effect.ensuring(
590 Effect.sync(() => {
591 if (!abort.signal.aborted) abort.abort();
592 }),
593 ),
594 Effect.timeoutOption(CAPABILITIES_PROBE_TIMEOUT_MS),
595 Effect.result,
596 Effect.map((result) => {
597 if (Result.isFailure(result)) return undefined;
598 return Option.isSome(result.success) ? result.success.value : undefined;
599 }),
600 );
601};
602
603const runClaudeCommand = Effect.fn("runClaudeCommand")(function* (
604 claudeSettings: ClaudeSettings,
605 args: ReadonlyArray<string>,
606 environment?: NodeJS.ProcessEnv,
607) {
608 const claudeEnvironment = yield* makeClaudeEnvironment(claudeSettings, environment);
609 const spawnCommand = yield* resolveSpawnCommand(claudeSettings.binaryPath, args, {
610 env: claudeEnvironment,
611 });
612 const command = ChildProcess.make(spawnCommand.command, spawnCommand.args, {
613 env: claudeEnvironment,
614 shell: spawnCommand.shell,
615 });
616 return yield* spawnAndCollect(claudeSettings.binaryPath, command);
617});
618
619export const checkClaudeProviderStatus = Effect.fn("checkClaudeProviderStatus")(function* (
620 claudeSettings: ClaudeSettings,
621 resolveCapabilities?: (
622 claudeSettings: ClaudeSettings,
623 ) => Effect.Effect<ClaudeCapabilitiesProbe | undefined>,
624 environment?: NodeJS.ProcessEnv,
625): Effect.fn.Return<
626 ServerProviderDraft,
627 never,
628 ChildProcessSpawner.ChildProcessSpawner | Path.Path
629> {
630 const resolvedEnvironment = environment ?? process.env;
631 const checkedAt = DateTime.formatIso(yield* DateTime.now);
632 const allModels = providerModelsFromSettings(
633 BUILT_IN_MODELS,
634 PROVIDER,
635 claudeSettings.customModels,
636 DEFAULT_CLAUDE_MODEL_CAPABILITIES,
637 );
638
639 if (!claudeSettings.enabled) {
640 return buildServerProvider({
641 presentation: CLAUDE_PRESENTATION,
642 enabled: false,
643 checkedAt,
644 models: allModels,
645 probe: {
646 installed: false,
647 version: null,
648 status: "warning",
649 auth: { status: "unknown" },
650 message: "Claude is disabled in T3 Code settings.",
651 },
652 });
653 }
654
655 const versionProbe = yield* runClaudeCommand(
656 claudeSettings,
657 ["--version"],
658 resolvedEnvironment,
659 ).pipe(Effect.timeoutOption(DEFAULT_TIMEOUT_MS), Effect.result);
660
661 if (Result.isFailure(versionProbe)) {
662 const error = versionProbe.failure;
663 yield* Effect.logWarning("Claude Agent CLI health check failed.", {
664 errorTag: error._tag,
665 });
666 return buildServerProvider({
667 presentation: CLAUDE_PRESENTATION,
668 enabled: claudeSettings.enabled,
669 checkedAt,
670 models: allModels,
671 probe: {
672 installed: !isCommandMissingCause(error),
673 version: null,
674 status: "error",
675 auth: { status: "unknown" },
676 message: isCommandMissingCause(error)
677 ? "Claude Agent CLI (`claude`) is not installed or not on PATH."
678 : "Failed to execute Claude Agent CLI health check.",
679 },
680 });
681 }
682
683 if (Option.isNone(versionProbe.success)) {
684 return buildServerProvider({
685 presentation: CLAUDE_PRESENTATION,
686 enabled: claudeSettings.enabled,
687 checkedAt,
688 models: allModels,
689 probe: {
690 installed: true,
691 version: null,
692 status: "error",
693 auth: { status: "unknown" },
694 message:
695 "Claude Agent CLI is installed but failed to run. Timed out while running command.",
696 },
697 });
698 }
699
700 const version = versionProbe.success.value;
701 const parsedVersion = parseGenericCliVersion(`${version.stdout}\n${version.stderr}`);
702 if (version.code !== 0) {
703 yield* Effect.logWarning("Claude Agent CLI version probe exited with a non-zero status.", {
704 exitCode: version.code,
705 stdoutLength: version.stdout.length,
706 stderrLength: version.stderr.length,
707 });
708 return buildServerProvider({
709 presentation: CLAUDE_PRESENTATION,
710 enabled: claudeSettings.enabled,
711 checkedAt,
712 models: allModels,
713 probe: {
714 installed: true,
715 version: parsedVersion,
716 status: "error",
717 auth: { status: "unknown" },
718 message: "Claude Agent CLI is installed but failed to run.",
719 },
720 });
721 }
722
723 const models = providerModelsFromSettings(
724 getBuiltInClaudeModelsForVersion(parsedVersion),
725 PROVIDER,
726 claudeSettings.customModels,
727 DEFAULT_CLAUDE_MODEL_CAPABILITIES,
728 );
729 const versionUpgradeMessage = supportsClaudeFable5(parsedVersion)
730 ? undefined
731 : supportsClaudeOpus48(parsedVersion)
732 ? formatClaudeFable5UpgradeMessage(parsedVersion)
733 : supportsClaudeOpus47(parsedVersion)
734 ? formatClaudeOpus48UpgradeMessage(parsedVersion)
735 : formatClaudeOpus47UpgradeMessage(parsedVersion);
736
737 const capabilities = resolveCapabilities
738 ? yield* resolveCapabilities(claudeSettings).pipe(Effect.orElseSucceed(() => undefined))
739 : undefined;
740 const slashCommands = capabilities?.slashCommands ?? [];
741 const dedupedSlashCommands = dedupeSlashCommands(slashCommands);
742
743 if (!capabilities) {
744 return buildServerProvider({
745 presentation: CLAUDE_PRESENTATION,
746 enabled: claudeSettings.enabled,
747 checkedAt,
748 models,
749 slashCommands: dedupedSlashCommands,
750 probe: {
751 installed: true,
752 version: parsedVersion,
753 status: "warning",
754 auth: { status: "unknown" },
755 message: "Could not verify Claude authentication status from initialization result.",
756 },
757 });
758 }
759
760 const authMetadata = claudeAuthMetadata({
761 subscriptionType: capabilities.subscriptionType,
762 authMethod: capabilities.tokenSource,
763 });
764 return buildServerProvider({
765 presentation: CLAUDE_PRESENTATION,
766 enabled: claudeSettings.enabled,
767 checkedAt,
768 models,
769 slashCommands: dedupedSlashCommands,
770 probe: {
771 installed: true,
772 version: parsedVersion,
773 status: "ready",
774 auth: {
775 status: "authenticated",
776 ...(capabilities.email ? { email: capabilities.email } : {}),
777 ...(authMetadata ? authMetadata : {}),
778 },
779 ...(versionUpgradeMessage ? { message: versionUpgradeMessage } : {}),
780 },
781 });
782});
783
784const nowIso = Effect.map(DateTime.now, DateTime.formatIso);
785
786export const makePendingClaudeProvider = (
787 claudeSettings: ClaudeSettings,
788): Effect.Effect<ServerProviderDraft> =>
789 Effect.gen(function* () {
790 const checkedAt = yield* nowIso;
791 const models = providerModelsFromSettings(
792 BUILT_IN_MODELS,
793 PROVIDER,
794 claudeSettings.customModels,
795 DEFAULT_CLAUDE_MODEL_CAPABILITIES,
796 );
797
798 if (!claudeSettings.enabled) {
799 return buildServerProvider({
800 presentation: CLAUDE_PRESENTATION,
801 enabled: false,
802 checkedAt,
803 models,
804 probe: {
805 installed: false,
806 version: null,
807 status: "warning",
808 auth: { status: "unknown" },
809 message: "Claude is disabled in T3 Code settings.",
810 },
811 });
812 }
813
814 return buildServerProvider({
815 presentation: CLAUDE_PRESENTATION,
816 enabled: true,
817 checkedAt,
818 models,
819 probe: {
820 installed: false,
821 version: null,
822 status: "warning",
823 auth: { status: "unknown" },
824 message: "Claude provider status has not been checked in this session yet.",
825 },
826 });
827 });
828
829export { probeClaudeCapabilities };