Solved: How to use an Anthropic Claude API key without browser login
Was teaching agentic AI today. Hit a stupid roadblock during the hands-on part.
The plan: Generate a temp Claude API key with strict limits, share it with students, revoke after class. No need for everyone to have paid accounts. Simple.
What actually happened: The Anthropic client library completely broke the workflow. Every time someone used the key, it forced open a browser demanding organizational login. Can’t give 20 students access to my org settings - that’s insane.
Searched everywhere for a way to disable this. Nothing in the docs.
Then a student finds this Reddit thread with the exact fix. Turns out it’s a common problem - CI/CD pipelines, automated scripts, team sharing - everyone hits this wall. The solution? One undocumented parameter in the client.
Writing this down because:
- I’ll forget otherwise
- You’ll probably hit the same issue
- The official docs won’t help you
The fix exists. It’s just hidden like some secret handshake.
The fix
Here is the fix (for macOS and Linux):
Add/edit ~/.claude/settings.json to have:
{
"apiKeyHelper": "~/.claude/anthropic_key.sh"
}
Add your key to ~/.claude/anthropic_key.sh:
echo "sk-........."
chmod +x ~/.claude/anthropic_key.sh