CurioQuest (Second-Brain)
wiki/decisions/2026-06-29-claude-code-oauth-text-generation.md
ADR: Claude Code OAuth for Local Text Generation
Date: 2026-06-29 Status: Accepted
Context
The CurioQuest backend initially used OpenAI Responses API for all text generation stages. That is clean for production, but too expensive for local/sample iteration while the product is still undergoing prompt, judge, and quality-loop development. The founder wants to keep OpenAI for image generation because GPT Image quality is materially better, but use Anthropic/Claude for writing-oriented stages where Claude is also expected to perform strongly.
Decision
Use a provider switch for text generation: TEXT_GENERATION_PROVIDER=openai keeps the OpenAI API path, while TEXT_GENERATION_PROVIDER=claude_code_oauth uses Claude Code OAuth locally for text artifacts.
Rationale
- Claude Code OAuth allows local/sample generation through the user's Claude login flow without requiring OpenAI text API calls for every iteration.
- The backend remains provider-swappable instead of hardcoding one model vendor.
- OpenAI remains available for image-generation stages where it is currently preferred.
- Claude Code OAuth is appropriate for local/development sample generation, while hosted production can still use provider API keys or a separate production auth path.
Alternatives Considered
| Option | Why rejected |
|---|---|
| Keep OpenAI Responses API for all text | Too expensive for high-iteration story and prompt development. |
| Use unsupported ChatGPT/OpenAI OAuth token reuse | Not a supported backend API auth pattern and too brittle/risky. |
| Replace all generation including images with Anthropic | Does not address the current preference for OpenAI image quality. |
| Manual copy/paste ChatGPT/Claude workflow only | Lower cost but breaks automation and artifact provenance. |
Consequences
- New env vars:
TEXT_GENERATION_PROVIDER=claude_code_oauthCLAUDE_CODE_OAUTH_TOKENCLAUDE_CODE_MODELCLAUDE_OAUTH_TOKENis accepted as a fallback alias.- App-side generation can now run text stages through Claude Code CLI in local/dev.
- The provider clears
ANTHROPIC_API_KEYandANTHROPIC_AUTH_TOKENin the child process to avoid silently using API billing on this local path. - Hosted production still needs a deliberate provider/auth decision before launch.