Skip to content

Commit 3ab7a3d

Browse files
committed
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
1 parent 2571781 commit 3ab7a3d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/api/providers/claude-code.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,30 @@ export class ClaudeCodeHandler extends BaseProvider implements ApiHandler {
8282

8383
const error = this.attemptParse(errorMessage)
8484
if (!error) {
85+
// Check if this is a 5-hour rate limit error
86+
// These errors typically contain system prompts and are very long
87+
if (
88+
content.text.includes("5-hour") ||
89+
content.text.includes("5 hour") ||
90+
content.text.includes("rate limit") ||
91+
content.text.includes("quota")
92+
) {
93+
throw new Error(t("common:errors.claudeCode.rateLimitReached"))
94+
}
8595
throw new Error(content.text)
8696
}
8797

98+
// Check for 5-hour rate limit in parsed error
99+
if (
100+
error.error?.message &&
101+
(error.error.message.includes("5-hour") ||
102+
error.error.message.includes("5 hour") ||
103+
error.error.message.includes("rate limit") ||
104+
error.error.message.includes("quota"))
105+
) {
106+
throw new Error(t("common:errors.claudeCode.rateLimitReached"))
107+
}
108+
88109
if (error.error.message.includes("Invalid model name")) {
89110
throw new Error(
90111
content.text + `\n\n${t("common:errors.claudeCode.apiKeyModelPlanMismatch")}`,

src/i18n/locales/en/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585
"processExitedWithError": "Claude Code process exited with code {{exitCode}}. Error output: {{output}}",
8686
"stoppedWithReason": "Claude Code stopped with reason: {{reason}}",
8787
"apiKeyModelPlanMismatch": "API keys and subscription plans allow different models. Make sure the selected model is included in your plan.",
88-
"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}}"
88+
"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}}",
89+
"rateLimitReached": "5-hour usage limit reached. Please wait for the limit to reset before continuing."
8990
},
9091
"gemini": {
9192
"generate_stream": "Gemini generate context stream error: {{error}}",

0 commit comments

Comments
 (0)