Skip to content

Conversation

@mitsuru
Copy link

@mitsuru mitsuru commented Dec 3, 2025

Summary

Add comprehensive Claude Code (Agent SDK) provider integration with full UI configuration support. This enables users to use Claude models through the Agent SDK with either Pro/Max subscription or API key authentication.

Closes #503

Key Features

  • Provider Integration: Support for ai-sdk-provider-claude-code package with three model variants (sonnet, opus, haiku)
  • Flexible Authentication: Works with both subscription mode (claude login) and optional API key
  • Configurable CLI Path: Custom Claude CLI executable path with multiple configuration sources:
    1. UI settings (highest priority)
    2. Environment variable (CLAUDE_CODE_EXECUTABLE_PATH)
    3. Default path ($HOME/.local/bin/claude)
  • UI Configuration: Dedicated settings page for Claude Code provider with real-time validation
  • Home Directory Expansion: Automatic ~/ expansion for path configuration
  • Setup Detection: Intelligent provider setup detection with CLI existence checking

Implementation Details

  • IPC Infrastructure: New handlers for Claude Code-specific configuration management
  • Schema: ClaudeCodeProviderSetting for type-safe configuration storage
  • UI Components: ClaudeCodeConfiguration component with executable path and API key inputs
  • Provider Detection: Cached IPC queries for optimal performance

Changes

  • Add ai-sdk-provider-claude-code package dependency
  • Implement Claude Code provider in get_model_client.ts with configurable CLI path
  • Add ClaudeCodeConfiguration component for settings UI
  • Extend provider setup logic to check CLI executable existence
  • Register IPC handlers for Claude Code configuration management
  • Add schema definitions for Claude Code provider settings

Benefits

  • Agent SDK Access: Leverage Claude Agent SDK features through Dyad
  • Flexible Configuration: Multiple ways to configure authentication and CLI path
  • Better UX: Visual feedback for setup status and configuration validation

Add support for ai-sdk-provider-claude-code to enable Claude models
via the Claude Agent SDK with Pro/Max subscription or API key.

Changes:
- Install ai-sdk-provider-claude-code package
- Add claude-code provider to CLOUD_PROVIDERS and MODEL_OPTIONS
- Add three model variants: sonnet, opus, haiku
- Implement provider case in get_model_client.ts
- Support both subscription mode and optional API key mode

This integration allows users to leverage Claude Agent SDK features
like MCP integration and Extended Thinking through Dyad.
Add pathToClaudeCodeExecutable setting to claudeCode provider
to ensure the CLI can be found via system PATH.

This fixes the error:
"Claude Code executable not found at .vite/build/cli.js"

The provider now uses "claude" command from system PATH,
which should be available after installing @anthropic-ai/claude-code.
Add IPC layer to manage Claude Code provider settings including
executable path and API key configuration.

- Add ClaudeCodeProviderSetting schema
- Implement claude_code_handlers.ts for settings management
- Add checkClaudeCliExists IPC method
- Register IPC channels in whitelist
Implement configurable Claude CLI executable path with priority:
1. User settings (claudeExecutablePath)
2. Environment variable (CLAUDE_CODE_EXECUTABLE_PATH)
3. Default path ($HOME/.local/bin/claude)

Includes home directory expansion (~/) support for path configuration.
Add dedicated configuration UI for Claude Code provider with:
- ClaudeCodeConfiguration component for executable path and API key
- Integration with ApiKeyConfiguration routing
- Consistent setup detection in ProviderSettingsPage
Enhance provider setup detection to check Claude CLI executable
existence for claude-code provider. Uses IPC query with caching
for optimal performance.
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 13 files

Prompt for AI agents (all 3 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/components/settings/ClaudeCodeConfiguration.tsx">

<violation number="1" location="src/components/settings/ClaudeCodeConfiguration.tsx:69">
P2: Trim whitespace from the API key before persisting so copies with trailing spaces/newlines don’t break authentication.</violation>

<violation number="2" location="src/components/settings/ClaudeCodeConfiguration.tsx:116">
P2: Persist the trimmed executable path so accidental whitespace doesn’t break CLI detection.</violation>
</file>

<file name="src/components/settings/ProviderSettingsPage.tsx">

<violation number="1" location="src/components/settings/ProviderSettingsPage.tsx:115">
P2: `isProviderSetup(provider)` treats any truthy API key as configured, so placeholder values like &quot;Invalid Key…&quot; or &quot;Not Set&quot; now mark the provider as configured and hide that setup is still required.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

? isVertexConfigured
: isValidUserKey || hasEnvKey; // Configured if either is set
// Use isProviderSetup from useLanguageModelProviders hook for consistent logic
const isConfigured = isProviderSetup(provider);
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: isProviderSetup(provider) treats any truthy API key as configured, so placeholder values like "Invalid Key…" or "Not Set" now mark the provider as configured and hide that setup is still required.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/components/settings/ProviderSettingsPage.tsx, line 115:

<comment>`isProviderSetup(provider)` treats any truthy API key as configured, so placeholder values like &quot;Invalid Key…&quot; or &quot;Not Set&quot; now mark the provider as configured and hide that setup is still required.</comment>

<file context>
@@ -110,12 +111,8 @@ export function ProviderSettingsPage({ provider }: ProviderSettingsPageProps) {
-        ? isVertexConfigured
-        : isValidUserKey || hasEnvKey; // Configured if either is set
+  // Use isProviderSetup from useLanguageModelProviders hook for consistent logic
+  const isConfigured = isProviderSetup(provider);
 
   // --- Save Handler ---
</file context>
Fix with Cubic

- Trim whitespace from API key before persisting to prevent authentication issues
- Trim whitespace from executable path before persisting to prevent CLI detection issues
- Fix isProviderSetup to reject placeholder values like "Invalid Key" and "Not Set"
@mitsuru mitsuru force-pushed the feature/claude-code-provider branch from cc1479f to 951f0ed Compare December 4, 2025 01:38
Copy link
Contributor

@wwwillchen wwwillchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the PR! I pulled it down and overall looks pretty good. i left a few comments.

can you add an e2e test? see - https://github.com/dyad-sh/dyad/blob/main/CONTRIBUTING.md#e2e-tests

here's an e2e test that you can model it after
https://github.com/dyad-sh/dyad/blob/main/e2e-tests/azure_provider_settings.spec.ts

console.error("Error checking Claude CLI existence:", error);
return false;
}
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is really low - let's use the default value (which i think is 5 mins) - the user should be able invalidate this if needed by clicking on a button

const expandHomeDir = (filePath: string): string => {
if (filePath.startsWith("~/")) {
const homeDir = process.env.HOME || process.env.USERPROFILE || "";
return path.join(homeDir, filePath.slice(2));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use safeJoin from path_utils?

`Using Claude Code provider: ${model.name}${apiKey ? " with API key" : " (subscription mode)"}`,
);

// Helper function to expand ~ to home directory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of this code looks duplicated with claude_code_handlers.ts - let's extract into a proper utils file and reuse it.


// Default path for display
const homeDir = "~";
const defaultClaudePath = `${homeDir}/.local/bin/claude`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on my computer (macos) claude is installed at:

~/.claude/local/claude

Should this be conditioned based on OS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claude Code subscription support

2 participants