[{"data":1,"prerenderedAt":58},["ShallowReactive",2],{"blog-claude-code-secrets":3,"blog-related-claude-code-secrets":39},{"slug":4,"title":5,"description":6,"category":7,"categoryId":8,"keyword":9,"date":10,"minutes":11,"body":12,"html":13,"headings":14},"claude-code-secrets","Claude Code and API keys: keep your secrets out of the chat","How to give Claude Code the API keys it needs without leaking them: environment variables, .env and .gitignore, deny rules, the sandbox and the Keychain.","Getting started","getting-started","claude code api keys","2026-11-25",6,"Claude Code works with your access. It reads your files, runs your commands and calls your APIs, so sooner or later it needs a key: Stripe in test mode, a database URL, a token for your deploy. The risk isn't that Claude steals it. It's that the key ends up somewhere it shouldn't: printed in a tool result, pasted into code, committed, or sitting in a transcript on disk. A few habits keep keys usable by Claude and out of everything else.\n\n## Where can a key leak in a Claude Code session?\n\nMore places than people expect:\n\n- **Tool output.** `cat .env`, `env`, `printenv`, `echo $STRIPE_KEY`, or `curl -v` showing its headers. Whatever a command prints goes into the conversation, is sent to the model, and stays there.\n- **Transcripts.** Every session is saved as plain text JSON lines under `~\u002F.claude\u002Fprojects\u002F` and kept for 30 days by default. A key printed once is in that file.\n- **Code.** Asked to \"make the webhook work\", Claude may write the key straight into a file if that's where it saw it.\n- **Commits.** A `.env` that isn't ignored, a config file with a token, a test fixture made from a real response.\n- **Settings.** Values in the `env` block of a `settings.json` are plain text, reach every process Claude Code starts, and a project's `.claude\u002Fsettings.json` is usually committed.\n- **Your prompts.** Pasting a key into the chat to \"just try it\" puts it in the transcript too.\n\nThe rule that covers all of these: **Claude should use a key by its name, never see its value.**\n\n## How should you give Claude Code a key?\n\nThrough environment variables, set before Claude Code starts. Every command it runs inherits them, so it can write:\n\n```sh\ncurl -s https:\u002F\u002Fapi.stripe.com\u002Fv1\u002Fbalance -u \"$STRIPE_KEY:\"\n```\n\nThe command as recorded says `$STRIPE_KEY`. The shell fills in the value when it runs, and the value never appears in the conversation, as long as the command doesn't print it.\n\nWhere do the variables come from? Not from a file Claude reads. Three good sources:\n\n**Your app's own `.env`, loaded by your app.** If your code reads `.env` at startup (dotenv and most frameworks do), Claude never needs to open it. It runs `npm run dev` and the app finds its keys.\n\n**The macOS Keychain.** Store the key once:\n\n```sh\nsecurity add-generic-password -a \"$USER\" -s larkspur-stripe-test -w\n```\n\nWith `-w` last and no value, `security` asks for it, so it doesn't land in your shell history. Then load it when you start Claude Code, in a small wrapper or a direnv `.envrc`:\n\n```sh\nexport STRIPE_KEY=\"$(security find-generic-password -s larkspur-stripe-test -w)\"\n```\n\nOn Linux, `secret-tool store --label=stripe service larkspur-stripe` and `secret-tool lookup service larkspur-stripe` do the same with the system keyring.\n\n**A secrets manager's CLI**, if your team already uses one, injecting variables into the command that starts `claude`.\n\n## How do you stop Claude Code from reading .env?\n\nWith deny rules. In the project's `.claude\u002Fsettings.json`:\n\n```json\n{\n  \"permissions\": {\n    \"deny\": [\n      \"Read(.\u002F.env)\",\n      \"Read(.\u002F.env.*)\",\n      \"Read(.\u002Fsecrets\u002F**)\",\n      \"Read(~\u002F.aws\u002F**)\",\n      \"Read(~\u002F.ssh\u002F**)\"\n    ]\n  }\n}\n```\n\nDeny rules win over everything else: Claude Code checks deny, then ask, then allow. A `Read` deny also blocks Edit and Write on the same path. And it goes further than the Read tool: in a Bash command Claude Code can analyze, the rule also applies to file commands it recognizes, such as `cat`, `head`, `tail`, `sed` and `tee`, and to redirections. `cat .env` is refused.\n\nKnow the limits:\n\n- A command that reads files without naming them, such as `grep -r STRIPE .`, isn't covered.\n- A Python or Node script that opens the file itself isn't covered.\n- A `.claudeignore` file does nothing. Move its entries into `Read` deny rules.\n- Paths: `.\u002F` and plain paths are relative to the working directory, `~\u002F` is your home, `\u002F\u002F` starts an absolute path. A single leading `\u002F` is relative to where the settings file applies (the project root, for a project's settings), not the root of the disk.\n\n### When do you need the sandbox?\n\nWhen \"Claude Code usually won't\" isn't good enough. The sandbox restricts what Bash commands can actually read and reach, at the operating system level. It's off by default; turn it on with `\u002Fsandbox`, or in settings:\n\n```json\n{\n  \"sandbox\": {\n    \"enabled\": true,\n    \"filesystem\": { \"denyRead\": [\"~\u002F.aws\u002Fcredentials\"] }\n  }\n}\n```\n\nYour `Read` deny rules are added to `denyRead` for you, so the `grep -r` and the Python script above are blocked too. The sandbox covers commands, not Claude's own file tools, which is why you keep both: deny rules for the tools, the sandbox for everything Bash runs.\n\n## Should .env be in .gitignore?\n\nAlways. Ignore every variant and commit an example with names only:\n\n```text\n# .gitignore\n.env\n.env.*\n!.env.example\n```\n\n```text\n# .env.example\nSTRIPE_KEY=\nDATABASE_URL=\n```\n\nCheck it took: `git check-ignore -v .env` should print the rule. The example file is useful to Claude too: it learns which variables exist without seeing a value.\n\nIf a key was ever committed, **rotate it**. Rewriting history doesn't help once it has been pushed, and probably cloned.\n\n## How do you keep Claude from printing a key?\n\nSay it in `CLAUDE.md`, where Claude reads it every session:\n\n```markdown\n## Secrets\n- Use keys through their environment variables ($STRIPE_KEY). Never echo,\n  print, log or write a key's value, and never put one in code or a commit.\n- To check a key is set: `test -n \"$STRIPE_KEY\" && echo set`.\n- Never use curl -v or print request headers.\n```\n\nThat covers almost every case, but `CLAUDE.md` is a request, not a rule. For a hard stop, a `PreToolUse` [hook](\u002Fblog\u002Fclaude-code-hooks) on Bash can refuse the commands that dump the environment:\n\n```sh\n#!\u002Fbin\u002Fbash\n# .claude\u002Fhooks\u002Fno-env-dump.sh — registered on PreToolUse, matcher \"Bash\"\ncmd=$(jq -r '.tool_input.command \u002F\u002F empty')\nif grep -Eq '(^|[;&|[:space:]])(printenv|(env|set)[[:space:]]*($|[;&|]))|echo .*\\$[A-Z_]*(KEY|TOKEN|SECRET)' \u003C\u003C\u003C\"$cmd\"; then\n  echo \"Blocked: this would print secrets. Use the variable without printing it.\" >&2\n  exit 2\nfi\n```\n\nExit code 2 cancels the call and shows Claude the reason, so it takes another route. Treat a hook like this as a guard rail, not a wall: a determined script can always get around a pattern. The wall is the sandbox.\n\n## Where does Claude Code keep its own credentials?\n\nYour Claude login is a secret too. On macOS it's stored in the encrypted Keychain. On Linux it's `~\u002F.claude\u002F.credentials.json` with mode `0600`, and on Windows `%USERPROFILE%\\.claude\\.credentials.json`, protected like the rest of your profile.\n\nIf you use an Anthropic API key, don't put it in the `env` block of a settings file. Export it from the Keychain as above, or use `apiKeyHelper`, a setting that points to a script printing the key, so Claude Code fetches it when it needs it. And check `\u002Fstatus`: a stray `ANTHROPIC_API_KEY` in your shell switches Claude Code from your plan to API billing ([API key or subscription](\u002Fblog\u002Fclaude-code-api-key-vs-subscription) explains why).\n\n## What should you do if a key leaked?\n\n1. **Rotate it** at the provider, right away. Everything else is cleanup.\n2. **Find the copies.** `grep -rl 'sk_live_' ~\u002F.claude\u002Fprojects` lists the transcripts that contain a Stripe live key; use your key's own prefix. Delete those files if you don't need the sessions.\n3. **Check git:** `git log -p -S 'sk_live_'` finds the commits that added or removed it.\n4. **Shrink the next one.** Use restricted, read-only or test keys where the service offers them. A leaked key that can only read balances is a bad day, not a disaster.\n\n## In Relais\n\nIn Relais, keys live in the Vault. Each one is kept in your Mac's Keychain, never in Relais's own config file nor in an export, and given as environment variables to the sessions of the agents you pick. Agents are told to use keys through their variables and never print them. When an agent needs a key it doesn't have, it asks with a card in its conversation: you type the value in a masked field, it goes to the Keychain, and the agent's next sessions have it without ever seeing it. The Keychain keeps keys out of files and exports; inside a session, the habits above still apply. Relais also removes `ANTHROPIC_API_KEY` from what it starts, so your Claude plan is never swapped for API billing. See [the Vault](\u002Ffeatures\u002Fvault) and [sharing agents and data with your team](\u002Fblog\u002Fshare-ai-agents-with-your-team).","\u003Cp>Claude Code works with your access. It reads your files, runs your commands and calls your APIs, so sooner or later it needs a key: Stripe in test mode, a database URL, a token for your deploy. The risk isn&#39;t that Claude steals it. It&#39;s that the key ends up somewhere it shouldn&#39;t: printed in a tool result, pasted into code, committed, or sitting in a transcript on disk. A few habits keep keys usable by Claude and out of everything else.\u003C\u002Fp>\n\u003Ch2 id=\"where-can-a-key-leak-in-a-claude-code-session\">\u003Ca class=\"anchor\" href=\"#where-can-a-key-leak-in-a-claude-code-session\" aria-label=\"Link to this section\">#\u003C\u002Fa>Where can a key leak in a Claude Code session?\u003C\u002Fh2>\n\u003Cp>More places than people expect:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>\u003Cstrong>Tool output.\u003C\u002Fstrong> \u003Ccode>cat .env\u003C\u002Fcode>, \u003Ccode>env\u003C\u002Fcode>, \u003Ccode>printenv\u003C\u002Fcode>, \u003Ccode>echo $STRIPE_KEY\u003C\u002Fcode>, or \u003Ccode>curl -v\u003C\u002Fcode> showing its headers. Whatever a command prints goes into the conversation, is sent to the model, and stays there.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Transcripts.\u003C\u002Fstrong> Every session is saved as plain text JSON lines under \u003Ccode>~\u002F.claude\u002Fprojects\u002F\u003C\u002Fcode> and kept for 30 days by default. A key printed once is in that file.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Code.\u003C\u002Fstrong> Asked to &quot;make the webhook work&quot;, Claude may write the key straight into a file if that&#39;s where it saw it.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Commits.\u003C\u002Fstrong> A \u003Ccode>.env\u003C\u002Fcode> that isn&#39;t ignored, a config file with a token, a test fixture made from a real response.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Settings.\u003C\u002Fstrong> Values in the \u003Ccode>env\u003C\u002Fcode> block of a \u003Ccode>settings.json\u003C\u002Fcode> are plain text, reach every process Claude Code starts, and a project&#39;s \u003Ccode>.claude\u002Fsettings.json\u003C\u002Fcode> is usually committed.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Your prompts.\u003C\u002Fstrong> Pasting a key into the chat to &quot;just try it&quot; puts it in the transcript too.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Cp>The rule that covers all of these: \u003Cstrong>Claude should use a key by its name, never see its value.\u003C\u002Fstrong>\u003C\u002Fp>\n\u003Ch2 id=\"how-should-you-give-claude-code-a-key\">\u003Ca class=\"anchor\" href=\"#how-should-you-give-claude-code-a-key\" aria-label=\"Link to this section\">#\u003C\u002Fa>How should you give Claude Code a key?\u003C\u002Fh2>\n\u003Cp>Through environment variables, set before Claude Code starts. Every command it runs inherits them, so it can write:\u003C\u002Fp>\n\u003Cpre class=\"code\" data-lang=\"sh\">\u003Ccode>curl -s https:\u002F\u002Fapi.stripe.com\u002Fv1\u002Fbalance -u &quot;$STRIPE_KEY:&quot;\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>The command as recorded says \u003Ccode>$STRIPE_KEY\u003C\u002Fcode>. The shell fills in the value when it runs, and the value never appears in the conversation, as long as the command doesn&#39;t print it.\u003C\u002Fp>\n\u003Cp>Where do the variables come from? Not from a file Claude reads. Three good sources:\u003C\u002Fp>\n\u003Cp>\u003Cstrong>Your app&#39;s own \u003Ccode>.env\u003C\u002Fcode>, loaded by your app.\u003C\u002Fstrong> If your code reads \u003Ccode>.env\u003C\u002Fcode> at startup (dotenv and most frameworks do), Claude never needs to open it. It runs \u003Ccode>npm run dev\u003C\u002Fcode> and the app finds its keys.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>The macOS Keychain.\u003C\u002Fstrong> Store the key once:\u003C\u002Fp>\n\u003Cpre class=\"code\" data-lang=\"sh\">\u003Ccode>security add-generic-password -a &quot;$USER&quot; -s larkspur-stripe-test -w\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>With \u003Ccode>-w\u003C\u002Fcode> last and no value, \u003Ccode>security\u003C\u002Fcode> asks for it, so it doesn&#39;t land in your shell history. Then load it when you start Claude Code, in a small wrapper or a direnv \u003Ccode>.envrc\u003C\u002Fcode>:\u003C\u002Fp>\n\u003Cpre class=\"code\" data-lang=\"sh\">\u003Ccode>export STRIPE_KEY=&quot;$(security find-generic-password -s larkspur-stripe-test -w)&quot;\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>On Linux, \u003Ccode>secret-tool store --label=stripe service larkspur-stripe\u003C\u002Fcode> and \u003Ccode>secret-tool lookup service larkspur-stripe\u003C\u002Fcode> do the same with the system keyring.\u003C\u002Fp>\n\u003Cp>\u003Cstrong>A secrets manager&#39;s CLI\u003C\u002Fstrong>, if your team already uses one, injecting variables into the command that starts \u003Ccode>claude\u003C\u002Fcode>.\u003C\u002Fp>\n\u003Ch2 id=\"how-do-you-stop-claude-code-from-reading-env\">\u003Ca class=\"anchor\" href=\"#how-do-you-stop-claude-code-from-reading-env\" aria-label=\"Link to this section\">#\u003C\u002Fa>How do you stop Claude Code from reading .env?\u003C\u002Fh2>\n\u003Cp>With deny rules. In the project&#39;s \u003Ccode>.claude\u002Fsettings.json\u003C\u002Fcode>:\u003C\u002Fp>\n\u003Cpre class=\"code\" data-lang=\"json\">\u003Ccode>{\n  \u003Cspan class=\"hljs-string\">\"permissions\"\u003C\u002Fspan>: {\n    \u003Cspan class=\"hljs-string\">\"deny\"\u003C\u002Fspan>: [\n      \u003Cspan class=\"hljs-string\">\"Read(.\u002F.env)\"\u003C\u002Fspan>,\n      \u003Cspan class=\"hljs-string\">\"Read(.\u002F.env.*)\"\u003C\u002Fspan>,\n      \u003Cspan class=\"hljs-string\">\"Read(.\u002Fsecrets\u002F**)\"\u003C\u002Fspan>,\n      \u003Cspan class=\"hljs-string\">\"Read(~\u002F.aws\u002F**)\"\u003C\u002Fspan>,\n      \u003Cspan class=\"hljs-string\">\"Read(~\u002F.ssh\u002F**)\"\u003C\u002Fspan>\n    ]\n  }\n}\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Deny rules win over everything else: Claude Code checks deny, then ask, then allow. A \u003Ccode>Read\u003C\u002Fcode> deny also blocks Edit and Write on the same path. And it goes further than the Read tool: in a Bash command Claude Code can analyze, the rule also applies to file commands it recognizes, such as \u003Ccode>cat\u003C\u002Fcode>, \u003Ccode>head\u003C\u002Fcode>, \u003Ccode>tail\u003C\u002Fcode>, \u003Ccode>sed\u003C\u002Fcode> and \u003Ccode>tee\u003C\u002Fcode>, and to redirections. \u003Ccode>cat .env\u003C\u002Fcode> is refused.\u003C\u002Fp>\n\u003Cp>Know the limits:\u003C\u002Fp>\n\u003Cul>\n\u003Cli>A command that reads files without naming them, such as \u003Ccode>grep -r STRIPE .\u003C\u002Fcode>, isn&#39;t covered.\u003C\u002Fli>\n\u003Cli>A Python or Node script that opens the file itself isn&#39;t covered.\u003C\u002Fli>\n\u003Cli>A \u003Ccode>.claudeignore\u003C\u002Fcode> file does nothing. Move its entries into \u003Ccode>Read\u003C\u002Fcode> deny rules.\u003C\u002Fli>\n\u003Cli>Paths: \u003Ccode>.\u002F\u003C\u002Fcode> and plain paths are relative to the working directory, \u003Ccode>~\u002F\u003C\u002Fcode> is your home, \u003Ccode>\u002F\u002F\u003C\u002Fcode> starts an absolute path. A single leading \u003Ccode>\u002F\u003C\u002Fcode> is relative to where the settings file applies (the project root, for a project&#39;s settings), not the root of the disk.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch3 id=\"when-do-you-need-the-sandbox\">\u003Ca class=\"anchor\" href=\"#when-do-you-need-the-sandbox\" aria-label=\"Link to this section\">#\u003C\u002Fa>When do you need the sandbox?\u003C\u002Fh3>\n\u003Cp>When &quot;Claude Code usually won&#39;t&quot; isn&#39;t good enough. The sandbox restricts what Bash commands can actually read and reach, at the operating system level. It&#39;s off by default; turn it on with \u003Ccode>\u002Fsandbox\u003C\u002Fcode>, or in settings:\u003C\u002Fp>\n\u003Cpre class=\"code\" data-lang=\"json\">\u003Ccode>{\n  \u003Cspan class=\"hljs-string\">\"sandbox\"\u003C\u002Fspan>: {\n    \u003Cspan class=\"hljs-string\">\"enabled\"\u003C\u002Fspan>: \u003Cspan class=\"hljs-keyword\">true\u003C\u002Fspan>,\n    \u003Cspan class=\"hljs-string\">\"filesystem\"\u003C\u002Fspan>: { \u003Cspan class=\"hljs-string\">\"denyRead\"\u003C\u002Fspan>: [\u003Cspan class=\"hljs-string\">\"~\u002F.aws\u002Fcredentials\"\u003C\u002Fspan>] }\n  }\n}\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Your \u003Ccode>Read\u003C\u002Fcode> deny rules are added to \u003Ccode>denyRead\u003C\u002Fcode> for you, so the \u003Ccode>grep -r\u003C\u002Fcode> and the Python script above are blocked too. The sandbox covers commands, not Claude&#39;s own file tools, which is why you keep both: deny rules for the tools, the sandbox for everything Bash runs.\u003C\u002Fp>\n\u003Ch2 id=\"should-env-be-in-gitignore\">\u003Ca class=\"anchor\" href=\"#should-env-be-in-gitignore\" aria-label=\"Link to this section\">#\u003C\u002Fa>Should .env be in .gitignore?\u003C\u002Fh2>\n\u003Cp>Always. Ignore every variant and commit an example with names only:\u003C\u002Fp>\n\u003Cpre class=\"code\" data-lang=\"text\">\u003Ccode># .gitignore\n.env\n.env.*\n!.env.example\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cpre class=\"code\" data-lang=\"text\">\u003Ccode># .env.example\nSTRIPE_KEY=\nDATABASE_URL=\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Check it took: \u003Ccode>git check-ignore -v .env\u003C\u002Fcode> should print the rule. The example file is useful to Claude too: it learns which variables exist without seeing a value.\u003C\u002Fp>\n\u003Cp>If a key was ever committed, \u003Cstrong>rotate it\u003C\u002Fstrong>. Rewriting history doesn&#39;t help once it has been pushed, and probably cloned.\u003C\u002Fp>\n\u003Ch2 id=\"how-do-you-keep-claude-from-printing-a-key\">\u003Ca class=\"anchor\" href=\"#how-do-you-keep-claude-from-printing-a-key\" aria-label=\"Link to this section\">#\u003C\u002Fa>How do you keep Claude from printing a key?\u003C\u002Fh2>\n\u003Cp>Say it in \u003Ccode>CLAUDE.md\u003C\u002Fcode>, where Claude reads it every session:\u003C\u002Fp>\n\u003Cpre class=\"code\" data-lang=\"markdown\">\u003Ccode>## Secrets\n- Use keys through their environment variables ($STRIPE_KEY). Never echo,\n  print, log or write a key's value, and never put one in code or a commit.\n- To check a key is set: `test -n &quot;$STRIPE_KEY&quot; &amp;&amp; echo set`.\n- Never use curl -v or print request headers.\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>That covers almost every case, but \u003Ccode>CLAUDE.md\u003C\u002Fcode> is a request, not a rule. For a hard stop, a \u003Ccode>PreToolUse\u003C\u002Fcode> \u003Ca href=\"\u002Fblog\u002Fclaude-code-hooks\">hook\u003C\u002Fa> on Bash can refuse the commands that dump the environment:\u003C\u002Fp>\n\u003Cpre class=\"code\" data-lang=\"sh\">\u003Ccode>#!\u002Fbin\u002Fbash\n# .claude\u002Fhooks\u002Fno-env-dump.sh — registered on PreToolUse, matcher &quot;Bash&quot;\ncmd=$(jq -r '.tool_input.command \u002F\u002F empty')\nif grep -Eq '(^|[;&amp;|[:space:]])(printenv|(env|set)[[:space:]]*($|[;&amp;|]))|echo .*\\$[A-Z_]*(KEY|TOKEN|SECRET)' &lt;&lt;&lt;&quot;$cmd&quot;; then\n  echo &quot;Blocked: this would print secrets. Use the variable without printing it.&quot; &gt;&amp;2\n  exit 2\nfi\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>Exit code 2 cancels the call and shows Claude the reason, so it takes another route. Treat a hook like this as a guard rail, not a wall: a determined script can always get around a pattern. The wall is the sandbox.\u003C\u002Fp>\n\u003Ch2 id=\"where-does-claude-code-keep-its-own-credentials\">\u003Ca class=\"anchor\" href=\"#where-does-claude-code-keep-its-own-credentials\" aria-label=\"Link to this section\">#\u003C\u002Fa>Where does Claude Code keep its own credentials?\u003C\u002Fh2>\n\u003Cp>Your Claude login is a secret too. On macOS it&#39;s stored in the encrypted Keychain. On Linux it&#39;s \u003Ccode>~\u002F.claude\u002F.credentials.json\u003C\u002Fcode> with mode \u003Ccode>0600\u003C\u002Fcode>, and on Windows \u003Ccode>%USERPROFILE%\\.claude\\.credentials.json\u003C\u002Fcode>, protected like the rest of your profile.\u003C\u002Fp>\n\u003Cp>If you use an Anthropic API key, don&#39;t put it in the \u003Ccode>env\u003C\u002Fcode> block of a settings file. Export it from the Keychain as above, or use \u003Ccode>apiKeyHelper\u003C\u002Fcode>, a setting that points to a script printing the key, so Claude Code fetches it when it needs it. And check \u003Ccode>\u002Fstatus\u003C\u002Fcode>: a stray \u003Ccode>ANTHROPIC_API_KEY\u003C\u002Fcode> in your shell switches Claude Code from your plan to API billing (\u003Ca href=\"\u002Fblog\u002Fclaude-code-api-key-vs-subscription\">API key or subscription\u003C\u002Fa> explains why).\u003C\u002Fp>\n\u003Ch2 id=\"what-should-you-do-if-a-key-leaked\">\u003Ca class=\"anchor\" href=\"#what-should-you-do-if-a-key-leaked\" aria-label=\"Link to this section\">#\u003C\u002Fa>What should you do if a key leaked?\u003C\u002Fh2>\n\u003Col>\n\u003Cli>\u003Cstrong>Rotate it\u003C\u002Fstrong> at the provider, right away. Everything else is cleanup.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Find the copies.\u003C\u002Fstrong> \u003Ccode>grep -rl &#39;sk_live_&#39; ~\u002F.claude\u002Fprojects\u003C\u002Fcode> lists the transcripts that contain a Stripe live key; use your key&#39;s own prefix. Delete those files if you don&#39;t need the sessions.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Check git:\u003C\u002Fstrong> \u003Ccode>git log -p -S &#39;sk_live_&#39;\u003C\u002Fcode> finds the commits that added or removed it.\u003C\u002Fli>\n\u003Cli>\u003Cstrong>Shrink the next one.\u003C\u002Fstrong> Use restricted, read-only or test keys where the service offers them. A leaked key that can only read balances is a bad day, not a disaster.\u003C\u002Fli>\n\u003C\u002Fol>\n\u003Ch2 id=\"in-relais\">\u003Ca class=\"anchor\" href=\"#in-relais\" aria-label=\"Link to this section\">#\u003C\u002Fa>In Relais\u003C\u002Fh2>\n\u003Cp>In Relais, keys live in the Vault. Each one is kept in your Mac&#39;s Keychain, never in Relais&#39;s own config file nor in an export, and given as environment variables to the sessions of the agents you pick. Agents are told to use keys through their variables and never print them. When an agent needs a key it doesn&#39;t have, it asks with a card in its conversation: you type the value in a masked field, it goes to the Keychain, and the agent&#39;s next sessions have it without ever seeing it. The Keychain keeps keys out of files and exports; inside a session, the habits above still apply. Relais also removes \u003Ccode>ANTHROPIC_API_KEY\u003C\u002Fcode> from what it starts, so your Claude plan is never swapped for API billing. See \u003Ca href=\"\u002Ffeatures\u002Fvault\">the Vault\u003C\u002Fa> and \u003Ca href=\"\u002Fblog\u002Fshare-ai-agents-with-your-team\">sharing agents and data with your team\u003C\u002Fa>.\u003C\u002Fp>\n",[15,18,21,24,27,30,33,36],{"id":16,"text":17},"where-can-a-key-leak-in-a-claude-code-session","Where can a key leak in a Claude Code session?",{"id":19,"text":20},"how-should-you-give-claude-code-a-key","How should you give Claude Code a key?",{"id":22,"text":23},"how-do-you-stop-claude-code-from-reading-env","How do you stop Claude Code from reading .env?",{"id":25,"text":26},"should-env-be-in-gitignore","Should .env be in .gitignore?",{"id":28,"text":29},"how-do-you-keep-claude-from-printing-a-key","How do you keep Claude from printing a key?",{"id":31,"text":32},"where-does-claude-code-keep-its-own-credentials","Where does Claude Code keep its own credentials?",{"id":34,"text":35},"what-should-you-do-if-a-key-leaked","What should you do if a key leaked?",{"id":37,"text":38},"in-relais","In Relais",[40,47,52],{"slug":41,"title":42,"description":43,"category":7,"categoryId":8,"keyword":44,"date":45,"minutes":46},"claude-code-on-linux","Claude Code on Linux: install, sign in, and the interfaces you can use","How to install Claude Code on Ubuntu, Debian, Fedora or Alpine, sign in with your Claude plan on a desktop or over SSH, keep it updated, and which graphical interfaces run on Linux today.","claude code linux","2026-11-27",5,{"slug":48,"title":49,"description":50,"category":7,"categoryId":8,"keyword":51,"date":10,"minutes":11},"claude-code-resume-session","Claude Code resume session: pick up where you left off","How to resume a Claude Code session with --continue, --resume and \u002Fresume, where sessions are stored, what comes back, and what to do after a limit or a crash.","claude code resume session",{"slug":53,"title":54,"description":55,"category":7,"categoryId":8,"keyword":56,"date":57,"minutes":46},"claude-code-beginners-guide","Claude Code for beginners: install, first session, habits","Install Claude Code, run your first session and learn the habits that matter: specific prompts, plan before edit, CLAUDE.md, small commits, a clean context.","claude code for beginners","2026-11-17",1795902782124]