Skip to content

Conversation

@potable-anarchy
Copy link

Summary

This PR adds a new optional use_claude_subscription setting to the ClaudeCode executor configuration. When enabled, this setting removes the ANTHROPIC_API_KEY environment variable before spawning the Claude Code agent, ensuring that users with Claude Pro/Team subscriptions can opt to use their subscription instead of being charged API fees.

Problem

Users who have both a Claude subscription AND an ANTHROPIC_API_KEY set in their environment variables are inadvertently charged API usage fees when running Claude Code agents through VibeKanban. This happens because:

  1. The API key is present in the environment
  2. Claude Code inherits environment variables from the parent process
  3. Claude Code prioritizes API key authentication over subscription authentication
  4. User gets charged API credits instead of using their included subscription

Solution

This PR introduces a new checkbox setting in the Agents settings page that allows users to explicitly opt into using their Claude subscription when an API key is detected.

Changes

Backend (Rust)

  • crates/executors/src/executors/claude.rs:
    • Added use_claude_subscription optional field to the ClaudeCode struct
    • Implemented logic in spawn_internal() to conditionally remove ANTHROPIC_API_KEY from the environment when the setting is enabled
    • Added tracing log when API key is removed for better debugging

Frontend (Auto-generated)

  • The setting automatically appears in the Agents settings page via JSON Schema auto-generation from the Rust struct
  • TypeScript bindings are auto-generated via the #[derive(TS)] macro
  • No manual frontend changes required

Implementation Details

  • The field is Option<bool> and defaults to false when not set, maintaining backward compatibility
  • Uses #[serde(skip_serializing_if = "Option::is_none")] to keep JSON configuration clean
  • Follows existing patterns in the codebase for optional executor settings
  • When enabled, uses Tokio's Command::env_remove() to remove the environment variable

Benefits

  • ✅ Prevents unexpected API charges for subscription users
  • ✅ Gives users explicit control over authentication method
  • ✅ Backward compatible - existing configurations continue to work unchanged
  • ✅ Simple implementation (8 lines of code)
  • ✅ No frontend changes needed - the setting appears automatically

Testing

The implementation follows the existing patterns in the codebase:

  • Existing Claude executor tests continue to pass
  • The default behavior (not removing API key) is unchanged
  • When the setting is enabled, the API key is removed from the environment before spawning

Screenshots

Setting in Agents Settings Page:
The new checkbox will appear automatically in the ClaudeCode executor configuration form alongside other settings like plan, approvals, and model.

Related

Questions for Reviewers

  1. Should this setting be global or per-configuration? Implementation: Per-configuration (follows existing pattern for executor-specific settings)
  2. Should we show an indicator in the UI when an API key is detected? (Could be a follow-up enhancement)
  3. Would you like any additional logging or warnings when the setting is enabled?

Checklist

This commit adds a new optional setting `use_claude_subscription` to the ClaudeCode
executor configuration. When enabled, this setting removes the ANTHROPIC_API_KEY
environment variable before spawning the Claude Code agent, ensuring that users with
Claude Pro/Team subscriptions can opt to use their subscription instead of being
charged API fees.

## Changes

- Added `use_claude_subscription` optional field to the `ClaudeCode` struct
- Implemented logic in `spawn_internal` to conditionally remove `ANTHROPIC_API_KEY`
  from the environment when the setting is enabled
- Added tracing log when API key is removed for better debugging

## Implementation Details

- The field is optional (`Option<bool>`) and defaults to `false` when not set,
  maintaining backward compatibility
- Uses `#[serde(skip_serializing_if = "Option::is_none")]` to keep JSON clean
- The setting is automatically exposed in the frontend via the JSON Schema
  auto-generation from Rust structs
- TypeScript bindings are auto-generated via the `#[derive(TS)]` macro

## Benefits

- Prevents unexpected API charges for users with Claude subscriptions
- Gives users explicit control over authentication method
- Backward compatible - existing configurations continue to work unchanged
- No frontend changes needed - the setting appears automatically in the
  ExecutorConfigForm

## Related

- Addresses feature request in discussion BloopAI#1228
- Design document: https://github.com/potable-anarchy/vibe-kanban-launcher/blob/main/DESIGN_PROPOSAL.md
@ggordonhall ggordonhall requested a review from abcpro1 November 24, 2025 10:02
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.

1 participant