How anthropics/claude-agent-sdk-demos works
1. What this repo is
- This is a monorepo of independent Claude Agent SDK demos, not one unified product.
- Each demo folder has its own runtime, UI, and integration style; they do not appear to share a common application layer beyond the SDK usage patterns and documentation.
2. Common architecture pattern across demos
- Most demos sit on the same boundary: a human-facing shell (CLI, React web app, or Electron app) talks to a Claude-powered orchestration layer, which may then call tools, hit external services, or read/write local state.
- The important architectural distinction is usually between:
- presentation layer: browser/desktop/terminal UI
- agent/orchestration layer: SDK session, prompts, tool routing, subagent coordination
- integration layer: email, filesystem, web search, document generation, database, or IMAP
- state layer: local session store, SQLite/db files, logs, or generated artifacts
3. Email Agent: the largest, most layered demo
- email-agent is the most complete system in the repo and is built as a local email assistant.
- It has four major parts:
- client/: React UI for inbox, email viewer, listeners panel, actions, and chat-style assistance
- server/: HTTP/WebSocket endpoints for emails, sync, listeners, and UI state
- database/: email persistence, search, sync, IMAP integration, and schema/migrations
- ccsdk/: orchestration code for actions, listeners, UI-state management, message queueing, and websocket handling
- The agent/custom_scripts/ tree contains the user-extensible business logic for actions, listeners, and UI states.
4. Email Agent data flow
- Email enters through IMAP sync into the database layer.
- The UI reads inbox/search results and listener status from the server endpoints.
- Agent-driven behaviors run through the ccsdk managers: listeners react to email events, actions execute workflows, and UI-state components feed the frontend.
- WebSocket connectivity is used for live assistant interaction and state updates, so the UI is not just polling static data; it is reacting to ongoing agent activity.
- The main external dependencies are the email server via IMAP and Anthropic/Claude for reasoning and tool use.
5. Email Agent’s extensibility model
- The repo treats actions, listeners, and UI states as first-class plugins.
- agent/custom_scripts/actions/ and listeners/ define concrete automation behaviors, while ui-states/ provides domain-specific dashboards.
- The agent/.claude/skills/ and template files show that this project is designed for generating new automations from a pattern, not just hardcoding one assistant.
- That makes the architecture more of a framework for email automations than a single-purpose app.
6. AskUserQuestion Previews: browser-mediated tool interaction
- ask-user-question-previews is a smaller web demo focused on one SDK capability: AskUserQuestion with HTML preview cards.
- It has a simple split between client/ and server.ts, with useAgentSocket.ts mediating the real-time bridge.
- The key flow is: Claude requests a clarification question → the browser renders preview options as styled HTML → the selected answer is sent back over WebSocket to continue the agent run.
- Architecturally, this demo highlights the tool-callback-to-UI roundtrip, not persistent storage or backend business logic.
7. Simple Chat App: minimal full conversation loop
- simple-chatapp is a compact React + server implementation of a chat experience backed by the SDK.
- client/ provides the chat window and chat list UI, while server/ contains the AI client, session management, and chat store.
- The important boundary here is the streaming chat session: user messages go from the browser to the server, the server streams model responses, and session state is preserved centrally.
- This demo is useful as the repo’s cleanest example of the end-to-end conversational loop.
8. Excel Demo: desktop app with Electron boundaries
- excel-demo is structurally different because it is an Electron application.
- It has the standard Electron split:
- src/main/: main process, menu, and preload wiring
- src/renderer/: React UI and chat/tool display components
- src/main/preload.ts: bridge between renderer and privileged main-process APIs
- The presence of agent/.claude/skills/xlsx/ and a Python recalc.py script suggests the agent can operate on spreadsheets through a tooling layer outside the UI, rather than directly in the renderer.
- The architecture centers on a desktop shell + local file/tool operations + AI assistance pattern.
9. Research Agent: multi-agent orchestration
- research-agent is a Python-based workflow for delegating research across specialized subagents.
- The core package contains:
- agent.py as the main coordinator
- prompts for lead_agent, researcher, data_analyst, and report_writer
- utilities for transcript capture, message handling, and subagent tracking
- The data flow is: user topic → lead agent decomposes the task → parallel research agents gather findings → synthesis/report-writing agents produce a final report.
- This repo emphasizes coordination, parallelism, and traceability of subagent work more than UI concerns.
10. Resume Generator: document-production pipeline
- resume-generator is a smaller, likely CLI-oriented demo focused on creating a one-page .docx resume from a person’s name.
- Its architecture is a pipeline from input name → web research (LinkedIn/GitHub/news) → content assembly → document generation.
- The docx Claude skill directory indicates the last stage is a formatted document output, not a persistent service or interactive UI.
11. Hello World and Hello World V2
- These are the smallest examples in the repo and serve as SDK onboarding/reference points.
- hello-world is a minimal single-file TypeScript example.
- hello-world-v2 demonstrates the newer session-oriented API patterns, especially separate send/stream behavior and multi-turn state handling.
- They define the baseline mental model used by the larger demos, but they are not the architectural center of the repo.
12. How to read the repo as a system
- Think of the repository as a set of reference architectures for Claude Agent SDK integration:
- browser chat apps
- email automation
- desktop file automation
- multi-agent research
- document generation
- The main architectural decisions vary by demo, but the recurring pattern is the same: UI or CLI input → agent orchestration → external tool/service integration → returned UI/state/output.
Main entry points: session.ts CCSDK core · agent.py Lead agent · server/server.ts Chat backend · server/server.ts API server
Components 26
Shared demos
Small onboarding and conversation examples
- Hello World · Minimal TypeScript SDK example
hello-world/hello-world.ts - Hello World v2 · Newer session-oriented SDK pattern
hello-world-v2/v2-examples.ts
AskUserQuestion
Browser-mediated clarification preview demo
- Browser UI · Renders question previews and answer controls
ask-user-question-previews/client/App.tsx - Socket bridge · Manages agent roundtrip over WebSocket
ask-user-question-previews/client/useAgentSocket.ts - Demo server · Hosts the agent loop and websocket endpoint
ask-user-question-previews/server.ts
Simple chat
Minimal web chat loop
- Chat UI · Conversation window and chat list
simple-chatapp/client/App.tsx - Chat backend · Session management and streamed responses
simple-chatapp/server/server.ts - Chat store · Persists conversation history and sessions
simple-chatapp/server/chat-store.ts
Email agent
Local email automation framework
- Email UI · Inbox, email viewer, listeners, and assistant chat
email-agent/client/App.tsx - API server · Exposes email, sync, listener, and UI-state endpoints
email-agent/server/server.ts - CCSDK core · Coordinates actions, listeners, UI state, queueing, and websocket flow
email-agent/ccsdk/session.ts - Actions · Agent-driven workflows and custom actions
email-agent/agent/custom_scripts/actions - Listeners · Email-triggered automations and classifiers
email-agent/agent/custom_scripts/listeners - UI states · Custom dashboards and stateful views for the frontend
email-agent/agent/custom_scripts/ui-states - Email DB · Schema, search, sync, and IMAP-backed storage
email-agent/database/email-db.ts - IMAP sync · Imports mail from the external email server
email-agent/database/imap-manager.ts
Excel demo
Electron spreadsheet assistant
- Main process · Privileged app shell and menu wiring
excel-demo/src/main/main.ts - Preload bridge · Exposes safe APIs from main to renderer
excel-demo/src/main/preload.ts - Renderer UI · Chat, tool-use, and todo displays
excel-demo/src/renderer/App.tsx - XLSX skill · Spreadsheet automation skill and recalculation script
excel-demo/agent/.claude/skills/xlsx/SKILL.md
Research agent
Multi-agent research workflow
- Lead agent · Decomposes topics and coordinates subagents
research-agent/research_agent/agent.py - Agent prompts · Specialized roles for lead, researcher, analyst, and writer
research-agent/research_agent/prompts/lead_agent.txt - Trace utils · Transcript capture and subagent tracking
research-agent/research_agent/utils/subagent_tracker.py
Resume generator
Document-generation pipeline
- Resume pipeline · Research, assemble, and emit a one-page resume
resume-generator/resume-generator.ts - DOCX skill · Formatting and output generation for Word documents
resume-generator/.claude/skills/docx/SKILL.md
Other components
- Claude SDK · Shared Claude Agent SDK dependency used by all demos
Connections 25
- Hello World → Claude SDK: uses · Minimal SDK onboarding example
- Hello World v2 → Claude SDK: uses · Session-oriented SDK example
- Browser UI → Socket bridge: events · UI delegates agent interactions to the socket hook
- Socket bridge → Demo server: ws · Bidirectional agent roundtrip
- Demo server → Claude SDK: uses · Runs the clarification/preview agent flow
- Chat UI → Chat backend: http/stream · Sends messages and receives streamed replies
- Chat backend → Chat store: persists · Stores sessions and conversation history
- Chat backend → Claude SDK: uses · Backed by Claude Agent SDK
- Email UI → API server: api/ws · Reads inbox state and live assistant updates
- API server → CCSDK core: delegates · Routes requests into orchestration layer
- CCSDK core → Claude SDK: uses · Claude reasoning and tool execution
- CCSDK core → Actions: runs · Executes user-defined workflows
- CCSDK core → Listeners: reacts · Processes email-triggered automations
- CCSDK core → UI states: drives · Feeds custom dashboard state
- API server → Email DB: reads/writes · Serves email and UI data from persistence
- Email DB → IMAP sync: syncs · Imports messages from external mail server
- Main process → Preload bridge: bridges · Exposes main-process capabilities to renderer
- Preload bridge → Renderer UI: api · Safe renderer access to privileged features
- Renderer UI → Claude SDK: uses · Chat-driven spreadsheet assistant
- Main process → XLSX skill: tools · Invokes spreadsheet automation outside the UI
- Lead agent → Agent prompts: orchestrates · Uses role-specific prompts for subagents
- Lead agent → Trace utils: tracks · Captures transcripts and subagent state
- Lead agent → Claude SDK: uses · Claude-powered research workflow
- Resume pipeline → DOCX skill: formats · Produces the final Word document
- Resume pipeline → Claude SDK: uses · Research and assembly pipeline