fix(anthropic): OAuth identity rewrite corrupted .clawcodex paths into ~/.Claude Code#710
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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>/memoryand/Users/…/.Claude Code/sessions— was not model guessing. On Claude-subscription OAuth logins,AnthropicProvider._prepare_subscription_request()runsover 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 shippedclean()over the real assembled prompt produces exactly the paths from the failure trace.This only bites subscription logins (
api_keyempty +anthropic-oauth.jsonpresent), 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:
~/.clawcodex/…,/etc/clawcodex,.clawcodex/settings.json$CLAWCODEX_CONFIG_DIR/CLAWCODEX_CONFIG_DIRclawcodex_dirs.pyclawcodex.appStandalone prose (
clawcodex data directory:,run clawcodex.,clawcodex, the tool) is still rewritten, and the officialYou are Claude Code…prefix block is unchanged, so the OAuth-endpoint conventions are preserved.Tests
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 Codenever appears, prose is still disguised, prefix block stays first.test_provider_uses_bearer_oauth_and_adapts_tools(assertsClawCodexprose is disguised) still passes.test_anthropic_subscription/test_prompt_assembly/test_live_base_system_prompt/test_clawcodex_dirs; 72 green acrosstest_model_system/test_openai_subscription(that path passesinstructionsthrough untouched — no analogous bug)._prepare_subscription_request— memory/sessions/data-dir paths intact, no.Claude Code, brand prose disguised.🤖 Generated with Claude Code