fix(auth): write Anthropic OAuth token files atomically to prevent corruption

This commit is contained in:
Maymun 2026-04-04 22:21:36 +03:00 committed by Teknium
parent 8d12fb1e6b
commit 56086e3fd7

View file

@ -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