Issue 00 · Autumn 2026日本語 · RSS
AgentKoji

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.

TL;DR

  • 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

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_TOKENANTHROPIC_API_KEY
Created withclaude setup-tokenClaude Console
BillingYour Claude subscription’s usage limitsConsole API billing
Place in the precedence5th3rd
Where it isn’t read--bare runsNowhere listed (--bare uses it)

The official authentication precedence, highest first:

  1. Cloud provider credentials (CLAUDE_CODE_USE_BEDROCK and similar)
  2. ANTHROPIC_AUTH_TOKEN
  3. ANTHROPIC_API_KEY
  4. apiKeyHelper output
  5. CLAUDE_CODE_OAUTH_TOKEN
  6. Anthropic profile and federation credentials
  7. 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:

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:

Our own advice (not from the docs):

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:

  1. 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
  2. Create a new token with claude setup-token and replace the secret
  3. 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:

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:

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

Summary

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.