claude-agent-sdk: SDKMessage type resolves to any due to missing type declarations

Resolved 💬 3 comments Opened Feb 23, 2026 by AlbertSanIza Closed Feb 27, 2026

Bug

The SDKMessage type exported from @anthropic-ai/claude-agent-sdk resolves to any in TypeScript projects that use skipLibCheck: true (which is the common default).

Root Cause

In sdk.d.ts (line 1533), SDKMessage is defined as a union that includes SDKRateLimitEvent and SDKPromptSuggestionMessage:

export declare type SDKMessage = SDKAssistantMessage | SDKUserMessage | ... | SDKRateLimitEvent | SDKPromptSuggestionMessage;

However, neither SDKRateLimitEvent nor SDKPromptSuggestionMessage are declared anywhere in sdk.d.ts. This means:

  • With skipLibCheck: false → TypeScript reports TS2304: Cannot find name 'SDKRateLimitEvent' and TS2304: Cannot find name 'SDKPromptSuggestionMessage'
  • With skipLibCheck: true (default in most projects) → TypeScript silently degrades the entire SDKMessage union to any

This cascades through Query (which extends AsyncGenerator<SDKMessage, void>), so any for await (const message of messages) loop has message typed as any, losing all type safety.

Reproduction

import { query, type SDKMessage } from '@anthropic-ai/claude-agent-sdk'

// This should error but doesn't — SDKMessage is any
const check: number = {} as SDKMessage

async function test() {
    const messages = query({ prompt: 'hi', options: { model: 'sonnet' } })
    for await (const message of messages) {
        // message is any — no autocomplete, no type narrowing
        message.nonExistentProperty // no error
    }
}

Additional broken declarations

Running tsc --skipLibCheck false also reveals:

  • Missing @modelcontextprotocol/sdk/types.js and @modelcontextprotocol/sdk/server/mcp.js imports (lines 4-6, 9)
  • SDKStreamlinedTextMessage and SDKStreamlinedToolUseSummaryMessage not exported from coreTypes (line 1895)

Expected Fix

Add the missing type declarations for SDKRateLimitEvent and SDKPromptSuggestionMessage to sdk.d.ts.

Environment

  • @anthropic-ai/claude-agent-sdk: installed via Claude Code
  • TypeScript with skipLibCheck: true, moduleResolution: "bundler"
  • Runtime: Bun

View original on GitHub ↗

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