Skip to content

Conversation

@brettheap
Copy link

Summary

Implements built-in OAuth authentication for ChatGPT Plus/Pro subscribers to use OpenAI models via their existing subscription.

Features

  • PKCE OAuth flow with OpenAI's auth endpoints
  • Local callback server on port 1455
  • Cross-platform browser launching (macOS, Windows, Linux)
  • Automatic token refresh before expiry
  • Integrated as default plugin in opencode

New Package

packages/openai-codex-auth/ - Layer 1 built-in plugin

Usage

  1. Run opencode auth login
  2. Select "ChatGPT Plus/Pro (Codex Subscription)"
  3. Complete OAuth in browser
  4. Use OpenAI models with your subscription

Based on: https://github.com/numman-ali/opencode-openai-codex-auth

Test plan

  • Build succeeds
  • opencode auth login shows the new option
  • OAuth flow completes successfully
  • Tokens stored in ~/.opencode/data/auth.json

🤖 Generated with Claude Code

brettheap and others added 14 commits December 30, 2025 00:28
Implements built-in OAuth authentication for ChatGPT Plus/Pro subscribers
to use OpenAI models via their existing subscription.

Features:
- PKCE OAuth flow with OpenAI's auth endpoints
- Local callback server on port 1455
- Cross-platform browser launching
- Automatic token refresh
- Integrated as default plugin in opencode

Based on: https://github.com/numman-ali/opencode-openai-codex-auth

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add api.responses.read and api.responses.write scopes to OAuth config
to fix "Missing scopes: api.responses.write" error when using OpenAI API.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Remove api.responses.read/write scopes as they are not permitted
by the Codex OAuth client. API access is implicit with the token.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The OAuth token works with chatgpt.com/backend-api, not api.openai.com.
- Change base URL to https://chatgpt.com/backend-api
- Use /codex/responses endpoint
- Add required headers: OpenAI-Beta, originator, chatgpt-account-id
- Extract account ID from JWT token claims

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add custom fetch that rewrites /responses to /codex/responses.
The SDK sends requests to standard paths but Codex backend
expects the /codex prefix.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…kend

The Codex backend requires an 'instructions' field in the request body.
Add request body transformation to include default instructions if not present.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…r instructions

- Add store:false (required by ChatGPT backend)
- Extract system message from input array to use as instructions
- Improve default instructions text

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The Codex backend expects instructions starting with the Codex
identification string "You are Codex, based on GPT-5..."

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add stream=true (required by Codex backend)
- Strip item IDs from input array (stateless operation)
- Remove system message from input after extracting to instructions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Embed the actual Codex system prompt from openai/codex repository.
The backend validates instructions content.

Source: https://github.com/openai/codex/blob/main/codex-rs/core/gpt_5_codex_prompt.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Delete instructions field entirely - backend validates strictly and
uses model-specific defaults. Also remove system messages from input.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The external plugin has proper prompt alignment with the Codex backend.
Use it as primary with built-in as fallback.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Use external opencode-openai-codex-auth plugin instead, which has
proper prompt alignment with the Codex backend. The built-in version
was added but never worked correctly.

Changes:
- Remove packages/openai-codex-auth/ directory
- Remove fallback logic in plugin loader
- Update dependencies

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@brettheap brettheap closed this Dec 31, 2025
@brettheap brettheap deleted the feat/openai-codex-auth branch December 31, 2025 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants