From 56086e3fd7a1f4079103bc0146cb79a6ae5b91bc Mon Sep 17 00:00:00 2001 From: Maymun <139681654+maymuneth@users.noreply.github.com> Date: Sat, 4 Apr 2026 22:21:36 +0300 Subject: [PATCH] fix(auth): write Anthropic OAuth token files atomically to prevent corruption --- agent/anthropic_adapter.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/agent/anthropic_adapter.py b/agent/anthropic_adapter.py index ea09c11ea4..05449e2a77 100644 --- a/agent/anthropic_adapter.py +++ b/agent/anthropic_adapter.py @@ -641,7 +641,9 @@ def _write_claude_code_credentials( existing["claudeAiOauth"] = oauth_data cred_path.parent.mkdir(parents=True, exist_ok=True) - cred_path.write_text(json.dumps(existing, indent=2), encoding="utf-8") + _tmp_cred = cred_path.with_suffix(".tmp") + _tmp_cred.write_text(json.dumps(existing, indent=2), encoding="utf-8") + _tmp_cred.replace(cred_path) # Restrict permissions (credentials file) cred_path.chmod(0o600) except (OSError, IOError) as e: @@ -1598,4 +1600,3 @@ def build_anthropic_kwargs( return kwargs -