First-run users with a credential already exported (ANTHROPIC_API_KEY,
OPENAI_API_KEY, etc.) currently still have to navigate the provider picker
or set CLAUDE_CODE_USE_* flags manually. Selecting the right provider from
ambient state should be automatic.
New module src/utils/providerAutoDetect.ts:
- detectProviderFromEnv() — synchronous env scan in a deterministic priority
order (anthropic → codex → github → openai → gemini → mistral → minimax).
Also detects Codex via ~/.codex/auth.json presence.
- detectLocalService() — parallel probes for Ollama (:11434) and LM Studio
(:1234), with honoring of OLLAMA_BASE_URL / LM_STUDIO_BASE_URL overrides.
Short 1.2s default timeout so first-run latency stays low when no local
service is running.
- detectBestProvider() — orchestrator. Env scan short-circuits the probe;
only hits the network when env has nothing.
All detection paths are side-effect-free: returns a DetectedProvider
descriptor describing what was found and why. Callers decide whether to
apply it (gated on hasExplicitProviderSelection() / profile file existence)
and how to hydrate the launch env.
Codex auth-file check is injectable (hasCodexAuth option) so tests are
hermetic from the dev machine's ~/.codex/auth.json state.
Co-authored-by: OpenClaude <openclaude@gitlawb.com>