Device Code authentication for OpenCode - authenticate ChatGPT Plus/Pro in headless environments (SSH, Docker, remote servers).
OpenCode's built-in ChatGPT OAuth requires a browser on the same machine. This tool uses Device Code flow to authenticate from any browser, even on a different device.
Enable Device Code authentication in your ChatGPT account:
- Go to ChatGPT Codex Security Settings
- Turn on "Enable device code authentication for Codex"
npx opencode-openai-device-authnpm install -g opencode-openai-device-auth
opencode-openai-device-auth- Run the command - you'll get a URL and a one-time code
- Open the URL in any browser (phone, laptop, etc.)
- Enter the code and sign in with your ChatGPT account
- Tokens are saved to
~/.local/share/opencode/auth.json - Use OpenCode normally with ChatGPT Plus/Pro models
=== OpenCode OpenAI Device Code Authentication ===
Requesting device code...
Follow these steps to sign in:
1. Open this link in your browser:
https://auth.openai.com/codex/device
2. Enter this one-time code (expires in 15 minutes)
ABCD-12345
Waiting for authorization...
..........
✓ Authentication successful!
Tokens saved to /home/user/.local/share/opencode/auth.json
You can now use OpenCode with your ChatGPT subscription:
opencode run "hello" --model=openai/gpt-5.1-codex
- SSH sessions - Authenticate on remote servers
- Docker containers - No browser needed inside containers
- CI/CD pipelines - Automate authentication
- Headless servers - No GUI required
Based on OpenAI Codex CLI's device code implementation.
MIT
