[BUG] Keychain Error on Re-authentication

Resolved 💬 4 comments Opened Oct 30, 2025 by rr-vishnu-sasi Closed Jan 12, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When attempting to re-authenticate with Claude Code after a previous login attempt, users receive the error: "Unable to save API key to macOS Keychain. Please ensure VS Code has keychain access permissions."

This occurs even when VS Code has proper keychain permissions. The actual issue is that the extension fails to update an existing keychain entry.

The extension attempts to run:
security add-generic-password -a [username] -s "Claude Code" -w [api-key]

This fails with exit code 45: SecKeychainItemCreateFromContent: The specified item already exists in the keychain

The error is caught and displayed as a misleading permissions error.

What Should Happen?

The extension should either:

  • Update the existing keychain entry with the new API key, OR
  • Delete the old entry before creating a new one, OR
  • Provide a clear error message about the conflicting entry

Error Messages/Logs

Unable to save API key to macOS Keychain. Please ensure VS Code has keychain access permission.

Steps to Reproduce

  1. Initial Setup:
  • Install Claude Code extension v2.0.29 in VS Code
  • Complete the login/authorization flow successfully
  • API key is saved to macOS keychain with service name "Claude Code"
  1. Trigger the Bug:
  • Log out of Claude Code OR
  • Attempt to login with a different API key OR
  • The authentication token expires and you need to re-authenticate
  1. Reproduce the Error:
  • Click "Sign in with Rakuten AI Gateway" (or equivalent login button)
  • Complete the authentication flow
  • Error appears: "Unable to save API key to macOS Keychain. Please ensure VS Code has keychain access permissions."
  1. Verify the Root Cause:

security find-generic-password -s "Claude Code" -a "$(whoami)"

  1. This will show an existing keychain entry

Claude Model

Not sure / Multiple models

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.0.29

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