Skip to content

rate_limit_event causes MessageParseError instead of being handled gracefully #603

@hernanvegas

Description

@hernanvegas

Bug

When the Claude Code CLI emits a rate_limit_event message (informational,
CLI handles retry internally), the Python SDK crashes with MessageParseError
instead of ignoring it.

Versions

  • claude-agent-sdk (Python): 0.1.39
  • @anthropic-ai/claude-agent-sdk (TypeScript): 0.2.50

Steps to reproduce

Run any query using the Python SDK. If the CLI encounters a temporary rate
limit (burst/minute limits), it emits a rate_limit_event to the stream.

Expected behavior

The event should be silently ignored, as the CLI already handles the wait/retry
internally. The TypeScript SDK (v0.2.50) does this correctly.

Actual behavior

MessageParseError: Unknown message type: rate_limit_event is raised,
terminating the query prematurely.

Root cause

In _internal/query.py, _read_messages() does not filter rate_limit_event
before passing messages to the stream. It then reaches message_parser.py which
falls into case _: raise MessageParseError(...).

Fix

Add a continue for rate_limit_event in query.py, similar to how
control_cancel_request is handled:

elif msg_type == "rate_limit_event":
    # CLI handles rate limiting internally — skip informational event
    continue

---

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions