-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: handle Claude Code 5-hour rate limit errors gracefully #7779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Detect 5-hour rate limit errors in Claude Code provider - Replace verbose error messages containing system prompts with a clean, user-friendly message - Add translation key for rate limit message Fixes #7778
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed my own code and found issues. Classic case of 'it worked on my machine... in English only.'
| "apiKeyModelPlanMismatch": "API keys and subscription plans allow different models. Make sure the selected model is included in your plan.", | ||
| "notFound": "Claude Code executable '{{claudePath}}' not found.\n\nPlease install Claude Code CLI:\n1. Visit {{installationUrl}} to download Claude Code\n2. Follow the installation instructions for your operating system\n3. Ensure the 'claude' command is available in your PATH\n4. Alternatively, configure a custom path in Roo settings under 'Claude Code Path'\n\nOriginal error: {{originalError}}" | ||
| "notFound": "Claude Code executable '{{claudePath}}' not found.\n\nPlease install Claude Code CLI:\n1. Visit {{installationUrl}} to download Claude Code\n2. Follow the installation instructions for your operating system\n3. Ensure the 'claude' command is available in your PATH\n4. Alternatively, configure a custom path in Roo settings under 'Claude Code Path'\n\nOriginal error: {{originalError}}", | ||
| "rateLimitReached": "5-hour usage limit reached. Please wait for the limit to reset before continuing." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This translation key needs to be added to all other locale files (es, fr, de, etc.) to prevent runtime errors for non-English users. Could we add the missing translations or at least provide English fallbacks for now?
Also ensure this key is added to all locale files in src/i18n/locales/*/common.json
| if (!error) { | ||
| // Check if this is a 5-hour rate limit error | ||
| // These errors typically contain system prompts and are very long | ||
| if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rate limit detection logic is duplicated here and again at lines 99-105. Could we extract this into a helper function to follow DRY principles?
| if ( | ||
| content.text.includes("5-hour") || | ||
| content.text.includes("5 hour") || | ||
| content.text.includes("rate limit") || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The keywords "rate limit" and "quota" are quite generic and might match other unrelated errors. Is this intentional? Could we make the detection more specific to Claude Code's 5-hour limit, perhaps by also checking for "Claude" or specific error codes?
| // Check if this is a 5-hour rate limit error | ||
| // These errors typically contain system prompts and are very long | ||
| if ( | ||
| content.text.includes("5-hour") || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using case-insensitive matching here for better robustness. Error messages from the API might vary in capitalization:
|
This issue needs scoping, I think we can implement a better general solution to transform the errors from Claude Code. |
This PR attempts to address Issue #7778. Feedback and guidance are welcome.
Problem
When Claude Code hits the 5-hour usage limit, users see both:
This creates a poor user experience and unnecessarily exposes internal implementation details.
Solution
This PR modifies the Claude Code provider to:
Changes
src/api/providers/claude-code.tsto detect and handle rate limit errorsrateLimitReachedtosrc/i18n/locales/en/common.jsonTesting
Fixes #7778
Important
Enhances error handling in
claude-code.tsfor 5-hour rate limit errors, adding user-friendly messages and preventing system prompt exposure.src/api/providers/claude-code.tsby checking for keywords like "5-hour", "rate limit", and "quota".rateLimitReachedtranslation key tosrc/i18n/locales/en/common.jsonfor user-friendly error messages.This description was created by
for b038a47. You can customize this summary. It will automatically update as commits are pushed.