Skip to content

[Bug] subscription-mode ocx claude becomes unauthenticated when host-managed flag is injected without a host token #253

Closed

Description

@MustangRider

Summary

Since v2.7.27, ocx claude injects CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1 in every Claude Code auth mode. In the default subscription mode, OpenCodex intentionally does not provide ANTHROPIC_AUTH_TOKEN because Claude Code is expected to keep using the user's existing claude.ai OAuth session. On Claude Code 2.1.206, combining that native-OAuth path with the host-managed flag makes the CLI report Not logged in · Please run /login.

The failure is isolated to the flag: the same installed Claude Code and OAuth session work when the variable is absent or set to 0.

Environment

  • Windows 11
  • OpenCodex 2.7.31
  • Claude Code 2.1.206
  • claudeCode.authMode: unset (default subscription mode)
  • No OpenCodex admission API keys configured
  • Existing claude.ai Max OAuth login

Reproduction

All tests below were run in the same shell environment. Values were changed only for the child process; no persistent environment variables were modified.

$ claude -p "Reply with exactly: OK" --output-format text
OK
exit 0

$ env -u CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST ocx claude -p "Reply with exactly: OK" --output-format text
Not logged in · Please run /login
exit 1

$ CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=0 ocx claude -p "Reply with exactly: OK" --output-format text
OK
exit 0

$ CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1 claude -p "Reply with exactly: OK" --output-format text
Not logged in · Please run /login
exit 1

This also shows that the failure does not require OpenCodex's base URL: setting the flag on plain claude is sufficient in this environment.

Regression source

Commit 5875a0b added the unconditional default in buildClaudeEnv() and the GUI manual environment block. It first shipped in v2.7.27:

setDefault("CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST", "1");

The flag has a valid purpose: it protects OpenCodex routing from stale provider variables in ~/.claude/settings.json. The problem is that subscription mode simultaneously promises a native OAuth path and intentionally supplies no host credential:

if (!env.ANTHROPIC_AUTH_TOKEN && config.claudeCode?.authMode === "proxy") {
  env.ANTHROPIC_AUTH_TOKEN = "opencodex-proxy";
}

The current unit test checks only that the flag is assembled, not whether the resulting Claude Code process still has a usable subscription login.

Expected behavior

Default subscription mode should preserve the existing claude.ai OAuth login while still routing requests through OpenCodex.

Suggested direction

Gate the host-managed flag on whether OpenCodex actually supplies ANTHROPIC_AUTH_TOKEN:

  • native subscription mode, no host token: do not inject the flag
  • proxy mode or configured admission key: keep the flag and its settings-env routing protection
  • preserve an explicit user-provided 0 or 1

The same condition should be applied to the GUI's copy/paste environment block. This avoids a Claude Code version gate and preserves the original anti-hijack behavior on host-token paths.

Temporary workaround

Use a shell-scoped override rather than a persistent setx value:

$env:CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST = "0"
ocx claude

Notes

I am intentionally reporting only the directly reproduced behavior on Claude Code 2.1.206. I am not assuming an affected version range or a specific internal OAuth implementation beyond the observable login result.

Activity

  1. Ingwannu commented on Jul 22, 2026

    @Ingwannu
    Owner

    Confirmed as a real regression. CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1 is also treated as a host-auth assertion by current Claude Code, so injecting it in subscription mode without a host token made a valid claude.ai login appear unauthenticated.

    Fixed on dev in 2aa4430c:

    • Subscription mode with no ANTHROPIC_AUTH_TOKEN: host-managed flag is left unset.
    • Proxy/admission-key modes: flag remains enabled because OpenCodex owns authentication.
    • An explicit user export such as CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=0 continues to win.
    • The GUI manual environment block follows the same condition.

    CLI environment and manual-block regression tests, type/i18n checks, and the full 3,394-test isolated suite passed. Closing as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions