A step-by-step workshop for building an AI-powered coding assistant using TypeScript and the Anthropic Claude API.
By the end of this workshop, you'll understand how to:
- Connect to the Anthropic Claude API
- Build a simple AI chatbot with conversation history
- Add tools like reading files and listing directories
- Handle tool requests and errors gracefully
- Build a modular agent framework that's easy to extend
You'll build 7 versions of a coding assistant, each adding more capabilities:
- Basic Chat β talk to Claude
- File Reader β read code files
- File Explorer β list files in folders
- Modular Framework β clean, extensible architecture
- Refined Toolkit β powerful tools like bash, edit, and grep
- Streaming Responses β real-time text and tool visibility
- Extended Thinking β see Claude's reasoning process in real-time
graph LR
subgraph "Application Progression"
A["Chapter 1<br/>Basic Chat"] --> B["Chapter 2<br/>+ File Reading"]
B --> C["Chapter 3<br/>+ Directory Listing"]
C --> D["Chapter 4<br/>Modular Framework"]
D --> E["Chapter 5<br/>Refined Toolkit"]
E --> F["Chapter 6<br/>Streaming"]
F --> G["Chapter 7<br/>Extended Thinking"]
end
subgraph "Tool Capabilities"
H["No Tools"] --> I["read_file"]
I --> J["read_file<br/>list_files"]
J --> K["read_file<br/>list_files<br/>(modular)"]
K --> L["bash, edit_file,<br/>grep (ripgrep)"]
L --> M["+ streaming<br/>+ tool visibility"]
M --> N["+ thinking blocks<br/>+ reasoning visibility"]
end
A -.-> H
B -.-> I
C -.-> J
D -.-> K
E -.-> L
F -.-> M
G -.-> N
Each agent works like this:
- Waits for your input
- Sends it to Claude
- Claude may respond directly or ask to use a tool
- The agent runs the tool (e.g., read a file)
- Sends the result back to Claude
- Claude gives you the final answer
This is the agentic loop β it's what makes the assistant "smart."
graph TB
subgraph "Agent Architecture"
A["Agent"] --> B["Anthropic Client"]
A --> C["Tool Registry"]
A --> D["readline Interface"]
A --> E["Verbose Logging"]
end
subgraph "Event Loop"
F["Start Chat"] --> G["Get User Input"]
G --> H{"Empty?"}
H -->|Yes| G
H -->|No| I["Add to Conversation"]
I --> J["Send to Claude"]
J --> K["Get Response"]
K --> L{"Tool Use?"}
L -->|No| M["Display Text"]
L -->|Yes| N["Execute Tools"]
N --> O["Collect Results"]
O --> P["Send Results to Claude"]
P --> K
M --> G
end
- Bun runtime (or Node.js 18+)
- An Anthropic API Key
# Clone and install
bun install
# Add your API key
export ANTHROPIC_API_KEY="your-api-key-here"A simple chatbot that talks to Claude with conversation history.
bun run chapter1/index.tsTry it:
- "Hello!"
- "What's 2+2?"
- "What did I just ask you?" (tests memory)
What you'll learn:
- Anthropic SDK basics
- Conversation history management
- The message loop pattern
Now Claude can read files from your computer.
bun run chapter2/read_file.tsTry it:
- "Read package.json"
- "What dependencies does this project use?"
What you'll learn:
- Tool definition with Zod schemas
- The tool use loop
- Handling tool results
Adds directory listing so Claude can explore your codebase.
bun run chapter3/list_files.tsTry it:
- "List all files in this directory"
- "What's in the chapter3 folder?"
What you'll learn:
- Adding multiple tools
- Tool dispatch by name
- Error handling patterns
A modular architecture with separation of concerns.
bun run chapter4/index.tsTry it:
- "What TypeScript files are in this project?"
- "Show me the agent.ts file"
What you'll learn:
- Modular code organization
- Shared type definitions
- Clean entry point pattern
- How to add new tools easily
Expands the agent's capabilities with powerful search, edit, and shell tools.
bun run chapter5/index.tsTry it:
- "Find all occurrences of 'Claude' in this project"
- "Fix the typo in Chapter 5 README"
- "Run ls -la using the bash tool"
What you'll learn:
- Implementing advanced tools (bash, edit_file)
- Integrating high-performance search with Ripgrep
- Externalizing tool descriptions for better prompt management
- Automatic dependency management (downloading Ripgrep binary)
Enhances the user experience with real-time streaming output and tool visibility.
bun run 6-streaming-response/index.tsTry it:
- "What files are in this project?" (watch text stream in real-time)
- "Read package.json and summarize it" (see tool calls as they happen)
What you'll learn:
- Using the Anthropic streaming API (
client.messages.stream()) - Handling streaming events (
text,streamEvent,contentBlock) - Showing tool calls before execution with
content_block_start - Building responsive CLI output with
process.stdout.write()
Makes Claude's reasoning process visible with thinking blocks and real-time streaming.
bun run 7-thinking-tokens/index.tsTry it:
- "Find all TypeScript files with potential bugs" (watch Claude reason through the problem)
- "Create a new tool for counting code lines" (see planning and decision-making)
- Use
--verbosefor debug logging
What you'll learn:
- Extended thinking API with
thinking: { type: "enabled", budget_tokens: 10000 } - Handling thinking stream events (
thinking_delta) - Visual indicators for thinking blocks (π with dimmed cyan text)
- Simple state management with boolean flags
- Reusing existing console utilities for new features
| Chapter | Focus | Tools Available |
|---|---|---|
| 1 | API basics, conversation history | None |
| 2 | Tool definition, tool use loop | read_file |
| 3 | Multiple tools, error handling | read_file, list_files |
| 4 | Modular architecture, extensibility | read_file, list_files |
| 5 | Advanced toolkit & infrastructure | read_file, list_files, bash, edit_file, grep |
| 6 | Streaming responses, tool visibility | Same as Chapter 5 + streaming |
| 7 | Extended thinking, reasoning visibility | Same as Chapter 6 + thinking blocks |
code-agent-ts/
βββ chapter1/
β βββ index.ts # Basic chat agent
βββ chapter2/
β βββ read_file.ts # Agent + read_file tool
βββ chapter3/
β βββ read_file.ts # Agent + read_file tool
β βββ list_files.ts # Agent + list_files tool
βββ chapter4/
β βββ index.ts # Entry point
β βββ agent.ts # Core Agent class
β βββ types.ts # Shared interfaces
β βββ tools/
β βββ read_file.ts # File reading tool
β βββ list_files.ts # Directory listing tool
βββ chapter5/
β βββ index.ts # Entry point
β βββ agent.ts # Core Agent class (inherited)
β βββ ripgrep/ # Ripgrep downloader & utility
β βββ tools/
β βββ bash_tool.ts # Shell command tool
β βββ edit_tool.ts # File editing tool
β βββ grep.ts # Advanced search tool
β βββ tool_description/ # Externalized descriptions
βββ 6-streaming-response/
β βββ index.ts # Entry point
β βββ agent.ts # Agent with streaming support
β βββ types.ts # Shared interfaces
β βββ ripgrep/ # Ripgrep downloader
β βββ tools/ # Same tools as Chapter 5
βββ 7-thinking-tokens/
β βββ index.ts # Entry point
β βββ agent.ts # Agent with thinking support
β βββ types.ts # Shared interfaces
β βββ tools/ # Same tools as Chapter 6
βββ logger.ts # Pino structured logging
βββ console.ts # Terminal output utilities
βββ README.md
| Technology | Purpose |
|---|---|
| Anthropic SDK | Claude API integration |
| Zod | Schema validation & JSON Schema generation |
| Commander | CLI argument parsing |
| Pino | Structured logging |
| picocolors | Terminal colors |
| boxen | Terminal boxes |
All chapters support --verbose for debug logging:
bun run 4-agent-tool-orchestration/index.ts --verboseThis shows:
- When messages are sent to Claude
- Tool executions and results
- Conversation history length
- API call timing
Once you complete Chapter 4, adding new tools is simple:
- Create the file:
4-agent-tool-orchestration/tools/my_tool.ts - Define the schema and executor
- Register in
index.ts
See Chapter 4 README for detailed instructions.
API key not working?
- Make sure it's exported:
echo $ANTHROPIC_API_KEY - Check your quota on Anthropic's console
Bun errors?
- Update Bun:
bun upgrade - Or use Node.js:
npx tsx 4-agent-tool-orchestration/index.ts
Tool errors?
- Use
--verbosefor detailed logs - Check file paths and permissions
After completing the workshop, try extending with:
- System prompts: Give Claude context about the project
- Extended thinking: Show Claude's reasoning process
- Parallel tool execution: Run multiple tools concurrently
- Tool cancellation: Allow users to abort mid-stream
- Context management: Handle long conversations efficiently