How can I authenticate the opencode GitHub Action with Anthropic using Oauth? #2292

Open
opened 2026-02-16 17:35:00 -05:00 by yindo · 7 comments
Owner

Originally created by @ianwalter on GitHub (Oct 26, 2025).

Originally assigned to: @rekram1-node on GitHub.

Question

Claude Code uses CLAUDE_CODE_OAUTH_TOKEN, but opencode seems to only support ANTHROPIC_API_KEY. How can I use Oauth so that I can use my Anthropic Max plan like I can with the local opencode TUI?

Originally created by @ianwalter on GitHub (Oct 26, 2025). Originally assigned to: @rekram1-node on GitHub. ### Question Claude Code uses `CLAUDE_CODE_OAUTH_TOKEN`, but opencode seems to only support `ANTHROPIC_API_KEY`. How can I use Oauth so that I can use my Anthropic Max plan like I can with the local opencode TUI?
Author
Owner

@github-actions[bot] commented on GitHub (Oct 26, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #1341: How to setup opencode github action with copilot provider? - discusses similar GitHub Action authentication challenges and mentions trying various token approaches
  • #276: Architecture: Hardcoded authentication logic in AnthropicProvider bypasses BaseProvider - addresses OAuth token handling (sk-ant-oat prefix checking) and authentication inconsistencies in the Anthropic provider

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Oct 26, 2025): This issue might be a duplicate of existing issues. Please check: - #1341: How to setup opencode github action with copilot provider? - discusses similar GitHub Action authentication challenges and mentions trying various token approaches - #276: Architecture: Hardcoded authentication logic in AnthropicProvider bypasses BaseProvider - addresses OAuth token handling (sk-ant-oat prefix checking) and authentication inconsistencies in the Anthropic provider Feel free to ignore if none of these address your specific case.
Author
Owner

@rekram1-node commented on GitHub (Oct 26, 2025):

@ianwalter we dont provide an env var for that right now but perhaps we should. I think the way to do it currently is to create an auth.json file in the github action.

If you are authed to anthropic on your machine the file should be ~/.local/share/opencode/auth.json

Then you can read the "anthropic" one

So I think you could create that in your github action and it should work for opencode

@rekram1-node commented on GitHub (Oct 26, 2025): @ianwalter we dont provide an env var for that right now but perhaps we should. I think the way to do it currently is to create an auth.json file in the github action. If you are authed to anthropic on your machine the file should be ~/.local/share/opencode/auth.json Then you can read the "anthropic" one So I think you could create that in your github action and it should work for opencode
Author
Owner

@AdiKsOnDev commented on GitHub (Nov 20, 2025):

@rekram1-node Is this now implemented? This would be a very cool addition (at least personally), it'll instantly replace the need for the newly created (and expensive xD) Web Claude Code.

UPD: Just to clarify I mean this allows configuring Opencode Actions to work with Claude MAX (and other) subscriptions

@AdiKsOnDev commented on GitHub (Nov 20, 2025): @rekram1-node Is this now implemented? This would be a very cool addition (at least personally), it'll instantly replace the need for the newly created (and expensive xD) Web Claude Code. UPD: Just to clarify I mean this allows configuring Opencode Actions to work with Claude MAX (and other) subscriptions
Author
Owner

@rekram1-node commented on GitHub (Nov 20, 2025):

we dont have it implemented rn no

@rekram1-node commented on GitHub (Nov 20, 2025): we dont have it implemented rn no
Author
Owner

@dbpolito commented on GitHub (Nov 27, 2025):

So the thing with oauth is that we need to keep refreshing as it expires, so what i'm doing:

  1. I create a secret with a ~/.local/share/opencode/auth.json with a valid oauth config
  2. Have a job running daily loading from secret if not on cache already (for the first time), hit the api to refresh oauth and save cache
  3. The opencode job itself just loads the file from cache

Create a secret with your auth file:

gh secret set OPENCODE_AUTH < ~/.local/share/opencode/auth.json
name: opencode

