Claude Quickstarts Reference Implementations
repository·main·Indexed 12 days ago
https://github.com/anthropics/claude-quickstartsA collection of starter projects and reference implementations for integrating Claude's capabilities. Includes an Autonomous Coding Agent demo utilizing a two-agent pattern with the Claude Code CLI and Claude Agent SDK, a containerized Browser Automation demo using Playwright for DOM-aware web interaction, and best practices for computer use on macOS (v0.1.0).
What's inside Claude Quickstarts
- Claude Managed Agents are agents run by Anthropic that provide server-side sessions, sandboxed tools, and an event stream for your application to consume. This repository contains several complete, runnable quickstart projects that demonstrate how to pair Managed Agents with different product surfaces and UI frameworks.
Overview of Claude Financial Data Analyst features
mainThe Claude Financial Data Analyst is a Next.js application designed to analyze financial data through chat-based interaction.
Key Capabilities:
- Intelligent Analysis: Uses Claude 3 Haiku and Claude 3.5 Sonnet to process data.
- Multi-Format File Support:
- Text/Code files (
.txt,.md,.html,.py,.csv, etc.) - PDF documents (text-based PDFs; scanned documents are not supported)
- Images
- Text/Code files (
- Interactive Data Visualization: Automatically generates charts using Recharts based on analyzed data, including:
- Line Charts (trends/time series)
- Bar Charts (metric comparisons)
- Multi-Bar Charts
- Area Charts & Stacked Area Charts
- Pie Charts (distribution analysis)
Available Claude Quickstart Projects
mainThis repository contains several specialized quickstart implementations. Choose a project based on your target use case:
- Customer Support Agent: Demonstrates natural language understanding and generation with access to a knowledge base.
- Financial Data Analyst: Demonstrates interactive data visualization and financial data analysis via chat.
- Computer Use Demo: Provides an environment and tools for Claude to control a desktop computer (supports
computer_use_20251124tool version with zoom actions). - Computer Use Best Practices: A native-macOS reference implementation (run in a VM!) demonstrating reliable patterns like explicit tool definitions, image pruning, prompt caching, and trajectory recording.
- Browser Use Demo: A reference implementation for browser automation using a Playwright-backed browser tool to navigate, inspect DOM, and fill forms.
- Autonomous Coding Agent: Uses the Claude Agent SDK to demonstrate a two-agent pattern (initializer + coding agent) for building applications with git-persisted progress.
- Managed Agents: Chat SDK: Pairs Claude Managed Agents with Vercel's Chat SDK for browser-based chat, research analysis, and multi-platform support (Slack, Teams, etc.).
- Managed Agents with CopilotKit and AG-UI: Demonstrates bridging managed-agent sessions to the AG-UI protocol and rendering tool calls as interactive generative UI components.
- Managed Agents: Knowledge Wiki: Demonstrates distilling a document corpus into a versioned memory-store knowledge wiki for efficient, provenance-backed querying.
Project File Structure and Core Components
mainThis project integrates
assistant-uiwith Claude Managed Agents. The following files represent the core logic and architecture:- Configuration & Provisioning:
setup/agent-config.ts: Defines the model, system prompt, tools (e.g.,always_ask,show_chart), and environment.setup/create-agent.ts: Handles one-time provisioning of the agent and its environment.
- Managed Agents Logic:
lib/managed-agents/reducer.ts: Converts the event log into messages.lib/managed-agents/session-controller.ts: Manages per-session replay, live tail, sending/confirming/interrupting, and batched approvals.lib/managed-agents/session-list-adapter.ts: Provides theRemoteThreadListAdapterfor the sidebar.lib/managed-agents/runtime-provider.tsx: ProvidesuseRemoteThreadListRuntimeand per-sessionuseExternalStoreRuntime.lib/managed-agents/attachments.ts: Handles Composer attachments via Files API upload and sandbox mounting.
- API & UI:
app/api/sessions/**: Route handlers forlist,create,replay,tail,messages,confirm,files, andinterrupt.components/tool-uis/: Contains tool cards and the approval bar.app/assistant.tsx: The main composed view containing the Sidebar, thread, toolkit, and suggestions.
- Security & Setup:
lib/owned-session.ts: Implements the session ownership gate for routes.skill.md: Contains setup walkthroughs, debugging, and gotchas.
- Configuration & Provisioning:
Project Layout and Module Overview
mainThe
computer-use-best-practicesrepository is organized into the following key components:Core Logic (
computer_use/)__main__.py: CLI entrypoint, handlesbuild_tools()andbuild_system_prompt().loop.py: Manages the streaming sampling loop, retries, and advisor/compaction wiring.trajectory.py: Manages on-disk transcripts, images, and per-run scratch directories.tools/: Contains the tool implementations:base.py: DefinesToolABC andToolCollection.computer.py: Usespyautoguifor screen control (includes zoom and key aliasing).browser.py: Usesplaywrightwith headless Chromium.shell.py: Provides a sandboxed bash and python environment with output caps.editor.py: Allows viewing, creating, string replacement, and insertion within the scratch directory.
Configuration and UI
constants.py: Contains theConfigdataclass,cfginstance, prompts, and derived sets.config.example.toml: A template for overridingCU_CONFIG.dev_ui/: Contains developer tools like thetrajectory_viewer(Streamlit) andtool_panel(FastAPI).
Use hosted vs. explicit computer tools
mainBy default, this implementation defines tools (name, description, JSON schema) explicitly in
computer_use/tools/computer.py. This allows you to edit exactly what the model sees but lacks Anthropic's built-in safety classifier coverage.To enable Anthropic's computer-use-specific safety classifiers (including prompt-injection detection on screenshots), you must use the hosted tool by setting:
cfg.use_hosted_computer_tool = True- OR
CU_USE_HOSTED_COMPUTER_TOOL=true(via env var).
When using the hosted tool, the server supplies the tool's description and schema, while other tools like
browser,bash, andcomputer_batchremain as explicit tools.How the Two-Agent Pattern works
mainThe demo implements a long-running autonomous coding workflow using two distinct agent roles:
Initializer Agent (Session 1):
- Reads
app_spec.txt. - Creates
feature_list.jsoncontaining test cases (e.g., 200 cases). - Sets up the project structure and initializes a git repository.
- Reads
Coding Agent (Sessions 2+):
- Picks up from the state left by the Initializer.
- Implements features one by one.
- Marks features as passing in
feature_list.jsonas they are completed.
Session Management
- Persistence: Progress is saved via
feature_list.jsonand git commits. - Resuming: If you press
Ctrl+Cto pause, you can resume by running the same command again. The agent auto-continues between sessions with a 3-second delay. - Context: Each session runs with a fresh context window.
Mental model: How Chat SDK and Managed Agents relate
mainIn this architecture, the conversation ID used by the Chat SDK is identical to the Managed Agents session ID.
- Session Creation: The page creates a session via
POST /api/sessions(callingsessions.create()) and passes the returned ID touseChatas thethreadId. - Storage: The Managed Agents API acts as the entire conversation store.
- Sidebar lists sessions via
sessions.list({ agent_id }). - Replaying a chat uses
sessions.events.list()to turnuser.messageandagent.messageevents back into chat bubbles. - The first message of a conversation is used as the title via
sessions.update().
- Sidebar lists sessions via
- Data Persistence: The server is stateless regarding Chat SDK internals.
createMemoryState()insrc/bot.tshandles message dedup and locks, butpersistMessageHistory: falseensures the adapter doesn't cache message bodies, leaving the live transcript in the browser and the durable transcript in the Managed Agents session.
- Session Creation: The page creates a session via
Manage context with image pruning and prompt caching
mainTo manage the high token cost of screenshot-heavy trajectories, the project uses two primary mechanisms:
Prompt Caching
loop.pyappliescache_control: {"type": "ephemeral"}breakpoints to the system prompt and the final tool-result block of the most recent user turn. This allows subsequent calls to serve the prefix from cache, reducing latency and cost.Image Pruning Strategies
Because prompt caching requires a byte-identical prefix, naive pruning (like keeping only the last N images) causes cache misses every turn. The project provides three strategies via
cfg.image_prune_strategy:"interval"(Default): Keeps the image count stable forcfg.image_prune_intervalturns. This ensures the prefix remains identical, allowing the cache to hit consistently. This is recommended for long, visual tasks."none": Disables pruning. Best for short, screenshot-light tasks where the cost of re-processing a few extra images is lower than the cost of a cache invalidation."simple": Keeps the last N images. This is "cache-hostile" because the prefix changes every turn.
Pruning vs. Autocompaction (Summarization)
- Summarization (
enable_autocompaction): A server-side event that condenses the conversation into a summary. It is more expensive (extra API turn) and causes a cold cache, but preserves more textual information. - Pruning: Faster and cheaper in the short term. It is most effective when it prevents the conversation from hitting the
autocompaction_trigger_tokensthreshold.
How assistant-ui and Claude Managed Agents work together
mainThis project pairs a frontend UI framework with a backend agent runtime:
- assistant-ui (Frontend): Provides the UI primitives including the composer, thread, sidebar, tool cards, and the approval gate. It expects a message array and callbacks to drive the interface.
- Claude Managed Agents (Backend): Provides a durable session that holds transcripts, runs code (like
bashwith pandas) in a sandbox, and streams events back to the UI.
The Integration Layer:
lib/managed-agents/reducer.tsis the core logic. It is a pure function that transforms a session's event log into assistant-ui'sThreadMessageLike[]model. This ensures that live streams and historical replays render identically.- State Management: There is no separate database; the Managed Agents session itself acts as the source of truth for all conversation history and state.
Security Model and Command Allowlist
mainThe demo employs a defense-in-depth security model to restrict agent actions. Commands are validated against an allowlist in
security.py.Security Layers
- OS-level Sandbox: Bash commands run in an isolated environment.
- Filesystem Restrictions: File operations are restricted strictly to the designated project directory.
- Bash Allowlist: Only specific command categories are permitted:
- File inspection:
ls,cat,head,tail,wc,grep - Node.js:
npm,node - Version control:
git - Process management:
ps,lsof,sleep,pkill(for dev processes only)
- File inspection:
Any command not in this allowlist is blocked by the security hook. To add new permitted commands, modify the
ALLOWED_COMMANDSlist insecurity.py.How the Knowledge Wiki pipeline works
mainThe Knowledge Wiki pattern avoids the 'reading tax' of re-reading a document corpus for every agent query by consolidating a corpus into a single, structured memory store once.
The Pipeline Steps
- Assemble Corpus: Gather documents (data rooms, discovery sets, etc.).
- Normalize: Convert all file types (PDF, Word, etc.) to plain text with a
[SOURCE: …]header for provenance. - Parallel Extraction: Split the corpus into batches. Run concurrent agent sessions that write structured notes into a shared memory store (the wiki). Each source document should have its own single-writer path to prevent overwrites.
- Resolve Open Questions: A cross-reading pass to close gaps left by extraction. Mark missing info as
confirmed-unresolvableinstead of guessing. - Consolidate (Dreaming): A server-side 'sleep-time' compute pass that reads transcripts and the store to write a new, reorganized store with deduplicated entities, an index, and repaired links. This step uses the
POST /v1/dreamsendpoint. - Query: Attach the consolidated store read-only to fresh agent sessions. Require provenance for every fact and script specific 'miss' behavior (e.g., naming the missing document).
- Operate: Periodically run 'dreaming' over real usage transcripts to reorganize the wiki around actual user queries.
- Evaluate: Grade outputs against a rubric to tune extraction rules and prompts.