Skip to main content

Command Palette

Search for a command to run...

Setting up Claude-Code with API Key

Updated
1 min read

As of the writing of this blog post, there was no straight forward way to use API key with Claude code.

I found following way

I have figured out following way, but not sure if they will change something in future which will break this, by the time you read this article.

But anyways, here is the simple steps:

  1. Open ~/.claude/settings.json file in your editor and put following code:

cat ~/.claude/settings.json

{
  "apiKeyHelper": "~/.claude/anthropic_key.sh"
}
  1. Now create that shell script file, and open in your code editor e.g: vi ~/.claude/anthropic_key.sh and put following content in it, replace with your correct API key here.
echo "sk_your_anthropic_api_key"
  1. Make the shell script executable
sudo chmod +x ~/.claude/anthropic_key.sh

That’s it, now if you run claude it should confirm with you do you really want to API key, you should say yes or choose the option that says yes

Enjoy!!