Invalid API key · Please run /login

Open 💬 24 comments Opened Aug 5, 2025 by dbalata

<details>
<summary>Diagnostic Script</summary>

#!/bin/bash
# Claude Code macOS Diagnostic Script
# Gathers comprehensive info for OAuth authentication bug reports

echo "Claude Code macOS Diagnostic Report"
echo "======================================"
echo ""

# Basic system info
echo "System Information"
echo "OS Version: $(sw_vers -productVersion)"
echo "Architecture: $(uname -m)"
echo "User: $USER"
echo "Shell: $SHELL"
echo ""

# Claude Code installation details
echo "Claude Code Installation"
if command -v claude &> /dev/null; then
    echo "✓ Claude command found"
    echo "Version: $(claude --version 2>/dev/null || echo 'Version check failed')"
    echo "Path: $(which claude)"
    echo "Install type: $(file $(which claude) | cut -d: -f2)"
    
    # Run claude doctor if available
    echo ""
    echo "Claude Doctor Output:"
    claude doctor 2>/dev/null || echo "✗ claude doctor failed"
else
    echo "✗ Claude command not found in PATH"
fi
echo ""

# Environment variables
echo "Environment Variables"
echo "ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:+SET (hidden)} ${ANTHROPIC_API_KEY:-NOT SET}"
echo "CLAUDE_API_KEY: ${CLAUDE_API_KEY:+SET (hidden)} ${CLAUDE_API_KEY:-NOT SET}"
echo "ANTHROPIC_BASE_URL: ${ANTHROPIC_BASE_URL:-NOT SET}"
echo "NODE_ENV: ${NODE_ENV:-NOT SET}"
echo ""

# Configuration files
echo "Configuration Files"
for config_path in ~/.config/claude ~/.local/share/claude ~/Library/Application\ Support/claude ~/.claude; do
    if [ -d "$config_path" ]; then
        echo "✓ Found: $config_path"
        ls -la "$config_path" 2>/dev/null | head -5
    else
        echo "✗ Missing: $config_path"
    fi
done
echo ""

# Keychain analysis
echo "Keychain Analysis"
echo "Checking keychain entries..."

# Check for OAuth credentials
echo "OAuth credentials (Claude Code-credentials):"
if security find-generic-password -s "Claude Code-credentials" &>/dev/null; then
    echo "✓ Found Claude Code-credentials entry"
    security find-generic-password -s "Claude Code-credentials" -g 2>&1 | head -3
else
    echo "✗ No Claude Code-credentials entry found"
fi

# Check for API key storage
echo ""
echo "API key storage (Claude Code):"
if security find-generic-password -s "Claude Code" &>/dev/null; then
    echo "✓ Found Claude Code entry"
    security find-generic-password -s "Claude Code" -g 2>&1 | head -3
else
    echo "✗ No Claude Code entry found"
fi

# Check keychain status
echo ""
echo "Keychain Status"
echo "Default keychain: $(security default-keychain | tr -d '\"')"
echo "Login keychain status:"
security show-keychain-info login.keychain 2>/dev/null || echo "✗ Login keychain issue"

echo ""
echo "Keychain list:"
security list-keychains | head -5

# Process information
echo ""
echo "Process Information"
echo "Claude processes:"
pgrep -fl claude || echo "No Claude processes running"

echo ""
echo "Node.js info:"
if command -v node &> /dev/null; then
    echo "Node version: $(node --version)"
    echo "npm version: $(npm --version)"
else
    echo "✗ Node.js not found"
fi

# Network connectivity
echo ""
echo "Network Connectivity"
echo "Testing Anthropic API connectivity..."
curl -s -o /dev/null -w "HTTP Status: %{http_code}, Time: %{time_total}s\n" https://api.anthropic.com/health || echo "✗ Network test failed"

# Recent logs if available
echo ""
echo "Recent Error Patterns"
echo "Checking for common error signatures..."

# Look for Claude Code errors in system logs (last hour)
log show --predicate 'subsystem == "com.apple.security"' --last 1h --style compact 2>/dev/null | grep -i claude || echo "No security logs found"

echo ""
echo "Quick Test"
echo "Attempting basic Claude Code command..."
timeout 10s claude --help 2>&1 | head -5 || echo "✗ Command test failed"

