[BUG] claude-agent-sdk: MessageParseError on rate_limit_event message type

Resolved 💬 8 comments Opened Feb 18, 2026 by 42tahara Closed Mar 22, 2026

Bug Description

claude-agent-sdk's message_parser.py does not handle the rate_limit_event message type emitted by Claude Code CLI. This causes MessageParseError("Unknown message type: rate_limit_event") to be raised, which terminates the entire message stream.

Reproduction

  1. Use claude-agent-sdk (tested on v0.1.37) to query Claude Code CLI
  2. When rate limiting occurs, the CLI emits a message with "type": "rate_limit_event"
  3. parse_message() in _internal/message_parser.py raises MessageParseError at the case _: branch (line 179-180)
  4. The async generator in _internal/client.py (line 141) propagates the exception, terminating the stream

Root Cause

In _internal/message_parser.py, the parse_message function handles these types: user, assistant, system, result, stream_event. The rate_limit_event type is not included.

Notably, types.py already defines "rate_limit" as a known SystemMessageSubtype (line 635), suggesting awareness of this message category, but the parser lacks a corresponding case.

Expected Behavior

rate_limit_event messages should be parsed into a typed message object (e.g., SystemMessage) or at minimum be silently skipped rather than raising an exception that breaks the stream.

Workaround

Monkey-patching parse_message to catch the exception and return None:

import claude_agent_sdk._internal.client as _sdk_client
import claude_agent_sdk._internal.message_parser as _sdk_parser

_original_parse_message = _sdk_parser.parse_message

def _safe_parse_message(data):
    try:
        return _original_parse_message(data)
    except Exception:
        return None

_sdk_parser.parse_message = _safe_parse_message
_sdk_client.parse_message = _safe_parse_message

Environment

  • claude-agent-sdk: 0.1.37
  • claude-code CLI: latest (as of 2026-02-18)
  • OS: macOS

View original on GitHub ↗

This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