Claude API Key Organization Mismatch — Fix (2026)
The Error
API key belongs to organization org-xxx but request specifies org-yyy
The Fix
# Check which org ID your API key belongs to (visible in Anthropic Console)
# Then set the matching org ID:
export ANTHROPIC_ORG_ID="org-xxx"
# Or remove the org override entirely to use the key's default org:
unset ANTHROPIC_ORG_ID
# Persist in your shell config:
grep -v "ANTHROPIC_ORG_ID" ~/.zshrc > ~/.zshrc.tmp && mv ~/.zshrc.tmp ~/.zshrc
echo 'export ANTHROPIC_ORG_ID="org-xxx"' >> ~/.zshrc
Why This Works
Anthropic API keys are scoped to a specific organization. When Claude Code sends a request with an explicit organization header that differs from the key’s owning organization, the API rejects it. This typically happens when you switch between personal and work accounts, or when environment variables from a previous project linger in your shell.
If That Doesn’t Work
# Check all places where the org might be set:
env | grep -i anthropic
cat ~/.claude/config.json 2>/dev/null | grep -i org
cat .env 2>/dev/null | grep -i org
# Generate a new API key for the correct organization at:
# https://console.anthropic.com/settings/keys
# Then update:
export ANTHROPIC_API_KEY="sk-ant-api03-new-key-here"
Multiple config sources can override each other. Check .env, shell rc files, and Claude config in that order.
Prevention
Add to your CLAUDE.md:
Use one API key per project. Set ANTHROPIC_API_KEY and ANTHROPIC_ORG_ID in the project's .env file (gitignored) rather than global shell config to prevent cross-project org conflicts.
See Also
- Invalid API Key Format sk-ant — Fix (2026)
- Claude API Invalid API Key Format Error — Fix (2026)
- ANTHROPIC_API_KEY Not Set in Subprocess Fix
- Organization Billing Suspended Error — Fix (2026)
- API Key Region Mismatch eu-west-1 — Fix (2026)
Related Error Messages
This fix also applies if you see these related error messages:
fatal: not a git repositoryerror: failed to push some refsfatal: refusing to merge unrelated historiesAuthenticationError: invalid x-api-keyError: API key not found in environment
Frequently Asked Questions
Why does Claude Code require git?
Claude Code uses git for several core operations: tracking file changes, creating commits, reading blame information, searching history with git log, and managing branches. Without git, these operations fail and Claude Code falls back to less efficient alternatives.
Can Claude Code work in a non-git directory?
Yes, but with reduced functionality. File search and editing work normally, but version control operations (commit, diff, blame) are unavailable. Claude Code displays a warning when opened in a directory without git initialization.
How do I prevent Claude Code from making unwanted git operations?
Add rules to your CLAUDE.md: Do not create commits automatically. Do not run git push. Always ask before any git operation that modifies history. Claude Code respects these constraints and asks for confirmation before proceeding.
Where should I store my Anthropic API key?
Store it in the ANTHROPIC_API_KEY environment variable in your shell profile (~/.bashrc, ~/.zshrc). Never hardcode API keys in source code or commit them to version control. For CI/CD, use your platform’s secrets manager.
Related Guides
Try it: Paste your error into our Error Diagnostic for an instant fix.
- Terminal Emulator Rendering Artifacts — Fix (2026)
- How to Use Thirdweb SDK Workflow (2026)
- Python Virtualenv Not Activated — Fix (2026)
- Claude Code Offline Mode Setup (2026)
Implementation Details
When working with this in Claude Code, pay attention to these practical details:
Project configuration. Add specific instructions to your CLAUDE.md file describing how your project handles this area. Include file paths, naming conventions, and any patterns that differ from common defaults. Claude Code reads CLAUDE.md at the start of every session and uses it to guide all operations.
Testing the setup. After configuration, verify everything works by running a simple test task. Ask Claude Code to perform a read-only operation first (like listing files or reading a config) before moving to write operations. This confirms that permissions, paths, and tools are all correctly configured.
Monitoring and iteration. Track your results over several sessions. If Claude Code consistently makes the same mistake, the fix is usually a more specific CLAUDE.md instruction. If it makes different mistakes each time, the issue is likely in the project setup or toolchain configuration.
Troubleshooting Checklist
When something does not work as expected, check these items in order:
- CLAUDE.md exists at the project root — run
ls -la CLAUDE.mdto verify - Node.js version is 18+ — run
node --versionto check - API key is set — run
echo $ANTHROPIC_API_KEY | head -c 10to verify (shows first 10 characters only) - Disk space is available — run
df -h .to check - Network can reach the API — run
curl -s -o /dev/null -w "%{http_code}" https://api.anthropic.com(should return 401 without auth, meaning the server is reachable) - No conflicting processes — run
ps aux | grep claude | grep -v grepto check for stale sessions