Invalid API key · Please run /login
<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:
- If OAuth creds found but command fails → macOS keychain permission bug
- If no OAuth creds found → authentication didn't store properly
- If network fails → connectivity issue
- 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.
24 Comments
Found 3 possible duplicate issues:
If your issue is a duplicate, please close it and 👍 the existing issue instead.
🤖 Generated with Claude Code
Attempted Fixes
Complete Environment Reset:
curl -fsSL https://claude.ai/install.sh | bashclaude doctorAuthentication Troubleshooting:
claude logout→claude logincyclesmacOS Keychain Fixes:
Version/Update Attempts:
curl -fsSL https://claude.ai/install.sh | bash -s latestNone 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.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.jsonfile 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!
I've solved this issue with Downgrading to 1.0.67:
I'm getting this now on a remote SSH terminal but works fine on the actual machine itself.
@itsthisjustin
tl;dr (via ssh):
@xiaohei-info
I have 'native' install and downgrading to 1.0.67 didn't work for me.
Tried:
Problem persists on 1.0.67 for me.
This issue is still happening I'm noticing it happens every day maybe 24 hours? The way I fix it is:
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.
Same issue on ssh anthropic please fix
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)
Invalid API key with terminus
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
Yes, I'm into this issue too, any idea?
Did that with no success. Tried in and out of tmux session -
/logininside of mac accessed with ssh always fails silentlySame thing on Windows VSCode. And tons of errors on the claude console website. Too bad they don't have billions to fix this.
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.
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.
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...
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.
same issue here
same issue
Happening here as well in Windows VS Code
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