Skip to content

MessageParseError on rate_limit_event message type terminates async generator #601

@robcalvillo

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.

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