Skip to content

fix: Handle rate_limit_event message to avoid MessageParseError#605

Open
liangzhang-keepmoving wants to merge 1 commit intoanthropics:mainfrom
liangzhang-keepmoving:fix-rate-limit-event
Open

fix: Handle rate_limit_event message to avoid MessageParseError#605
liangzhang-keepmoving wants to merge 1 commit intoanthropics:mainfrom
liangzhang-keepmoving:fix-rate-limit-event

Conversation

@liangzhang-keepmoving
Copy link

Summary

This PR fixes the issue where the SDK would crash with MessageParseError: Unknown message type: rate_limit_event when the Claude Code CLI emits a rate_limit_event message.

Root Cause

The CLI emits a rate_limit_event message at session start on every run, but the SDK's _read_messages() method in query.py was passing all messages to the stream, including informational events that shouldn't be parsed as SDK messages.

Fix

Added a continue statement for rate_limit_event messages in _read_messages(), similar to how control_cancel_request is handled. This skips the informational event and prevents it from reaching the message parser.

Changes

  • Modified src/claude_agent_sdk/_internal/query.py to add a case for rate_limit_event messages
  • The fix is minimal and focused, only adding the necessary code to handle this specific message type

Testing

The fix has been tested locally and resolves the issue where the SDK would crash with MessageParseError when the CLI emits a rate_limit_event message.

This change ensures that the SDK can properly handle the rate_limit_event message type, which is emitted by the CLI on every session start, without crashing.

Fixes #603 and #601

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rate_limit_event causes MessageParseError instead of being handled gracefully

1 participant