Skip to content

feat(ai-providers): add Codex as a provider (ChatGPT OAuth login and/or CLI integration) #32

Description

@hyskasoftware

Summary

Add Codex (OpenAI's terminal coding agent, https://github.com/openai/codex) as a first-class AI provider in HysCode, supporting both sign-in methods available in the Codex CLI:

  1. ChatGPT OAuth login — reuse the Codex auth flow (codex login) so users with a ChatGPT plan (Plus/Pro/Business/Edu/Enterprise) can use Codex inside HysCode without an API key.
  2. API key / access tokencodex login --with-api-key (usage-based billing) and enterprise access tokens (codex login --with-access-token).

Background / Research

Verified 2026-08-01 from https://developers.openai.com/codex/auth and https://developers.openai.com/codex/sdk:

  • Install: npm install -g @openai/codex; Windows: irm https://chatgpt.com/codex/install.ps1 | iex.
  • Sign-in methods:
    • ChatGPT (OAuth): codex login opens a browser flow; tokens auto-refresh during use. Device-code variant codex login --device-auth (beta) for headless/remote setups.
    • API key: printenv OPENAI_API_KEY | codex login --with-api-key (standard API rates, platform billing).
    • Enterprise access token: printenv CODEX_ACCESS_TOKEN | codex login --with-access-token (ChatGPT Enterprise workspaces).
  • Credentials cached in ~/.codex/auth.json (plaintext) or the OS keyring via cli_auth_credentials_store = "file | keyring | auto" in config.toml. The CLI and IDE extension share the same cache; login state can be queried with codex login status.
  • Codex SDK (TypeScript): @openai/codex-sdknew Codex(), codex.startThread(), thread.run(prompt), codex.resumeThread(id). Requires Node.js 18+; it spawns/controls the local Codex runtime. This matches the pattern HysCode already uses for the Claude Agent sidecar.
  • The Codex CLI also supports non-interactive execution and can run as an MCP server — alternative integration seams.

Proposed integration (decision needed at implementation time)

Option A — SDK sidecar (recommended, mirrors claude-agent-sidecar)

  • New package packages/codex-sidecar bundling @openai/codex-sdk (same shape as packages/claude-agent-sidecar).
  • New provider codex in packages/ai-providers/src/providers/codex.ts following ClaudeAgentProvider (packages/ai-providers/src/providers/claude-agent.ts): model catalog + chat() delegating to an injected CodexInvoke transport.
  • New Tauri command codex_run in apps/desktop/src-tauri/src/commands/ (mirrors claude_agent.rs) that spawns the sidecar.
  • Auth: detect existing ~/.codex/auth.json / keyring; optionally drive codex login from the app for the ChatGPT OAuth flow. No API keys stored in TS/SQLite — use the existing Rust keychain layer.
  • Registration in packages/ai-providers/src/registry.ts (initialize + reinitializeProvider).

Option B — Codex CLI as MCP server: connect through the existing packages/mcp-client (stdio transport). Less code, but coarser integration (thread model, streaming, tool routing) and a weaker fit with the AIProvider.chat() contract.

Scope

  • Decide Option A vs B (or hybrid: SDK for agentic runs, plain OpenAI provider for chat-only)
  • Provider registration + model catalog (Codex models, context window, pricing, tool/streaming flags)
  • Auth UX in Settings: API key input and/or "Sign in with ChatGPT" browser flow; honor ~/.codex/auth.json if present
  • Sidecar bundling + Tauri command
  • Settings tab UI (parity with other providers)
  • Tests: model catalog, provider contract (streaming/tools), integration
  • Docs: docs/architecture/AI_PROVIDERS.md

Acceptance criteria

  • Provider codex appears in the provider picker and works with both ChatGPT login and API key
  • Streaming (AsyncIterable<StreamChunk>) and tool calls work through the harness
  • No API keys in TypeScript or SQLite (Rust keychain layer only)
  • npm run lint && npm run typecheck green
  • Rust changes (if any): cargo test, cargo clippy, cargo fmt green
  • ./scripts/agent-preflight.sh (or PowerShell equivalent) green
  • Docs updated

Notes

  • The Codex CLI shares its auth cache with the IDE extension — reading ~/.codex/auth.json must be done carefully (plaintext token file, treated like a password).
  • Out of scope for now: Codex cloud / workspace agents, codex app desktop-app integration, Codex security scans.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions