claudecodeui icon indicating copy to clipboard operation
claudecodeui copied to clipboard

Credit balance is too low although it should use claude account

Open saulide opened this issue 6 months ago • 2 comments

Im using the 1.7.0 and encouter this problem:

I started the project with an API key once, now i switched to the claude account. In my .claude/settings.json settings i have forceLoginMethod set to claude.

But i i want to write something to the claude in the UI, i get Credit balance is too low . If i switch to shell in the , and type the same again, then it works, but just in the shell.

Any Ideas how to fix that? Or is it a bug?

saulide avatar Aug 27 '25 10:08 saulide

Fixed with following addition of code.

console.log('🔍 Final Claude command will be: claude ' + args.join(' '));

// Read Claude settings to check authentication preference
const claudeSettings = await getClaudeSettings();

// Prepare environment for Claude CLI
const claudeEnv = { ...process.env };

// Handle authentication method based on forceLoginMethod setting:
// - "claudeai" = use Claude.ai account (remove API key)
// - "console" = use API key (keep API key)
// - not set = use API key if available (keep API key)
if (claudeSettings.forceLoginMethod === 'claudeai' && claudeEnv.ANTHROPIC_API_KEY) {
  delete claudeEnv.ANTHROPIC_API_KEY;
  console.log('🔐 Removed ANTHROPIC_API_KEY because forceLoginMethod is set to "claudeai" (use Claude.ai account)');
} else if (claudeSettings.forceLoginMethod === 'console') {
  console.log('🔐 Keeping ANTHROPIC_API_KEY because forceLoginMethod is set to "console" (use API key)');
} else if (claudeSettings.forceLoginMethod) {
  console.log('🔐 Keeping ANTHROPIC_API_KEY because forceLoginMethod is set to:', claudeSettings.forceLoginMethod);
} else if (claudeEnv.ANTHROPIC_API_KEY) {
  console.log('🔐 Keeping ANTHROPIC_API_KEY (no forceLoginMethod setting found)');
}

console.log('🔐 Environment check:');
console.log('  HOME:', claudeEnv.HOME);
console.log('  USER:', claudeEnv.USER);
console.log('  ANTHROPIC_API_KEY:', claudeEnv.ANTHROPIC_API_KEY ? 'present' : 'removed');
console.log('  forceLoginMethod:', claudeSettings.forceLoginMethod || 'not set');
console.log('  Working directory:', workingDir);

const claudeProcess = spawnFunction('claude', args, {
  cwd: workingDir,
  stdio: ['pipe', 'pipe', 'pipe'],
  env: claudeEnv
});

saulide avatar Aug 27 '25 10:08 saulide

@saulide would you be able to create a PR for this? Does this happen if you start with a fresh install on 1.8.1?

viper151 avatar Sep 16 '25 15:09 viper151