echo ""
echo "======================================"
echo "Diagnostic complete"
echo ""
echo "Next steps based on findings above:"
echo "1. If OAuth creds found but command fails → macOS keychain permission bug"
echo "2. If no OAuth creds found → authentication didn't store properly"  
echo "3. If network fails → connectivity issue"
echo "4. Share this output with Anthropic support or GitHub issue"

</details>

Claude Code macOS Diagnostic Report
======================================

System Information
OS Version: 15.5
Architecture: arm64
User: [REDACTED]
Shell: /bin/zsh

Claude Code Installation
✓ Claude command found
Version: 1.0.68 (Claude Code)
Path: /Users/[REDACTED]/.local/bin/claude
Install type: Mach-O 64-bit executable arm64

Claude Doctor Output:
Diagnostics
└ Currently running: native (1.0.68)
└ Path: /Users/[REDACTED]/.local/bin/claude
└ Invoked: /$bunfs/root/claude
└ Config install method: native
└ Auto-updates enabled: true

Environment Variables
ANTHROPIC_API_KEY: NOT SET
CLAUDE_API_KEY: NOT SET
ANTHROPIC_BASE_URL: NOT SET
NODE_ENV: NOT SET

Configuration Files
✗ Missing: /Users/[REDACTED]/.config/claude
✓ Found: /Users/[REDACTED]/.local/share/claude
✓ Found: /Users/[REDACTED]/Library/Application Support/claude
✓ Found: /Users/[REDACTED]/.claude

Keychain Analysis
Checking keychain entries...
OAuth credentials (Claude Code-credentials):
✗ No Claude Code-credentials entry found
API key storage (Claude Code):
✗ No Claude Code entry found

Keychain Status
Default keychain: login.keychain
Login keychain status: [OK]

Process Information
Claude processes: No Claude processes running

Network Connectivity
Testing Anthropic API connectivity...
HTTP Status: 200, Time: [REDACTED]s

====================================
Diagnostic complete

Next steps based on findings above:

  1. If OAuth creds found but command fails → macOS keychain permission bug
  2. If no OAuth creds found → authentication didn't store properly
  3. If network fails → connectivity issue
  4. Share this output with Anthropic support or GitHub issue

Key Issue Identified

ISSUE: OAuth login shows "successful" but stores no credentials in keychain, causing immediate "Invalid API key" error on any command execution.

View original on GitHub ↗

24 Comments

github-actions[bot] · 11 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/5166
  2. https://github.com/anthropics/claude-code/issues/5118
  3. https://github.com/anthropics/claude-code/issues/1154

If your issue is a duplicate, please close it and 👍 the existing issue instead.

🤖 Generated with Claude Code

dbalata · 11 months ago

Attempted Fixes

Complete Environment Reset:

  • Nuclear cleanup: removed all config directories, keychain entries, npm packages
  • Fresh native installer: curl -fsSL https://claude.ai/install.sh | bash
  • Verified clean state with claude doctor

Authentication Troubleshooting:

  • Multiple claude logoutclaude login cycles
  • Ensured no API key environment variables set
  • Authenticated using only Pro subscription credentials (avoided mixing with Console/API)
  • Tested from different directories and terminal sessions

macOS Keychain Fixes:

  • Reset default keychains via Keychain Access app
  • Manually deleted all Claude-related keychain entries
  • Verified keychain permissions and login keychain status
  • Checked for keychain corruption with Keychain First Aid

Version/Update Attempts:

  • Updated to latest version: curl -fsSL https://claude.ai/install.sh | bash -s latest
  • Confirmed running 1.0.68 (latest at time of testing)
  • Verified native install vs npm install differences

None of these fixes resolved the issue. The core problem persists: OAuth flow completes successfully but fails to store any credentials in keychain, despite showing "Login successful" message.

Diagnostic Key Finding: security find-generic-password -s "Claude Code-credentials" returns no entries, confirming OAuth credentials are never being written to keychain in the first place.

duanehutchins · 11 months ago

Duplicated the issue here with a fresh install on a fresh machine. Authentication seems to work, but the client is not authenticated.

After logging into claude, it says the api key is invalid. Confirmed that the .credentials.json file doesn't exist, and there are no new API keys created in my Anthropic account.

