← statichum.studio

Local-first OAuth credential broker that serializes single-use refresh-token rotation across concurrent CLI processes and AI agents

dev tool real project •• multiple requests

Developers running multiple CLI processes, parallel AI coding agents, cron jobs, or multi-tab clients against the same OAuth credentials keep getting logged out, because providers like Anthropic MCP and OpenAI Codex now use rotating single-use refresh tokens. When two processes read the same refresh token and both redeem it, the first wins and the rest are de-authed with refresh_token_reused or invalid_grant. The fix devs keep describing is a small local broker daemon that owns the refresh state, serializes the read-refresh-write cycle behind a lock, and vends fresh access tokens to every process, provider-agnostic and with no enterprise identity provider required.

builder note

Do not try to fix this inside each app. Ship one tiny local broker (Unix socket or localhost) that becomes the single refresh authority, so every process asks it for an access token instead of touching the shared credentials file and rotation happens once behind a lock. singleflight plus atomic temp-file rename plus a short grace window on the previous refresh token covers nearly every reported failure mode, and provider adapters are thin.

landscape (3 existing solutions)

The industry is converging on a credential-broker or sidecar pattern in 2026, but shipping options are either enterprise-IdP-bound or vault-flavored. The local-first, provider-agnostic broker for N processes sharing one rotating refresh token does not exist, so every CLI and agent reimplements (or skips) the locking and hits the same race.

Nango Managed SaaS for app-to-API integrations (800+ APIs), server-side. Nango's own engineering writeup describes concurrent refresh-token rotation as an unresolved gap with no standard library. It is not a local broker for coordinating one shared credential file across processes on a single machine.
Microsoft Entra Auth SDK sidecar Handles token lifecycle and caching as a sidecar, but is bound to Entra and enterprise identity providers, not provider-agnostic, and is overkill for indie devs and agent fleets.
Generic locking primitives (proper-lockfile, async-mutex, OS flock, singleflight) You wire these up yourself, per app and per provider. There is no purpose-built, provider-agnostic drop-in broker, which is exactly why the same race recurs across Claude Code, Codex, and others.

sources (2)

other https://github.com/anthropics/claude-code/issues/66210 "MCP OAuth refresh token being used 4 days after it was already refreshed" 2026-06-08
other https://github.com/router-for-me/CLIProxyAPI/issues/3783 "Concurrent token refreshes for the same Codex ... credential can fail with refresh_token_reused" 2026-06-09
oauthrefresh-tokenai-agentscli-toolingauth