Skip to content

Bug: Extension Fails for Subscription Users if ANTHROPIC_API_KEY is setΒ #7196

@coygeek

Description

@coygeek

App Version

3.25.17

API Provider

Not Applicable / Other

Model Used

Claude Code

Roo Code Task Links (Optional)

Title: Bug: Extension Fails for Subscription Users if ANTHROPIC_API_KEY is set

Description

When the extension is correctly configured to use Claude Code as the API Provider, it fails if an ANTHROPIC_API_KEY environment variable is present in the user's shell environment.

This leads to a confusing Credit balance is too low error for users with Claude Max/Pro subscriptions. They have correctly set up the extension to use their local CLI (to leverage their flat-rate subscription), but an old, lingering API key from a separate pay-as-you-go account intercepts the authentication and causes the failure.

This makes the extension seem broken even when the user has configured it perfectly according to its own settings.

Steps to Reproduce

  1. Have an active Claude Max or Pro subscription.

  2. Install the claude code CLI and log in successfully using your subscription account (/login).

  3. In your shell profile (e.g., ~/.zshrc), set an ANTHROPIC_API_KEY environment variable from a separate, pay-as-you-go Console account that has a zero-dollar balance.

  4. Load the environment variable in your shell (source ~/.zshrc).

  5. In the Cline/Roo Code extension settings, set the API Provider to Claude Code and ensure the Claude Code CLI Path points to your local installation.

  6. Attempt to run any command through the extension's UI.

Expected Behavior

Since the API Provider is set to Claude Code, the extension should successfully use the CLI's active subscription-based login (claudeai method). It should either ignore the ANTHROPIC_API_KEY environment variable or warn the user about the potential conflict.

Actual Behavior

The extension's background call to the claude code CLI prioritizes the ANTHROPIC_API_KEY environment variable. This results in an API call using the old, unfunded account, which is immediately rejected.

The user sees the error: Command failed with exit code 1: ... Credit balance is too low.

Root Cause Analysis

The claude code CLI has different authentication pathways for interactive use versus non-interactive/SDK use (which the extension uses via the -p flag). The non-interactive mode defaults to using the ANTHROPIC_API_KEY if it is set, bypassing the user's interactive subscription login. This makes the extension's "API Provider" setting fail silently.

Workaround / Solution

The issue was successfully resolved by performing the following step:

  1. Removing the Environment Variable: Manually removing the export ANTHROPIC_API_KEY="..." line from the user's shell profile (~/.zshrc).

Proposed Solutions for the Extension

This issue creates a very poor user experience for legitimate subscription customers. The extension could help mitigate this significantly:

  1. High Priority - Detection and Warning: On startup, the extension should check process.env.ANTHROPIC_API_KEY. If the key is set and the API Provider is set to Claude Code, the extension must show a prominent VS Code warning notification. The warning should state: "An ANTHROPIC_API_KEY environment variable was detected. This may conflict with your subscription login and cause errors. Please unset it to ensure your Claude Max/Pro plan is used."
  2. Documentation: Add a section to the README specifically for Claude Max/Pro users, instructing them to ensure ANTHROPIC_API_KEY is not set in their environment.

Thank you for the excellent tool. Addressing this conflict will greatly improve the experience for subscription users.

πŸ” Steps to Reproduce

.

πŸ’₯ Outcome Summary

.

πŸ“„ Relevant Logs or Errors (Optional)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue/PR - TriageNew issue. Needs quick review to confirm validity and assign labels.bugSomething isn't workingdocumentationImprovements or additions to documentation

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions