Skip to content

MessageParseError on rate_limit_event message type terminates async generator #601

Closed

Description

@robcalvillo

Description

The CLI emits a rate_limit_event message at session start on every run. The SDK's parse_message function does not handle this message type, hitting the catch-all case in its match statement and raising MessageParseError. Since this exception occurs inside the async generator, it terminates the stream and the consumer never receives the ResultMessage with output, cost data, or session ID.

This is not triggered by actually hitting a rate limit. It's an informational status message emitted on 100% of sessions.

Payload

{
  "rate_limit_info": {
    "isUsingOverage": false,
    "overageDisabledReason": "org_level_disabled",
    "overageStatus": "rejected"
  },
  "type": "rate_limit_event",
  "uuid": "edf7a929-4317-4642-85e2-3bd9ee2b97b9"
}

Repro

from claude_agent_sdk import query, ClaudeAgentOptions

async for message in query(
    prompt="What is 2 + 2?",
    options=ClaudeAgentOptions(allowed_tools=["Bash"]),
):
    print(message)

Raises MessageParseError before ResultMessage is received.

Environment

  • claude-agent-sdk==0.1.39
  • Python 3.14.3
  • macOS (Darwin)
  • Claude Code CLI in PATH, authenticated via OAuth token

Suggested fix

Handle rate_limit_event in parse_message by either returning a SystemMessage with the payload or silently skipping it. The data is informational and should not terminate the stream.

Activity

  1. NickFall commented on Feb 21, 2026

    @NickFall

    Confirmed. This seems to have started happening in the past few hours. Initially I thought it was multiple calls hitting the API (originating from Task calls spawning subagents) but this doesn't seem to be the case, as robcalvillo describes. I still haven't been able to find a workaround.

    I thought it was the past few hours but there are Issues raised on the Claude Code repo describing this that are at least a couple of days old. Oddly enough I was able to use it fine earlier today, but then it abruptly stopped.

    anthropics/claude-code#26498
    anthropics/claude-code#26669

  2. igor-gorohovsky-sembly commented on Feb 22, 2026

    @igor-gorohovsky-sembly

    I encountered the same problem. I can't run my agent, it always fails with MessageParseError.

  3. qing-ant commented on Mar 24, 2026

    @qing-ant
    Contributor

    This was fixed in commit 2d5c3cb (PR #648 — "feat: add typed RateLimitEvent message"), which shipped in v0.1.49. The parser now handles rate_limit_event messages and returns a typed RateLimitEvent instead of raising MessageParseError. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions