fix: use CLAUDE_CODE_OAUTH_TOKEN for OAuth authentication

This commit is contained in:
Thomas Marchand
2026-01-18 19:04:40 +00:00
parent 2117dec3e1
commit 9b43a0da49

View File

@@ -261,9 +261,19 @@ impl ClaudeCodeClient {
.arg("--include-partial-messages") .arg("--include-partial-messages")
.arg("--dangerously-skip-permissions"); .arg("--dangerously-skip-permissions");
// Set API key if configured // Set API key or OAuth token if configured
if let Some(ref api_key) = self.config.api_key { // OAuth tokens start with "sk-ant-oat" and must use CLAUDE_CODE_OAUTH_TOKEN
cmd.env("ANTHROPIC_API_KEY", api_key); // API keys start with "sk-ant-api" and use ANTHROPIC_API_KEY
if let Some(ref key) = self.config.api_key {
if key.starts_with("sk-ant-oat") {
// OAuth access token
cmd.env("CLAUDE_CODE_OAUTH_TOKEN", key);
debug!("Using OAuth token for Claude CLI authentication");
} else {
// Regular API key
cmd.env("ANTHROPIC_API_KEY", key);
debug!("Using API key for Claude CLI authentication");
}
} }
// Model selection // Model selection