From 3ab7a3db145e6f23ce9a9299f40fd6cdec4c00ae Mon Sep 17 00:00:00 2001 From: Roo Code Date: Mon, 8 Sep 2025 10:48:13 +0000 Subject: [PATCH] fix: handle Claude Code 5-hour rate limit errors gracefully - 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 --- src/api/providers/claude-code.ts | 21 +++++++++++++++++++++ src/i18n/locales/en/common.json | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/api/providers/claude-code.ts b/src/api/providers/claude-code.ts index dfafb78aab..cf0bc5dc8b 100644 --- a/src/api/providers/claude-code.ts +++ b/src/api/providers/claude-code.ts @@ -82,9 +82,30 @@ export class ClaudeCodeHandler extends BaseProvider implements ApiHandler { const error = this.attemptParse(errorMessage) if (!error) { + // 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") || + content.text.includes("5 hour") || + content.text.includes("rate limit") || + content.text.includes("quota") + ) { + throw new Error(t("common:errors.claudeCode.rateLimitReached")) + } throw new Error(content.text) } + // Check for 5-hour rate limit in parsed error + if ( + error.error?.message && + (error.error.message.includes("5-hour") || + error.error.message.includes("5 hour") || + error.error.message.includes("rate limit") || + error.error.message.includes("quota")) + ) { + throw new Error(t("common:errors.claudeCode.rateLimitReached")) + } + if (error.error.message.includes("Invalid model name")) { throw new Error( content.text + `\n\n${t("common:errors.claudeCode.apiKeyModelPlanMismatch")}`, diff --git a/src/i18n/locales/en/common.json b/src/i18n/locales/en/common.json index 40a897ceb3..9c4fb23bb7 100644 --- a/src/i18n/locales/en/common.json +++ b/src/i18n/locales/en/common.json @@ -85,7 +85,8 @@ "processExitedWithError": "Claude Code process exited with code {{exitCode}}. Error output: {{output}}", "stoppedWithReason": "Claude Code stopped with reason: {{reason}}", "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." }, "gemini": { "generate_stream": "Gemini generate context stream error: {{error}}",