## π― Major Improvements ### Smart ETag-Based Caching - Replaced 24-hour TTL cache with HTTP ETag-based conditional requests - Only downloads instructions when content actually changes (304 Not Modified responses) - Significantly reduces GitHub API calls while staying up-to-date ### Release Tag Tracking for Stability - Now fetches Codex instructions from latest GitHub release tag instead of main branch - Ensures compatibility with ChatGPT Codex API (main branch may have unreleased features) - Prevents "Instructions are not valid" errors from bleeding-edge changes ## π Bug Fixes ### Model Normalization - Fixed default model fallback: unsupported models now default to `gpt-5` (not `gpt-5-codex`) - Preserves user's choice between `gpt-5` and `gpt-5-codex` when explicitly specified - Only codex model variants normalize to `gpt-5-codex` ### Error Prevention - Added `body.text` initialization check to prevent TypeError on `body.text.verbosity` - Improved error handling in request transformation ### Code Quality - Standardized all console.error prefixes to `[openai-codex-plugin]` - Updated documentation to reflect ETag caching implementation - Added npm version and downloads badges to README ## π Documentation - Updated README with accurate caching behavior description - Added npm package badges for version tracking - Clarified release-based fetching strategy Co-authored-by: Hanzo Dev <[email protected]>
OpenAI ChatGPT OAuth Plugin for opencode
This plugin enables opencode to use OpenAI's Codex backend via ChatGPT Plus/Pro OAuth authentication, allowing you to use your ChatGPT subscription instead of OpenAI Platform API credits.
Features
- β ChatGPT Plus/Pro OAuth authentication
- β Zero external dependencies - Lightweight with only @openauthjs/openauth
- β Auto-refreshing tokens - Handles token expiration automatically
- β Smart auto-updating Codex instructions - Tracks latest stable release with ETag caching
- β Full tool support (write, edit, bash, grep, etc.)
- β Automatic tool remapping (Codex tools β opencode tools)
- β High reasoning effort with detailed thinking blocks
- β Modular architecture for easy maintenance
Installation
Quick Start
No npm install needed! opencode automatically installs plugins when you add them to your config.
-
Add plugin to your opencode configuration:
Edit your
opencode.jsonfile (create it if it doesn't exist):Global config:
~/.config/opencode/opencode.jsonProject config:<project>/.opencode.json{ "$schema": "https://opencode.ai/config.json", "plugin": [ "opencode-openai-codex-auth" ], "model": "openai/gpt-5-codex" } -
That's it! opencode will auto-install the plugin on first run.
New to opencode? Learn more:
Alternative: Local Development
For testing or development, you can use a local file path:
{
"plugin": [
"file:///absolute/path/to/opencode-openai-codex-auth"
]
}
Authentication
Login with ChatGPT OAuth:
opencode auth login
Select "OpenAI" and choose:
- "ChatGPT Plus/Pro (Codex Subscription)" - Opens browser automatically for OAuth flow
Important
: Make sure the official Codex CLI is not running during first login, as both use port 1455 for OAuth callback. After initial authentication, this won't be an issue.
Usage
# Use gpt-5-codex with high reasoning (default)
opencode run "create a hello world file" --model=openai/gpt-5-codex
# Or set as default in opencode.json
opencode run "solve this complex algorithm problem"
The plugin automatically configures:
- High reasoning effort for deep thinking
- Detailed reasoning summaries to show thought process
- Medium text verbosity for balanced output
How It Works
The plugin:
- Authentication: Uses ChatGPT OAuth flow with PKCE for secure authentication
- Token Management: Native token refresh implementation (no external dependencies)
- Codex Instructions: Automatically fetches from the latest stable release of openai/codex
- Tracks latest release tag (not main branch) for stability
- Uses ETag-based caching for efficient updates (only downloads when content changes)
- Cached locally in
~/.opencode/cache/ - Auto-updates when OpenAI publishes new releases
- Falls back to bundled version if GitHub is unavailable
- Request Transformation: Routes requests to
https://chatgpt.com/backend-api/codex/responses - Model Normalization: Maps all model names to
gpt-5-codex(the Codex backend model) - Tool Remapping: Injects instructions to map Codex tools to opencode tools:
apply_patchβeditupdate_planβtodowrite
- Reasoning Configuration: Forces high reasoning effort with detailed summaries
- History Filtering: Removes stored conversation IDs since Codex uses
store: false
Limitations
- ChatGPT Plus/Pro required: Must have an active ChatGPT Plus or Pro subscription
- Medium text verbosity: Codex only supports
mediumfor text verbosity
Troubleshooting
Authentication Issues
- Ensure you have an active ChatGPT Plus or Pro subscription
- Try re-logging in with
opencode auth login - Check browser console during OAuth flow if auto-login fails
Tool Execution Issues
- Verify plugin is loaded in
opencode.json - Check that model is set to
openai/gpt-5-codex - Check
~/.opencode/cache/for cached instructions (auto-downloads from GitHub)
Request Errors
- 401 Unauthorized: Token expired, run
opencode auth loginagain - 400 Bad Request: Check console output for specific error details
- 403 Forbidden: Subscription may be expired or invalid
Project Structure
opencode-openai-codex-auth/
βββ index.mjs # Main plugin entry point
βββ lib/
β βββ auth.mjs # OAuth authentication logic
β βββ codex.mjs # Codex instructions & tool remapping
β βββ server.mjs # Local OAuth callback server
β βββ codex-instructions.md # Bundled Codex instructions (fallback)
βββ package.json
βββ README.md
βββ LICENSE
Module Overview
- index.mjs: Main plugin export and request transformation
- lib/auth.mjs: OAuth flow, PKCE, token exchange, JWT decoding
- lib/codex.mjs: Fetches/caches Codex instructions from GitHub, tool remapping
- lib/server.mjs: Local HTTP server for OAuth callback handling
Credits
Based on research and working implementations from:
- ben-vargas/ai-sdk-provider-chatgpt-oauth
- ben-vargas/ai-opencode-chatgpt-auth
- openai/codex OAuth flow
- sst/opencode
License
MIT