on:
  issue_comment:
    types: [created]
  pull_request_review_comment:
    types: [created]

jobs:
  opencode:
    if: |
      contains(github.event.comment.body, ' /oc') ||
      startsWith(github.event.comment.body, '/oc') ||
      contains(github.event.comment.body, ' /opencode') ||
      startsWith(github.event.comment.body, '/opencode')
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read
      pull-requests: read
      issues: read
    steps:
      - uses: actions/checkout@v4
      - uses: actions/cache/restore@v4
        with:
          path: ~/.local/share/opencode/auth.json
          key: opencode-auth
      - uses: sst/opencode/github@latest
        with:
          model: anthropic/claude-sonnet-4-5
name: opencode-auth

on:
  schedule:
    - cron: '0 3 * * *'
  workflow_dispatch:

jobs:
  refresh:
    runs-on: ubuntu-latest
    steps:
      - id: cache
        uses: actions/cache@v4
        with:
          path: ~/.local/share/opencode/auth.json
          key: opencode-auth
      - if: steps.cache.outputs.cache-hit != 'true'
        run: |
          mkdir -p ~/.local/share/opencode
          echo '${{ secrets.OPENCODE_AUTH }}' > ~/.local/share/opencode/auth.json
      - run: curl -fsSL https://opencode.ai/install | bash
      - run: opencode models

@rekram1-node i'm adding some other PRs trying to improve this github integration, we could definitely add support fro this on opencode github install to ask if you want to do that, and setup like this.

@dbpolito commented on GitHub (Nov 27, 2025): So the thing with oauth is that we need to keep refreshing as it expires, so what i'm doing: 1. I create a secret with a `~/.local/share/opencode/auth.json` with a valid oauth config 2. Have a job running daily loading from secret if not on cache already (for the first time), hit the api to refresh oauth and save cache 3. The opencode job itself just loads the file from cache Create a secret with your auth file: ``` gh secret set OPENCODE_AUTH < ~/.local/share/opencode/auth.json ``` ```yaml name: opencode on: issue_comment: types: [created] pull_request_review_comment: types: [created] jobs: opencode: if: | contains(github.event.comment.body, ' /oc') || startsWith(github.event.comment.body, '/oc') || contains(github.event.comment.body, ' /opencode') || startsWith(github.event.comment.body, '/opencode') runs-on: ubuntu-latest permissions: id-token: write contents: read pull-requests: read issues: read steps: - uses: actions/checkout@v4 - uses: actions/cache/restore@v4 with: path: ~/.local/share/opencode/auth.json key: opencode-auth - uses: sst/opencode/github@latest with: model: anthropic/claude-sonnet-4-5 ``` ```yaml name: opencode-auth on: schedule: - cron: '0 3 * * *' workflow_dispatch: jobs: refresh: runs-on: ubuntu-latest steps: - id: cache uses: actions/cache@v4 with: path: ~/.local/share/opencode/auth.json key: opencode-auth - if: steps.cache.outputs.cache-hit != 'true' run: | mkdir -p ~/.local/share/opencode echo '${{ secrets.OPENCODE_AUTH }}' > ~/.local/share/opencode/auth.json - run: curl -fsSL https://opencode.ai/install | bash - run: opencode models ``` @rekram1-node i'm adding some other PRs trying to improve this github integration, we could definitely add support fro this on `opencode github install` to ask if you want to do that, and setup like this.
Author
Owner

@m9tdev commented on GitHub (Jan 8, 2026):

Thanks @dbpolito! I just had to change opencode models to opencode --model anthropic/claude-sonnet-4-5 "say hi" to actually refresh the tokens.

@m9tdev commented on GitHub (Jan 8, 2026): Thanks @dbpolito! I just had to change `opencode models` to `opencode --model anthropic/claude-sonnet-4-5 "say hi"` to actually refresh the tokens.
Author
Owner

@dbpolito commented on GitHub (Jan 8, 2026):

yeah, i ended up changing it to...

@dbpolito commented on GitHub (Jan 8, 2026): yeah, i ended up changing it to...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#2292