I use my own API key in private projects, and it seems to work like this:
# .env file ANTHROPIC_API_KEY=sk-...In the project:
# .claude/settings.json { "apiKeyHelper": "source .env && echo $ANTHROPIC_API_KEY" }Then invoke
claudein inside the project root and verify with/statuscommand:Claude Code v1.0.85 L Session ID: 69... ... Account L Auth Token: apiKeyHelper L API Key: apiKeyHelper
Source: https://github.com/anthropics/claude-code/issues/441#issuecomment-3207226042
If someone get this error: Error getting API key from apiKeyHelper (in settings or ~/.claude.json): /bin/sh: 1: source: not found
That error comes from the fact that your shell (likely /bin/sh) doesn’t recognize the source command — it’s a Bash built-in, not POSIX-standard.
Here's the fix (Force bash):
{ "apiKeyHelper": "bash -c 'source .env && echo $ANTHROPIC_API_KEY'" }
Never teach people to put a secret key in a non-popular env var convention file. Always put it in the popular environment variable file.
Answer from ImBIOS on Stack OverflowVideos
I use my own API key in private projects, and it seems to work like this:
# .env file ANTHROPIC_API_KEY=sk-...In the project:
# .claude/settings.json { "apiKeyHelper": "source .env && echo $ANTHROPIC_API_KEY" }Then invoke
claudein inside the project root and verify with/statuscommand:Claude Code v1.0.85 L Session ID: 69... ... Account L Auth Token: apiKeyHelper L API Key: apiKeyHelper
Source: https://github.com/anthropics/claude-code/issues/441#issuecomment-3207226042
If someone get this error: Error getting API key from apiKeyHelper (in settings or ~/.claude.json): /bin/sh: 1: source: not found
That error comes from the fact that your shell (likely /bin/sh) doesn’t recognize the source command — it’s a Bash built-in, not POSIX-standard.
Here's the fix (Force bash):
{ "apiKeyHelper": "bash -c 'source .env && echo $ANTHROPIC_API_KEY'" }
Never teach people to put a secret key in a non-popular env var convention file. Always put it in the popular environment variable file.
Looks like folks found a workaround that actually works: https://github.com/anthropics/claude-code/issues/441#issuecomment-3050967059
Create a
~/.claude/settings.jsonfile with this content:{ "apiKeyHelper": "echo <API KEY>" }
I've been trying to do something like `export ANTHROPIC_API_KEY=sk...` to set an api key for claude code but when I do I get a message telling me to either do `claude /logout` or unset the api key.
When I run `claude /logout` I am prompted to log back in and authenticate with anthropic. It seems as though I cannot just set an api key and use claude code. They are forcing me to login.
Does anyone know if I am mistaken or if there's a way around this?