claude setup-token
claude setup-token: a one-year token for Claude Code
claude setup-token runs Claude's browser sign-in once and prints a 1-year OAuth token, so Claude Code can run in CI or on a server without a browser. Set it as CLAUDE_CODE_OAUTH_TOKEN. It works with 4 paid plans (Pro, Max, Team and Enterprise) and can only make model requests.
- Token lifetime
- 1 year
- Environment variable
- CLAUDE_
CODE_ OAUTH_ TOKEN - Plans
- Pro, Max, Team, Enterprise
- Saved anywhere
- No, printed to the terminal
Updated
What claude setup-token does
claude setup-token runs your subscription sign-in once in a browser and gives you a long-lived token you can move to headless machines, containers and CI runners that don't have a browser. Here's how the command works at a glance.
| Item | Detail |
|---|---|
| Command | claude setup-token |
| Sign-in | Same browser flow as / |
| Output | OAuth token printed to the terminal |
| Lifetime | One year |
| Saved to disk | No, store it yourself |
| Used as | CLAUDE_ |
| Plans | Pro, Max, Team or Enterprise |
| Can do | Model requests only |
| Usage | Counts against your plan's limits |
Use the token in CI or on a server
- On a machine that has a browser, run
claude setup-tokenin your terminal and approve the sign-in in the browser window that opens, just like/login. - Copy the token printed to the terminal and save it in your CI system's secret store or server environment right away, because Claude Code doesn't save this token anywhere on disk.
- Expose the secret to your job as the
CLAUDE_CODE_OAUTH_TOKENenvironment variable: runexport CLAUDE_CODE_OAUTH_TOKEN=your-tokenon macOS, Linux and WSL,$env:CLAUDE_CODE_OAUTH_TOKEN = "your-token"in PowerShell, orset CLAUDE_CODE_OAUTH_TOKEN=your-tokenin Windows CMD. - Run Claude Code non-interactively with
claude -p "query"(or pipe input in withcat file | claude -p "query"), which prints the response to stdout and exits. - Before the 1-year expiration is up, run
claude setup-tokenagain and replace the stored secret in your CI config, since each run generates a fresh one-year token.
claude --bare ignores CLAUDE_CODE_OAUTH_TOKEN, so bare-mode jobs need ANTHROPIC_API_KEY or an apiKeyHelper script instead.
# Once, on a computer with a browser
claude setup-token
# In the CI job, with the printed token stored as a secret
export CLAUDE_CODE_OAUTH_TOKEN="$CLAUDE_TOKEN_SECRET"
claude -p "Summarize the failing tests in this repository"
Use the token in GitHub Actions
- Open
claudeinside a local clone of your repository and run/install-github-app(this only works withgithub.comrepositories and requires the GitHub CLI signed in throughgh auth login). - When prompted for authentication, choose to create a long-lived token with your Claude subscription; Claude Code will install the Claude GitHub App, save the token as the
CLAUDE_CODE_OAUTH_TOKENrepository secret, push a branch with the workflow files, and open a pull request. - Merge that pull request into your repository.
- Mention
@claudein an issue or pull request comment to verify that the action responds.
If you'd rather set the workflow up by hand, install the Claude GitHub App on the repository, add the token from claude setup-token as the CLAUDE_CODE_OAUTH_TOKEN repository secret, and pass it to anthropics/claude-code-action@v1 using the claude_code_oauth_token input instead of anthropic_api_key, as the YAML example below shows.
For a secret shared across an organization's repositories, Anthropic recommends a Claude Console API key instead, because an OAuth token is tied to the subscription of the person who ran claude setup-token.
name: Claude Code
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
jobs:
claude:
if: contains(github.event.comment.body, '@claude')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
actions: read
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
What a setup-token can't do
- It can only make model requests, so Remote Control sessions and
claude.aiconnectors don't work with it, though local MCP servers still do. - Bare mode (
claude --bare) doesn't readCLAUDE_CODE_OAUTH_TOKENat all. - Running
/loginwhile the variable is set switches only that active session, and Claude Code goes right back to readingCLAUDE_CODE_OAUTH_TOKENthe next time a session starts. - It signs in with your own Claude subscription, so it requires a Pro, Max, Team or Enterprise plan and won't work on the Free plan.
Why Claude Code ignores your token
When more than one credential is present, Claude Code checks them in this order and uses the first one it finds:
- Cloud provider credentials (Amazon Bedrock, Google Cloud, Microsoft Foundry)
ANTHROPIC_AUTH_TOKENANTHROPIC_API_KEYapiKeyHelperCLAUDE_CODE_OAUTH_TOKEN- An Anthropic profile
- The subscription login from
/login
In non-interactive mode (claude -p), Claude Code always uses ANTHROPIC_API_KEY without asking whenever it's set, so a leftover Claude API key in your CI environment beats the setup-token and bills API rates instead of using your plan; unset ANTHROPIC_API_KEY in the job.
Limits, billing and other sign-ins
Every request the token makes counts against your subscription's Claude usage limits: the session limit that resets every five hours and the weekly limit. Both limits are shared across claude.ai, Claude Desktop and interactive Claude Code, so a busy CI pipeline will eat into the same allowance you use at your desk.
If you're on a Max plan, its monthly API credits ($100 on Max 5x, $200 on Max 20x) don't pay for claude -p when you're signed in with your subscription; those credits only cover claude -p when Claude Code runs with an API key from the Claude Console organization you linked. Organizations that want API-based billing can sign Claude Code in with a Claude Console account instead of a subscription.
Among all the ways to authenticate Claude Code, only the subscription sign-ins draw from your plan's usage limits:
| Sign-in | How it works | Usage comes from |
|---|---|---|
/ on Pro or Max | Browser sign-in with your claude.ai account | Your plan's usage limits |
/ on Team or Enterprise | The claude.ai account your admin invited | Your Team or Enterprise plan |
claude setup-token | One-year token in CLAUDE_ | Your plan's usage limits |
| Claude Console | Console login or ANTHROPIC_ | API rates |
| Cloud providers | Bedrock, Google Cloud or Foundry settings | Your cloud provider account |
Call Claude from your own code with your plan
A setup-token only signs in Claude Code. If you want to put your Claude Pro or Max plan behind an OpenAI-compatible API for your own scripts, apps and other tools, Plan2API turns your Claude subscription into an API by connecting your account at plan2api.com/connect through Claude's own sign-in page and giving you a p2a_ key for https://api.plan2api.com/v1, where requests run on the same plan limits.
Plan2API encrypts your connected login with HPKE (X25519) and AES-256-GCM so only your API key can unlock it, and it never stores your prompts or outputs (see the security details).
| Feature | claude setup-token | Plan2API key |
|---|---|---|
| Works with | Claude Code | Any OpenAI-compatible client |
| Providers | Claude | Claude, ChatGPT, Gemini, Kimi |
| Claude plans | Pro, Max, Team, Enterprise | Pro or Max |
| Limits used | Your plan's limits | Your plan's limits |
| Price | Included in your Claude plan | Free, or $12 or $29 a month |
Use the AI subscriptions you already pay for as one OpenAI-compatible API key.
- Free: 1 subscription, 50 requests a day, no card
- Pro: $12 a month
FAQ
How long does a claude setup-token last?
One year from when you generate it. Each time you run claude setup-token it creates a new one-year token, so run it again and update your stored secret before the year is up.
Where does claude setup-token save the token?
Nowhere. After you approve the browser sign-in, claude setup-token prints the token to the terminal and exits, so you need to copy it and store it yourself, for example in your CI secret store.
Can I use claude setup-token in GitHub Actions?
Yes. Save the token as the CLAUDE_CODE_OAUTH_TOKEN repository secret and pass it to anthropics/claude-code-action@v1 with the claude_code_oauth_token input, or run /install-github-app inside Claude Code to set it up automatically. Your account needs a Claude Pro, Max, Team or Enterprise plan.
Why is CLAUDE_CODE_OAUTH_TOKEN being ignored?
Either the job is running with claude --bare, which doesn't read CLAUDE_CODE_OAUTH_TOKEN, or a higher-priority credential like ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, apiKeyHelper or cloud provider variables is set in the same environment.
Does a setup-token use my Claude usage limits?
Yes. Because the token signs in with your Claude subscription, everything it runs counts against the same 5-hour session limit and weekly limit shared with claude.ai, Claude Desktop and interactive Claude Code.
Can I use my Claude subscription from other tools?
Yes, through Plan2API. You connect your Claude Pro or Max account and get a p2a_ API key that works with any OpenAI-compatible client against https://api.plan2api.com/v1, drawing from your plan's normal usage limits.
Sources
- Claude Code authentication (Anthropic docs)code.claude.com
- Claude Code CLI referencecode.claude.com
- Using Claude Code with your Pro or Max plansupport.claude.com
- Monthly API credits for Max and Team planssupport.claude.com
- Claude Code GitHub Actionscode.claude.com