Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Sep 8, 2025

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:

  • A clean grey message indicating the limit was reached
  • A verbose red error message containing the full system prompt and agent instructions

This creates a poor user experience and unnecessarily exposes internal implementation details.

Solution

This PR modifies the Claude Code provider to:

  1. Detect 5-hour rate limit errors by checking for specific keywords ("5-hour", "5 hour", "rate limit", "quota")
  2. Replace the verbose error message with a clean, user-friendly localized message
  3. Prevent system prompts from being exposed to users

Changes

  • Modified src/api/providers/claude-code.ts to detect and handle rate limit errors
  • Added translation key rateLimitReached to src/i18n/locales/en/common.json

Testing

  • All existing tests pass
  • Type checking passes
  • Linting passes

Fixes #7778


Important

Enhances error handling in claude-code.ts for 5-hour rate limit errors, adding user-friendly messages and preventing system prompt exposure.

  • Behavior:
    • Detects 5-hour rate limit errors in src/api/providers/claude-code.ts by checking for keywords like "5-hour", "rate limit", and "quota".
    • Replaces verbose error messages with a user-friendly localized message.
    • Prevents exposure of system prompts to users.
  • Localization:
    • Adds rateLimitReached translation key to src/i18n/locales/en/common.json for user-friendly error messages.
  • Testing:
    • All existing tests pass.
    • Type checking and linting pass.

This description was created by Ellipsis for b038a47. You can customize this summary. It will automatically update as commits are pushed.

- 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
@roomote roomote bot requested review from cte, jr and mrubens as code owners September 8, 2025 10:51
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working labels Sep 8, 2025
Copy link
Contributor Author

@roomote roomote bot left a 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."
Copy link
Contributor Author

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 (
Copy link
Contributor Author

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") ||
Copy link
Contributor Author

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") ||
Copy link
Contributor Author

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:

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 8, 2025
@daniel-lxs
Copy link
Member

This issue needs scoping, I think we can implement a better general solution to transform the errors from Claude Code.

@daniel-lxs daniel-lxs closed this Sep 9, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 9, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Extra long error message when Claude Code hits 5-hour limit

4 participants