CLAUDE_CODE_OAUTH_TOKEN: Setup, CI Use and Leak Response
CLAUDE_CODE_OAUTH_TOKEN is the one-year token that claude setup-token prints. How it differs from ANTHROPIC_API_KEY, how to use it in CI, and how to revoke it after a leak.
- CLAUDE_CODE_OAUTH_TOKEN holds the one-year OAuth token that claude setup-token prints. It authenticates against your Claude subscription (Pro, Max, Ultra, Team or Enterprise), and per the docs it is shown in the terminal and not saved anywhere.
- If ANTHROPIC_API_KEY is also set, the key ranks higher in the authentication precedence, and in non-interactive -p mode a present key is always used. Billing then follows the API, so remove the key from any job you want on your subscription.
- After a leak, signing out of all sessions under Settings > Account on claude.ai invalidates the token, setup-token tokens included. Deleting the CI secret does not: the credential it held stays valid.
CLAUDE_CODE_OAUTH_TOKEN is the environment variable that carries the OAuth token claude setup-token creates. The docs describe a one-year token tied to your Claude subscription, meant for places where you can’t log in through a browser, such as CI and scripts. It is not an API key: if ANTHROPIC_API_KEY is also set, the key wins. This guide covers what the token is, how it differs from an API key, how to use it in CI and on servers, how to keep it from leaking, how to revoke it when it does, and what the terms say, all limited to what the official pages state.
Facts come from the official docs and help center, checked 2026-11-24. In our test environment we did not run claude setup-token or issue a token. The code examples follow the official docs and we did not run them (unverified).
What claude setup-token creates
According to the official authentication page, claude setup-token creates a one-year OAuth token for CI pipelines and scripts.
claude setup-token
- The browser authorization is the same flow as
/login, and the token prints to the terminal after you approve access - The token is not saved anywhere. Copy it and set it as
CLAUDE_CODE_OAUTH_TOKENin the environment you want to authenticate - It authenticates against your Claude subscription and requires a Pro, Max, Ultra, Team or Enterprise plan
- It can only make model requests. It can’t establish Remote Control sessions or fetch claude.ai connectors. MCP servers you configure locally still work
- A run with
--baredoesn’t read this token. In that case authenticate withANTHROPIC_API_KEYor anapiKeyHelper
Sources: https://code.claude.com/docs/en/authentication and https://code.claude.com/docs/en/cli-reference (checked 2026-11-24)
The environment variable reference adds that CLAUDE_CODE_OAUTH_TOKEN is ignored in project and local settings. Putting it in the env block of a repository’s .claude/settings.json has no effect. It belongs in the shell environment or the job environment.
Sources: https://code.claude.com/docs/en/env-vars and https://code.claude.com/docs/en/settings-reference (checked 2026-11-24)
How it differs from ANTHROPIC_API_KEY
CLAUDE_CODE_OAUTH_TOKEN | ANTHROPIC_API_KEY | |
|---|---|---|
| Created with | claude setup-token | Claude Console |
| Billing | Your Claude subscription’s usage limits | Console API billing |
| Place in the precedence | 5th | 3rd |
| Where it isn’t read | --bare runs | Nowhere listed (--bare uses it) |
The official authentication precedence, highest first:
- Cloud provider credentials (
CLAUDE_CODE_USE_BEDROCKand similar) ANTHROPIC_AUTH_TOKENANTHROPIC_API_KEYapiKeyHelperoutputCLAUDE_CODE_OAUTH_TOKEN- Anthropic profile and federation credentials
- Subscription OAuth credentials from
/login
In non-interactive mode (-p) the key is always used when present. The help center warns that if ANTHROPIC_API_KEY is set, Claude Code authenticates with it instead of your subscription, which results in API usage charges. For a job you want on your subscription, remove ANTHROPIC_API_KEY from its environment. /status shows which credential is active, and in the JSON from claude auth status the authMethod field reports values such as oauth_token or api_key.
On billing, the GitHub Actions page says that if you authenticate with an OAuth token, runs use your Claude subscription instead of API billing. Subscription limits are shared between Claude and Claude Code, and per the help center a claude -p run signed in with a plan draws from the plan’s usage limits too.
Sources: https://code.claude.com/docs/en/authentication, https://code.claude.com/docs/en/github-actions, https://support.claude.com/en/articles/11145838-use-claude-code-with-your-pro-or-max-plan and https://support.claude.com/en/articles/17154008-monthly-api-credits-for-max-ultra-and-team-plans (checked 2026-11-24)
Using it in CI, scripts and servers
GitHub Actions
The official steps: run claude setup-token locally, store the output as a repository secret named CLAUDE_CODE_OAUTH_TOKEN, and pass it to the claude_code_oauth_token input. The sample claude.yml is written with the anthropic_api_key line, so you swap that line:
- uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
/install-github-app lets you choose between an API key and a subscription token and saves the secret for you. For a secret shared across an organization’s repositories, the docs recommend a Console API key rather than an OAuth token, because the token is tied to the subscription of the person who ran claude setup-token. The page also describes workload identity federation, which avoids storing a long-lived secret at all.
Source: https://code.claude.com/docs/en/github-actions (checked 2026-11-24)
GitLab CI
The official GitLab CI/CD page documents one authentication path: ANTHROPIC_API_KEY as a masked CI/CD variable. It doesn’t describe using CLAUDE_CODE_OAUTH_TOKEN on GitLab (unconfirmed). The variable is generic, so setting it may work, but we haven’t tried it and the docs don’t say, so we don’t claim it.
Source: https://code.claude.com/docs/en/gitlab-ci-cd (checked 2026-11-24)
claude -p, VPS and containers
For scripts and cron, pass the variable in the job’s environment and call claude -p without --bare:
# The token is injected by the runner or secret manager; don't write it in the script
claude -p "Summarize the failing tests in this log"
The docs have no dedicated guidance for VPS or container placement. What follows is our own suggestion, not an official procedure:
- Don’t put it in a Dockerfile
ENVorARG, since image layers keep it. Pass it at run time by name, as indocker run -e CLAUDE_CODE_OAUTH_TOKEN - Don’t spread one token across many servers. Keep a separate secret per server and note where each one lives
- Avoid typing
export CLAUDE_CODE_OAUTH_TOKEN=...into a shell that records history; load it from a secret manager
For server setup in general, see Run Claude Code on a VPS: SSH, tmux and Headless Login.
Keeping it from leaking
Whoever holds this token can call models against your subscription. The exposure is your usage limits plus whatever the token can do. Per the docs, that is limited to model requests, with no Remote Control and no claude.ai connectors.
What the docs say:
- Never commit API keys or OAuth tokens to the repository. Store them as GitHub Secrets and reference them from the workflow
- On public repositories, GitHub withholds secrets from runs triggered by fork pull requests
- For a shared setup, use an API key or workload identity federation, not the token
Our own advice (not from the docs):
- Run
claude setup-tokenon a machine with no screen sharing or recording. The token is only printed, so it sits in terminal scrollback - Don’t paste it into chat, gists, paste sites, issues or an AI assistant. When asking for help with an error, blank out environment values first
- Keep environment variables out of logs. Debug output from
set -xorenvis visible to everyone who can read the job log - A job that lets the agent run Bash can read its environment. The official secure-deployment guide suggests keeping credentials outside the agent’s environment and injecting them through a proxy
Sources: https://code.claude.com/docs/en/github-actions and https://code.claude.com/docs/en/agent-sdk/secure-deployment (checked 2026-11-24)
Revoking and reissuing after a leak
The revocation path we could confirm:
- On claude.ai, open Settings > Account and click Log Out. The support article says this signs you out across all devices, and the list it gives includes Claude Code “including tokens created with setup-token for continuous integration (CI)”. It also signs out web, mobile, desktop, and integrations such as Claude in Chrome and Slack. It doesn’t affect API keys
- Create a new token with
claude setup-tokenand replace the secret - A session using a long-lived token shows “OAuth token revoked” or “OAuth token has expired” once the token is revoked or expires. The official fix is to generate a new token and restart. Per the environment variable reference, unless you run
/login, Claude Code uses the token you set for the whole session, so a new token only takes effect after a restart
Caveats:
- Deleting the GitHub secret leaves the token valid. The Uninstall section says that if you delete a secret, the credential it held stays valid
- The support article also describes removing a Claude Code authorization token under Settings > Claude Code with the trash can icon. Whether a
setup-tokentoken shows up there as its own entry is unconfirmed - Whether running
claude setup-tokenagain invalidates the previous token is not stated (unconfirmed). After replacing a token, consider the Log Out above so no old token stays alive - If you used an API key instead, deleting the key in the Console is the revocation. Logging out on claude.ai doesn’t touch it
Sources: https://support.claude.com/en/articles/10310342-how-do-i-log-out-of-all-active-sessions, https://code.claude.com/docs/en/errors, https://code.claude.com/docs/en/env-vars and https://code.claude.com/docs/en/github-actions (checked 2026-11-24)
What the terms say
What we could confirm:
- The Consumer Terms (Anthropic’s terms for individual users) say you may not share your account login information, Anthropic API key or account credentials with anyone else, or make your account available to anyone else. They also bar accessing the services through automated or non-human means, such as a bot or script, except via an Anthropic API key or where Anthropic explicitly permits it. We read the docs’ own
setup-tokenguidance for CI and scripts as that explicit permission, but the terms don’t spell this out - The Claude Code legal page says OAuth authentication is intended for purchasers of subscription plans and ordinary use. Developers building products or services should use API keys from the Console or a supported cloud provider. Anthropic doesn’t permit routing requests through Free, Pro, Max or Ultra plan credentials on behalf of users, and developers may not collect, store or intermediate Claude.ai credentials or session tokens
- Advertised usage limits for Pro, Max and Ultra assume ordinary, individual usage
Putting your own subscription token in your own jobs is the use the docs describe. Handing it to other people, or building it into a product or service that runs on behalf of users, falls outside what these pages allow. We haven’t read the terms for Team and Enterprise, so how they treat this is unconfirmed. If your case is unclear, use the contact route the legal page gives.
Sources: https://www.anthropic.com/legal/consumer-terms (the page showed Effective Oct 8, 2025) and https://code.claude.com/docs/en/legal-and-compliance (checked 2026-11-24)
What we couldn’t confirm
- An official procedure for using
CLAUDE_CODE_OAUTH_TOKENin GitLab CI - A way to revoke a single
setup-tokentoken (whether it appears under Settings > Claude Code, or whether a CLI command exists) - Whether re-running
claude setup-tokeninvalidates the previous token - Which input wins when the GitHub Action receives both
claude_code_oauth_tokenandanthropic_api_key - How the Team and Enterprise terms treat sharing or automation
Summary
CLAUDE_CODE_OAUTH_TOKENis the one-year tokenclaude setup-tokenprints. It isn’t saved anywhere and authenticates against your Claude subscription- If
ANTHROPIC_API_KEYis set, it ranks higher. To run on your subscription, remove the key - In GitHub Actions, pass it to the
claude_code_oauth_tokeninput. The GitLab CI docs cover only the API key; the token there is unconfirmed - Don’t commit it, don’t paste it into paste sites or logs, and use an API key for anything shared across an organization
- Revoke with Log Out under Settings > Account on claude.ai. Deleting the secret leaves the token valid
- Sharing it with others or building it into a product falls outside what the docs allow
Related articles
- Claude Code in CI, Headless and Production
- Claude Code GitHub Actions: Setup, @claude and Security
- Claude Code GitLab CI/CD: Setup, Bedrock and Vertex (Beta)
- Claude Code Headless Mode: claude -p for Scripts and Cron
- Run Claude Code on a VPS: SSH, tmux and Headless Login
FAQ
- Where does claude setup-token store the token?
- Nowhere. After you approve access in the browser, the token is printed to the terminal. You copy it and set it as CLAUDE_CODE_OAUTH_TOKEN wherever you want to authenticate. The docs describe it as a one-year token.
- Which wins if both CLAUDE_CODE_OAUTH_TOKEN and ANTHROPIC_API_KEY are set?
- In the official authentication precedence, ANTHROPIC_API_KEY ranks above CLAUDE_CODE_OAUTH_TOKEN. In non-interactive mode (-p) a present key is always used. Setting the token while a key is present can therefore still mean API billing.
- How do I revoke a leaked setup-token token?
- The support article says that signing out of all sessions under Settings > Account on claude.ai also signs out Claude Code, including tokens created with setup-token for CI. Revoking one token on its own is unconfirmed in the official docs. Deleting the GitHub secret alone leaves the token valid.
- Can I use CLAUDE_CODE_OAUTH_TOKEN in GitLab CI?
- The official GitLab CI/CD page documents only ANTHROPIC_API_KEY as a masked variable and doesn't mention this token (unconfirmed). The GitHub Actions page documents a claude_code_oauth_token input.
- Can I share my subscription token with teammates?
- The Consumer Terms say you may not share your account login information or credentials with anyone else. For a secret shared across repositories, the GitHub Actions docs recommend a Claude Console API key instead of an OAuth token.