DEV Community
Follow
Five Requests in Fifteen Seconds From One Status Bar Item
The Claude Code VS Code extension displays usage limits directly in the status bar for user convenience. Initially, the extension made frequent API calls, leading to rate limiting errors. The core issue identified was that each VS Code window ran a separate instance of the extension, duplicating requests. To resolve this, a shared global storage file was implemented to store usage data accessible by all windows. This file allows windows to read cached data and only fetch updates when necessary, based on a refresh interval.A claim system was introduced to prevent multiple windows from fetching data simultaneously. If a window detects another window is already fetching, it waits. Random jitter was added to timers to avoid synchronized requests from multiple windows. When an API returns a 429 rate limit error, this information is now stored in the shared file, preventing further requests until the block expires.The extension also improved its handling of failed API checks. Instead of displaying a warning immediately, it now retains the last known usage data and retries after increasing intervals. Warnings are only shown after multiple consecutive failures. The extension explicitly states that it only reads login credentials and never refreshes or writes them back. It makes a single, shared API request per window for usage data and avoids telemetry or other network calls. The principles outlined are to assume one copy per window, treat 429 errors as instructions to wait, and consider single failures as noise rather than critical.