Allow passing CLAUDE_REFRESH_TOKEN and CLAUDE_ACCESS_TOKEN via env variables to use Claude Max subscription in the GitHub action #809

Closed
opened 2026-02-16 17:28:24 -05:00 by yindo · 4 comments
Owner

Originally created by @remorses on GitHub (Jul 19, 2025).

Currently there is no way to use Claude Max subscription with opencode programatically

This is how the official Anthropic actions solves this:

jobs:
  claude:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Run Claude PR Action
        uses: grll/claude-code-action@beta
        with:
          use_oauth: true
          claude_access_token: ${{ secrets.CLAUDE_ACCESS_TOKEN }}
          claude_refresh_token: ${{ secrets.CLAUDE_REFRESH_TOKEN }}
          claude_expires_at: ${{ secrets.CLAUDE_EXPIRES_AT }}
          allowed_tools: "Bash(git:*),View,GlobTool,GrepTool,BatchTool"

Using CLAUDE_REFRESH_TOKEN and CLAUDE_ACCESS_TOKEN from the environment should be enough.

You could then use the action claude-code-login to automatically refresh the tokens

Originally created by @remorses on GitHub (Jul 19, 2025). Currently there is no way to use Claude Max subscription with opencode programatically This is how the official Anthropic actions solves this: ```yml jobs: claude: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Run Claude PR Action uses: grll/claude-code-action@beta with: use_oauth: true claude_access_token: ${{ secrets.CLAUDE_ACCESS_TOKEN }} claude_refresh_token: ${{ secrets.CLAUDE_REFRESH_TOKEN }} claude_expires_at: ${{ secrets.CLAUDE_EXPIRES_AT }} allowed_tools: "Bash(git:*),View,GlobTool,GrepTool,BatchTool" ``` Using `CLAUDE_REFRESH_TOKEN` and `CLAUDE_ACCESS_TOKEN` from the environment should be enough. You could then use the action [claude-code-login](https://github.com/grll/claude-code-login) to automatically refresh the tokens
yindo closed this issue 2026-02-16 17:28:24 -05:00
Author
Owner

@thdxr commented on GitHub (Jul 19, 2025):

check ~/.local/share/opencode/auth.json - you could write that file and it would work

@thdxr commented on GitHub (Jul 19, 2025): check `~/.local/share/opencode/auth.json` - you could write that file and it would work
Author
Owner

@remorses commented on GitHub (Jul 19, 2025):

This should do the trick:

name: opencode

on:
  issue_comment:
    types: [created]

jobs:
  opencode:
    if: startsWith(github.event.comment.body, 'hey opencode')
    runs-on: ubuntu-latest
    permissions:
      id-token: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 1

      - name: Write auth.json
        run: |
          printf '{"anthropic":{"type":"oauth","refresh":"%s","access":"%s"}}' \
            "${{ secrets.ANTHROPIC_REFRESH_TOKEN }}" \
            "${{ secrets.ANTHROPIC_ACCESS_TOKEN }}" \
            | install -D /dev/stdin ~/.local/share/opencode/auth.json

      - name: Run opencode
        uses: sst/opencode/sdks/github@github-v1
        with:
          model: anthropic/claude-sonnet-4-20250514

@remorses commented on GitHub (Jul 19, 2025): This should do the trick: ```yml name: opencode on: issue_comment: types: [created] jobs: opencode: if: startsWith(github.event.comment.body, 'hey opencode') runs-on: ubuntu-latest permissions: id-token: write steps: - name: Checkout repository uses: actions/checkout@v4 with: fetch-depth: 1 - name: Write auth.json run: | printf '{"anthropic":{"type":"oauth","refresh":"%s","access":"%s"}}' \ "${{ secrets.ANTHROPIC_REFRESH_TOKEN }}" \ "${{ secrets.ANTHROPIC_ACCESS_TOKEN }}" \ | install -D /dev/stdin ~/.local/share/opencode/auth.json - name: Run opencode uses: sst/opencode/sdks/github@github-v1 with: model: anthropic/claude-sonnet-4-20250514 ```
Author
Owner

@dbpolito commented on GitHub (Jul 28, 2025):

Wouldn't be good to add support for this somehow or at least add this to the documentation? Not sure what's the percentage of people using API vs Pro / Max plan, but i'm definitely going to try using this way.

Thanks for sharing 🫶

@dbpolito commented on GitHub (Jul 28, 2025): Wouldn't be good to add support for this somehow or at least add this to the documentation? Not sure what's the percentage of people using API vs Pro / Max plan, but i'm definitely going to try using this way. Thanks for sharing 🫶
Author
Owner

@thehaseebahmed commented on GitHub (Nov 21, 2025):

@dbpolito @remorses are you guys using this approach? For some reason it works for a while but when the access token fails, it struggles to refresh the token.

@thehaseebahmed commented on GitHub (Nov 21, 2025): @dbpolito @remorses are you guys using this approach? For some reason it works for a while but when the access token fails, it struggles to refresh the token.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#809