Answer: On macOS/Linux, add the export line to your shell config file (e.g., ~/.zshrc for zsh or ~/.bash_profile for bash) and then source that file to apply the changes. On Windows, open System Properties → Advanced → Environment Variables, add a new User variable named ANTHROPIC_API_KEY with your key as the value, click OK, and restart your terminal. Status: Confirmed Entry: tool/claude-apps/settings/set-api-key-env-var-permanently Revision: 2 Digest: sha256:a87cb3bda8bc9316 (changes whenever the content changes) Timeline: Created: 2026-11-13T02:57:56Z Last changed: 2026-11-19T11:58:22Z (bash config file: — → ~/.bash_profile) Last verified: 2026-11-20T12:01:46Z Next check: 2026-11-21T12:01:46Z Check interval: Daily Expected change: No fixed schedule Data: Field | Value | Source | As of zsh config file | ~/.zshrc | [1] | 2026-11-20 bash config file | ~/.bash_profile | [1] | 2026-11-20 Windows variable name | ANTHROPIC_API_KEY | [1] | 2026-11-20 Windows variable value | your-api-key-here | [1] | 2026-11-20 Sources: [1] Anthropic. "Manage API key environment variables in Claude Code | Claude Help Center". https://support.claude.com/en/articles/12304248-manage-api-key-environment-variables-in-claude-code Role: primary. Accessed: 2026-11-20T12:01:46Z Quote: "echo 'export ANTHROPIC_API_KEY="your-api-key-here"' >> ~/.zshrc" (Supports: zsh config file) Quote: "echo 'export ANTHROPIC_API_KEY="your-api-key-here"' >> ~/.bash_profile" (Supports: bash config file) Quote: "Variable name: ANTHROPIC_API_KEY" (Supports: Windows variable name) Quote: "Variable value: your-api-key-here" (Supports: Windows variable value) Snapshot SHA-256: af3fbf2948ddfa530414b7ea72d19ea408260f08497b5ad746f0aaaaffafce8a (captured 2026-11-18T11:58:18Z) Verification: Method: Automated extraction from [1] with deepseek-flash (JSON output, thinking disabled). Every value was checked by code to appear verbatim in a quoted passage of [1]. On this check the text of [1] was unchanged since 2026-11-18T11:58:18Z, so the values verified then were kept. Cross-check: not-available at 2026-11-20T12:01:46Z. No independent second source is configured for this entry Last successful check: 2026-11-20T12:01:46Z Last attempt: 2026-11-20T12:01:46Z Notes and limitations: Extracted automatically from a single official source (section "Set an API key environment variable permanently"). Related: https://latestn.com/tool/claude-apps/settings/set-break-reminder How do I set a break reminder in Claude? https://latestn.com/tool/claude-apps/settings/set-default-effort-level How do I set the default effort level for new conversations in Claude? https://latestn.com/tool/claude-apps/settings/set-default-model-env-var How do I set a default Claude model for all future Claude Code sessions using environment variables? https://latestn.com/tool/claude-apps/settings/open-monthly-recap How do I open my monthly recap in Claude? https://latestn.com/tool/claude-apps/settings/rate-chats-setting-location Where is the Rate chats setting located in Claude organization settings? https://latestn.com/tool/claude-apps/settings/remove-api-key-env-var How do I remove an API key environment variable in Claude Code? https://latestn.com/tool/ All entries in AI tools Change log: Time | Event | Change | Source 2026-11-19T11:58:22Z | changed | bash config file: — → ~/.bash_profile | [1] 2026-11-19T11:58:22Z | changed | zsh config file: — → ~/.zshrc | [1] 2026-11-19T11:58:22Z | changed | bash apply command: source ~/.bash_profile → — | [1] 2026-11-19T11:58:22Z | changed | bash config command: echo 'export ANTHROPIC_API_KEY="your-api-key-here"' >> ~/.bash_profile → — | [1] 2026-11-19T11:58:22Z | changed | zsh apply command: source ~/.zshrc → — | [1] 2026-11-19T11:58:22Z | changed | zsh config command: echo 'export ANTHROPIC_API_KEY="your-api-key-here"' >> ~/.zshrc → — | [1] 2026-11-13T02:57:56Z | added | Entry created | — Changes for this entry as a feed: https://latestn.com/tool/claude-apps/settings/set-api-key-env-var-permanently/latest Challenge this entry: Open challenges: None How: If a value here is wrong or out of date, send what is wrong and a link to evidence. Challenges are queued and checked against the evidence; they do not change the entry by themselves. If the entry changes as a result, the change log says so. Form: https://latestn.com/dispute/tool/claude-apps/settings/set-api-key-env-var-permanently POST: https://latestn.com/dispute/tool/claude-apps/settings/set-api-key-env-var-permanently with claim, evidence_url, and optionally field and contact (form-encoded or JSON) GET: https://latestn.com/dispute/tool/claude-apps/settings/set-api-key-env-var-permanently?claim={what is wrong}&evidence_url={link} How to cite: LatestN. (2026). How do I set an ANTHROPIC_API_KEY environment variable permanently for Claude Code? Revision 2, last verified 2026-11-20T12:01:46Z. https://latestn.com/tool/claude-apps/settings/set-api-key-env-var-permanently (accessed 2026-11-21T10:03:25Z). @misc{LatestN_tool_claude_apps_settings_set_api_key_env_var_permanently_r2, title = {How do I set an ANTHROPIC_API_KEY environment variable permanently for Claude Code?}, author = {{LatestN}}, year = {2026}, howpublished = {\url{https://latestn.com/tool/claude-apps/settings/set-api-key-env-var-permanently}}, note = {Revision 2; digest sha256:a87cb3bda8bc9316; last verified 2026-11-20T12:01:46Z; accessed 2026-11-21T10:03:25Z} } Reuse: License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) Attribution: Copying and adapting are allowed, including commercially, if you credit LatestN and link to the entry you used. Each entry ends with a ready-made citation. URL: https://latestn.com/tool/claude-apps/settings/set-api-key-env-var-permanently