Temp workaround: I got this working on the new machine by copying the following files/directories from the old (working) device to the new device:

  • ~/.claude/*
  • ~/.claude.json
  • ~/.claude.json.backup
  • {[project/directory}}/.claude/*

This uses the same API key for both machines, which is not ideal, but it got the new machine up and running. I'll re-auth once Anthropic fixes the bug.

Hopefully this helps!

xiaohei-info · 11 months ago

I've solved this issue with Downgrading to 1.0.67:

npm uninstall -g @anthropic-ai/claude-code
npm install -g @anthropic-ai/claude-code@1.0.67
itsthisjustin · 11 months ago

I'm getting this now on a remote SSH terminal but works fine on the actual machine itself.

sleepdefic1t · 11 months ago

@itsthisjustin

  • machine (macos) ✅
  • ssh ❌

tl;dr (via ssh):

security unlock-keychain ~/Library/Keychains/login.keychain-db
astout · 11 months ago

@xiaohei-info

I've solved this issue with Downgrading to 1.0.67: `` npm uninstall -g @anthropic-ai/claude-code npm install -g @anthropic-ai/claude-code@1.0.67 ``

I have 'native' install and downgrading to 1.0.67 didn't work for me.

Tried:

    curl -fsSL https://claude.ai/install.sh | bash -s 1.0.67

Problem persists on 1.0.67 for me.

titofebus · 11 months ago

This issue is still happening I'm noticing it happens every day maybe 24 hours? The way I fix it is:

  1. Uninstall Claude Code
  2. Install 1.00.67
  3. LogIn
  4. /Exit
  5. Open Claude Code

This resolves the problem temporarily for at least 24 hours.

Seeing most people have this problem with SSH and mosh.

itsthisjustin · 11 months ago
This issue is still happening I'm noticing it happens every day maybe 24 hours? The way I fix it is: 1. Uninstall Claude Code 2. Install 1.00.67 3. LogIn 4. /Exit 5. Open Claude Code This resolves the problem temporarily for at least 24 hours. Seeing most people have this problem with SSH and mosh.

Make sure you disable auto updates before you downgrade. Should last now. That was my issue.

ht2k05 · 11 months ago

Same issue on ssh anthropic please fix

kradalby · 10 months ago

I just hit this, I am not using SSH, but I am using tmux for my tab management. Running in my terminal without tmux works fine. Using latest macOS (15.6.1)

superbirds2008 · 10 months ago

 Invalid API key with terminus

Lexing · 10 months ago

If ssh into a Mac, and this error happens. The issue is because Claude cannot read credentials in Mac OS keychain.
Run this and you will be fine

security unlock-keychain ~/Library/Keychains/login.keychain-db
xiaohei-info · 10 months ago
I just hit this, I am not using SSH, but I am using tmux for my tab management. Running in my terminal without tmux works fine. Using latest macOS (15.6.1)

Yes, I'm into this issue too, any idea?

iron-cherep · 10 months ago
If ssh into a Mac, and this error happens. The issue is because Claude cannot read credentials in Mac OS keychain. Run this and you will be fine `` security unlock-keychain ~/Library/Keychains/login.keychain-db ``

Did that with no success. Tried in and out of tmux session - /login inside of mac accessed with ssh always fails silently

TheDirigible · 8 months ago

Same thing on Windows VSCode. And tons of errors on the claude console website. Too bad they don't have billions to fix this.

abbbe · 8 months ago

I have managed to make Claude on remote MacOS over SSH under tmux, based on the info from this thread. Devil is in the details though...

For authentication to work, Claude must have access to keys in the keychain.

To make sure the API key ends up in the keychain of remote MacOS, you have to run Claude from an interactive terminal on that MacOS. Log in there over VNC, run Claude in Terminal, let it open local browser and authorise.

Next SSH into the same MacOS and open tmux. Run "security unlock-keychain ~/Library/Keychains/login.keychain-db" and enter your password. Now you can run claude and it will just work.

github-actions[bot] · 7 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

j-weave · 6 months ago

For anyone still reading this ticket, my coworker fixed this issue for herself via
https://github.com/anthropics/claude-code/issues/64#issuecomment-2683207735

Hopefully that will help at least some people looking into this issue...

Marow · 5 months ago

Same here. Tried with claude code in VS Code. Added some money to my acc, will use it with Anthropic Console, Authorized it and got Invalid API Key.

zjalicf · 5 months ago

same issue here

Hari-Bonda · 5 months ago

same issue

GeckMan · 5 months ago

Happening here as well in Windows VS Code

scissorstail · 4 months ago

VSCode Claude Code extension and native Claude Code use different files.

Windows PowerShell. New-Item -ItemType SymbolicLink -Path .claude\config.json -Target ..\.claude.json -Force