claude-code - 💡(How to fix) Fix [BUG] GCP OAuth2 token fetched on every request instead of being cached [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52324Fetched 2026-04-24 06:10:11
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×4

Error Message

Error Messages/Logs

Fix Action

Fix / Workaround

Workaround

Code Example

CLAUDE_CODE_USE_VERTEX=1
  CLOUD_ML_REGION=global
  ANTHROPIC_VERTEX_PROJECT_ID=prj-noncore-dev-totc2
  VERTEX_REGION_CLAUDE_3_5_HAIKU=global

---

POST https://oauth2.googleapis.com/token        ← repeated every request
POST https://aiplatform.googleapis.com/v1/...   ← actual Claude API call
POST https://oauth2.googleapis.com/token        ← repeated every request
POST https://aiplatform.googleapis.com/v1/...   ← actual Claude API call
...

---
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Environment

  • Claude Code version: 2.1.118 (Claude Code)
  • Backend: Vertex AI
  • Environment variables set:
    CLAUDE_CODE_USE_VERTEX=1
    CLOUD_ML_REGION=global
    ANTHROPIC_VERTEX_PROJECT_ID=prj-noncore-dev-totc2
    VERTEX_REGION_CLAUDE_3_5_HAIKU=global

Describe the bug

Claude Code appears to call https://oauth2.googleapis.com/token on every outgoing request to Vertex AI, rather than fetching a token once, caching it, and reusing it for up to its 1-hour TTL.

Expected behavior

GCP Bearer tokens are valid for 1 hour. The token should be fetched once per session (or per expiry), cached in memory, and reused for all subsequent Vertex AI requests within that window — consistent with standard GCP client library behavior.

Actual behavior

A call to oauth2.googleapis.com/token is observed before every call to aiplatform.googleapis.com, e.g.:

POST https://oauth2.googleapis.com/token        ← repeated every request
POST https://aiplatform.googleapis.com/v1/...   ← actual Claude API call
POST https://oauth2.googleapis.com/token        ← repeated every request
POST https://aiplatform.googleapis.com/v1/...   ← actual Claude API call
...

Impact

  • Adds latency to every request (an extra round-trip to Google's auth endpoint)
  • Unnecessarily chatty — inflates network traffic and token issuance volume
  • May cause rate limiting on oauth2.googleapis.com in high-usage scenarios

Workaround

None available for CLI users.

What Should Happen?

GCP Bearer tokens are valid for 1 hour. The token should be fetched once per session (or per expiry), cached in memory, and reused for all subsequent Vertex AI requests within that window — consistent with standard GCP client library behavior.

Error Messages/Logs

Steps to Reproduce

Run claude and send hi.

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.118 (Claude Code)

Platform

Google Vertex AI

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

extent analysis

TL;DR

Implement token caching to reuse GCP Bearer tokens for up to 1 hour, reducing unnecessary requests to https://oauth2.googleapis.com/token.

Guidance

  • Investigate the authentication mechanism used by Claude Code to identify where token caching can be implemented.
  • Consider using an in-memory cache with a TTL of 1 hour to store and reuse GCP Bearer tokens.
  • Review the Vertex AI client library documentation to ensure consistency with standard GCP client library behavior.
  • Monitor network traffic and token issuance volume to verify the effectiveness of the token caching implementation.

Example

No code snippet is provided as the issue does not contain sufficient information about the authentication mechanism used by Claude Code.

Notes

The implementation of token caching may require modifications to the Claude Code authentication mechanism, which could have implications for security and token management.

Recommendation

Apply a workaround by implementing token caching, as this is likely to reduce latency and unnecessary network traffic, and prevent potential rate limiting issues on oauth2.googleapis.com.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING