This directory contains examples demonstrating the advanced features of the Claude Code SDK.
Demonstrates token streaming patterns and workarounds:
- SDK token stream analysis (shows current chunked delivery behavior)
- Response collection pattern for processing complete responses
- Character-by-character typewriter effect (working visual streaming)
- Stream metrics and timing analysis
Important: Claude Code CLI currently delivers responses in chunks rather than true token-by-token streaming. Example 3 shows how to create actual visual streaming effects by controlling display timing after collection.
Run:
node token-streaming.jsShows advanced error handling patterns:
- Typed error detection
- Retry logic for rate limits
- Graceful degradation
- Error logging strategies
- Custom error handlers
Run:
node error-handling.jsExplores various retry patterns:
- Exponential backoff
- Linear retry
- Fibonacci sequence retry
- Circuit breaker pattern
- Retry with telemetry
Run:
node retry-strategies.jsInteractive CLI chat with visual typewriter streaming:
- Real-time character-by-character display of responses
- Conversation history management
- Adjustable streaming speed (fast/normal/slow)
- Model switching and debug mode
- Session commands and help system
Features the only working visual streaming pattern - responses appear with realistic typewriter effect!
Run:
node interactive-streaming.jsMake sure you have the SDK installed:
npm install @instantlyeasy/claude-code-sdk-tsAnd Claude Code CLI configured:
claude --helpThese examples demonstrate production-ready patterns:
-
Error Handling: Always wrap your queries in try-catch blocks and handle specific error types appropriately.
-
Retry Logic: Use exponential backoff for transient failures and respect rate limits.
-
Streaming: Use token streaming for better UX in interactive applications.
-
Telemetry: Track metrics to understand your application's behavior and performance.