published fresh until

Why does Claude Code Vertex reuse an expired helper token?

Summary If Claude Code calls a Vertex gateway with an expired helper token and gets 401s, compare the helper TTL with its refresh margin and consider the reported shorter cache; automatic refresh after rejection remains unresolved.

Not for a helper script that exits or prints invalid output; see claude-code-apikeyhelper-script-is-failing-stdout.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

For Claude Code Vertex gateway 401s with an expired helper token, consider the reporter's shorter helper-cache workaround while treating automatic rejection-triggered refresh as unresolved (edonaliko, anthropics/claude-code #105408).

Do first: compare CLAUDE_CODE_API_KEY_HELPER_TTL_MS with the helper's refresh margin; edonaliko reports using 90000 when their helper renews tokens with under two minutes remaining (October 27).

The report's exact symptom is “401 Unauthorized: Token has expired”: requests continue using cached output after rejection. There is one live reporter plus a separate diagnostic analysis (edonaliko, Ben-Home).

Not for: helper execution failures or noisy stdout; see claude-code-apikeyhelper-script-is-failing-stdout.

Diagnostic: 401 Unauthorized: Token has expired

Affected configuration: edonaliko reports Claude Code 2.1.308 on macOS, Terminal.app, with CLAUDE_CODE_USE_VERTEX=1, CLAUDE_CODE_SKIP_VERTEX_AUTH=1, an internal Vertex-compatible gateway and apiKeyHelper. Their gateway authenticates users with 60-minute Okta ID tokens, while holding the GCP credentials itself. They report recovery with the same helper and gateway in Bedrock mode, but no helper rerun after the Vertex gateway's 401 (October 27, #105408).

Cause and the two proposed responses

  • Reporter's diagnosis: edonaliko's inspection of the 2.1.304 bundle suggests Vertex classifies the 401 as a GCP credential error before reaching the generic helper-cache clearing path. They propose letting gateway-auth 401s reach that path or clearing the helper cache in the Vertex branch. As of November 19, 2026, the report proposes avoiding GCP-credential classification of a 401 when CLAUDE_CODE_SKIP_VERTEX_AUTH is set (report and code walkthrough).
  • Reported workaround: edonaliko reports setting the helper TTL to 90,000 ms, below their helper's two-minute refresh margin, so the helper re-runs every 90 seconds instead of only when needed. This is specific to that helper and costs more helper invocations; it does not repair rejection-triggered refresh (same report).
  • Separate analysis: Ben-Home suggests a five-minute TTL against a 60-minute token to distinguish scheduled renewal from the missing 401 path. Their October 29 reply is a diagnostic proposal, not an independent live reproduction or proof that five minutes fits edonaliko's helper (comment).

A reader check can compare helper invocation timestamps around token renewal and a naturally occurring rejection; that adapts the invocation-log comparison in edonaliko's reproduction. Do not count a shorter cache as proof that the 401 handler reruns the helper (reproduction).

Resolution status

#105408 is open. The anthropics/claude-code 2.1.316 release includes gateway sign-in and other auth changes but does not name this Vertex helper-refresh defect. No released fix is established by these sources.

Limits

Single live reporter; the second contributor supplies analysis rather than another deployment result. Native Vertex GCP authentication, other helper implementations and Bedrock failures are outside this case. The TTL must fit actual token age and helper refresh behavior; no universal value is established.

Checked 2026-11-19.

Started from a post by @edonaliko, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Why does Claude Code Vertex reuse an expired helper token?
Summary: If Claude Code calls a Vertex gateway with an expired helper token and gets 401s, compare the helper TTL with its refresh margin and consider the reported shorter cache; automatic refresh after rejection remains unresolved.
Copy for agent
get the whatworks thread claude-code-vertex-apikeyhelper-401-token-refresh and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread claude-code-vertex-apikeyhelper-401-token-refresh
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks