Skip to content

fix(anthropic): OAuth identity rewrite corrupted .clawcodex paths into ~/.Claude Code#710

Merged
agentforce314 merged 1 commit into
mainfrom
fix/oauth-clean-preserve-paths
Jul 13, 2026
Merged

fix(anthropic): OAuth identity rewrite corrupted .clawcodex paths into ~/.Claude Code#710
agentforce314 merged 1 commit into
mainfrom
fix/oauth-clean-preserve-paths

Conversation

@agentforce314

Copy link
Copy Markdown
Owner

Root cause of the errors #706 / #707 didn't fully fix

The trace that motivated those PRs — the model searching /Users/…/.Claude Code/projects/<slug>/memory and /Users/…/.Claude Code/sessions — was not model guessing. On Claude-subscription OAuth logins, AnthropicProvider._prepare_subscription_request() runs

re.sub(r"claw[ -]?codex", "Claude Code", text, flags=re.IGNORECASE)

over every system block at request time. That rewrites filesystem paths too: ~/.clawcodex/sessions/~/.Claude Code/sessions/. So the corrected paths #706/#707 added (and the auto-memory section) reached the model already corrupted — the prompt authoritatively named nonexistent locations, and the model obediently searched them. Reproduced byte-for-byte: running the shipped clean() over the real assembled prompt produces exactly the paths from the failure trace.

This only bites subscription logins (api_key empty + anthropic-oauth.json present), which is why prompt-assembly-level reproductions looked correct — the corruption happens in the provider layer, after assembly. It also explains #706's original "pure guessing" misdiagnosis.

Fix

Constrain the disguise to standalone brand mentions. Matches that are part of a machine-readable token survive verbatim:

  • path segments: ~/.clawcodex/…, /etc/clawcodex, .clawcodex/settings.json
  • env vars: $CLAWCODEX_CONFIG_DIR / CLAWCODEX_CONFIG_DIR
  • module/file names: clawcodex_dirs.py
  • domains: clawcodex.app

Standalone prose (clawcodex data directory:, run clawcodex., clawcodex, the tool) is still rewritten, and the official You are Claude Code… prefix block is unchanged, so the OAuth-endpoint conventions are preserved.

re.sub(r"(?<![\w.$/\\-])claw[ -]?codex(?![\w-])(?!\.\w)", "Claude Code", text, flags=re.IGNORECASE)

Tests

  • New test_identity_rewrite_preserves_paths_env_vars_and_domains — real-world strings from the assembled prompt (memory path, sessions Grep line, fix(prompt): name ~/.clawcodex in # Environment so the model finds session history #706 data-dir line, env var, domain, prose); asserts paths survive, .Claude Code never appears, prose is still disguised, prefix block stays first.
  • Existing test_provider_uses_bearer_oauth_and_adapts_tools (asserts ClawCodex prose is disguised) still passes.
  • 71 green across test_anthropic_subscription / test_prompt_assembly / test_live_base_system_prompt / test_clawcodex_dirs; 72 green across test_model_system / test_openai_subscription (that path passes instructions through untouched — no analogous bug).
  • End-to-end: assembled the live clawsphere prompt, ran it through the fixed _prepare_subscription_request — memory/sessions/data-dir paths intact, no .Claude Code, brand prose disguised.

🤖 Generated with Claude Code

…codex paths

_prepare_subscription_request's clean() rewrote EVERY case-insensitive
"clawcodex" in the system prompt to "Claude Code" — including filesystem
paths. On Claude-subscription logins the model was told its memory lives at
~/.Claude Code/projects/<slug>/memory and its history at
~/.Claude Code/sessions — literal nonexistent locations it then searched
verbatim. This is the real source of the "guessed wrong paths" #706/#707
addressed: those fixes emit correct paths, and this rewrite corrupted them
after prompt assembly, at the provider layer.

Constrain the rewrite to standalone brand mentions: matches inside path
segments (~/.clawcodex, /etc/clawcodex), env vars ($CLAWCODEX_CONFIG_DIR),
module/file names (clawcodex_dirs), and domains (clawcodex.app) survive
verbatim. Prose disguise and the official-prefix block are unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@agentforce314 agentforce314 merged commit a9bb25c into main Jul 13, 2026
2 checks passed
@agentforce314 agentforce314 deleted the fix/oauth-clean-preserve-paths branch July 13, 2026 21:05
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.

1 participant