Skip to content

fix(claude): use sk-ant-oat01 placeholder, drop CLAUDE_CODE_OAUTH_TOKEN env#351

Merged
dpup merged 2 commits into
majorcontext:mainfrom
abezzub-dr:fix/claude-oauth-placeholder-token
May 18, 2026
Merged

fix(claude): use sk-ant-oat01 placeholder, drop CLAUDE_CODE_OAUTH_TOKEN env#351
dpup merged 2 commits into
majorcontext:mainfrom
abezzub-dr:fix/claude-oauth-placeholder-token

Conversation

@abezzub-dr
Copy link
Copy Markdown
Contributor

Summary

Split out of #308 per @dpup's review.

Claude Code checks the sk-ant-oat prefix to decide whether the session is OAuth-authenticated. With the previous CLAUDE_CODE_OAUTH_TOKEN=moat-proxy-injected env var, Claude Code did not recognize the session as OAuth and skipped the OAuth code paths that determine account capabilities (e.g. 1M context window availability for subscription accounts).

Replace the env var with a .credentials.json containing an sk-ant-oat01-* placeholder. The real token is still injected by the proxy at the network layer; the placeholder never reaches Anthropic's servers.

  • Add credential.ClaudeOAuthPlaceholder constant
  • containerEnvForCredential and OAuthProvider.ContainerEnv return nil for the claude provider so Claude Code reads .credentials.json instead of the env var
  • WriteCredentialsFile writes the new placeholder

Test plan

  • make test-unit (unrelated internal/deps URL-reachability failures only)
  • make lint
  • moat claude recognizes OAuth session and shows subscription tier

…EN env

Claude Code checks the sk-ant-oat prefix to decide whether the session is
OAuth-authenticated. With the previous CLAUDE_CODE_OAUTH_TOKEN=moat-proxy-injected
env var, Claude Code did not recognize the session as OAuth and skipped the
OAuth code paths that determine account capabilities (e.g. 1M context window
availability for subscription accounts).

Replace the env var with a .credentials.json containing an sk-ant-oat01-*
placeholder. The real token is still injected by the proxy at the network
layer; the placeholder never reaches Anthropic's servers.

- Add credential.ClaudeOAuthPlaceholder constant
- containerEnvForCredential and OAuthProvider.ContainerEnv return nil for
  the "claude" provider so Claude Code reads .credentials.json instead of
  the env var
- WriteCredentialsFile writes the new placeholder
@abezzub-dr abezzub-dr force-pushed the fix/claude-oauth-placeholder-token branch from 66644c3 to bfe9477 Compare May 18, 2026 15:50
TestStartNoFirewallWhenNotEnabled was flaky on CI. The test installs
a Store backed by t.TempDir() on the Run, but never stops the monitor
goroutine that Start() spawns. captureLogs inside monitorContainerExit
opens <store>/logs.jsonl, racing with the testing framework's TempDir
cleanup: depending on scheduling the test failed with either
"directory not empty" (cleanup interleaved with the goroutine's file
creation) or warning logs about "no such file or directory" (cleanup
finished first).

Register a t.Cleanup after the store t.TempDir() call. Because Cleanup
runs LIFO, this fires before the temp dir is removed: monitorCancel
unblocks WaitContainer, monitorWg.Wait blocks until captureLogs and
cleanupResources finish, and only then does t.TempDir() proceed.

Reproduced 6/20 failures without the fix; 100 race-enabled runs pass
after it.
@dpup dpup merged commit 3ecc34a into majorcontext:main May 18, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants