Don is an intelligent coding agent powered by Claude (Anthropic) that enables developers to interact with their codebase through natural language. Don can read, write, edit, and manage files seamlessly, making it an invaluable assistant for code generation, refactoring, and project management tasks.
The src directory contains the core implementation of Don's conversational intelligence and file system integration capabilities.
The core agent implementation that manages the conversation loop and tool execution.
Key Features:
- Interactive CLI interface for chatting with the AI agent (named "Don")
- Conversation management and message history tracking
- Integration with Anthropic Claude API (using
claude-haiku-4-5model) - Tool execution workflow: detects tool calls from Claude and executes them
- Graceful exit handling
Main Classes:
Agent: Handles the conversation loop, user input, and API interactions
Key Methods:
run(): Main conversation loop that reads user input and manages responsesgetMessage(): Reads user input from stdinrunInference(): Sends conversation messages to Claude API with available tools
Defines all available tools that Claude can use, with validation and execution logic.
Key Features:
- Zod schema-based tool definition and validation
- Converts Zod schemas to JSON schema for Claude API compatibility
- Tool registry for dynamic lookup and execution
- Error handling for tool execution
Exported Items:
toolsDefinitions: Array of tool definitions for Claude APIexecuteTool(): Function to execute tools by name with input validation
Available Tools:
-
read_file
- Description: Read the contents of a file
- Input:
path(string) - relative file path - Output: File contents as string
-
list_files
- Description: List files and directories at a given path
- Input:
path(string, optional) - directory path (defaults to current directory) - Output: Newline-separated list of file paths
-
edit_file
- Description: Edit or create files by replacing text
- Input:
path(string) - file pathold_str(string, optional) - text to find and replacenew_str(string) - replacement text
- Output: Success/error message
Tool Type Definition:
type Tool<T extends z.ZodObject<any>> = {
definition: Anthropic.Tool;
schema: T;
handler: (input: z.infer<T>) => Promise<string>;
};Low-level file system utilities and command execution.
Key Features:
- Promise-based file operations
- Directory traversal (excluding node_modules)
- Command execution via shell
- Smart file creation with directory creation
- Text replacement with validation
Tools Class Methods:
readFile(path): Read file contentswriteNewFile(filePath, content): Write/create a fileeditFile(path, old_str, new_str): Edit existing files or create new oneslistFiles(raw): List all files and directories recursivelyrunCommand(command): Execute shell commands
Helper Functions:
walkDir(dir): Recursively traverse directory structure, returning both files and directories
┌─────────────────────────────────────────┐
│ index.ts (Agent Class) │
│ - User input handling │
│ - Conversation management │
│ - Claude API integration │
└────────────────┬────────────────────────┘
│
↓
┌─────────────────────────────────────────┐
│ definitions.ts (Tool Execution Layer) │
│ - Tool validation (Zod schemas) │
│ - Tool registry & execution │
│ - Schema conversion (Zod → JSON) │
└────────────────┬────────────────────────┘
│
↓
┌─────────────────────────────────────────┐
│ tools.ts (File System) │
│ - Low-level file operations │
│ - Directory traversal │
│ - Command execution │
└─────────────────────────────────────────┘
npm run devThis starts an interactive chat session. You can:
- Ask questions and have conversations
- Request file operations (read, write, edit, list)
- Type "exit" to quit the program
You: List all files in the src directory
Don ✨: <executes list_files tool>
Don: Here are the files in the src directory...
You: Read the content of index.ts
Don ✨: <executes read_file tool>
Don: The index.ts file contains the following...
You: Create a new function that validates email addresses
Don ✨: <executes edit_file tool>
Don: I've created a new validation utility with email verification...
You: Refactor this code for better performance
Don ✨: <reads file, analyzes, and applies optimizations>
Don: I've refactored your code to improve performance by...
@anthropic-ai/sdk: Claude API clientchalk: Terminal color outputdotenv: Environment variable loadingzod: Schema validationzod-to-json-schema: Convert Zod schemas to JSON schemas- Node.js built-in modules:
readline,fs/promises,child_process,path
Required for API access:
ANTHROPIC_API_KEY: Your Anthropic API key
- User input → Claude processes with tool definitions
- Claude returns tool use request
executeTool()looks up tool in registry- Zod schema validates input data
- Tool handler executes file system operation
- Result returned to Claude for next inference
- Invalid tool names: Returns error result
- Validation failures: Zod catches schema mismatches
- File operation errors: Caught and returned as error responses
- User input EOF: Gracefully closes program
- Uses
claude-haiku-4-5model for fast, efficient responses - Maximum tokens set to 8024
- Conversation history is maintained throughout the session
- File operations are synchronous within async handlers
- Excludes
node_modulesfrom directory listings
Don is perfect for:
- Code Generation: Generate boilerplate, utilities, and scaffolding
- Code Review: Ask Don to review and suggest improvements
- Refactoring: Improve code structure and performance through natural language requests
- Documentation: Generate or update project documentation
- Bug Fixes: Describe issues and let Don help locate and fix them
- Project Navigation: Quickly understand your codebase structure
✨ Natural Language Interaction - Communicate with your codebase using plain English 📁 File Management - Read, create, edit, and browse files seamlessly 🤖 AI-Powered - Leverages Claude's advanced coding knowledge ⚡ Fast & Efficient - Quick responses optimized for productivity 💾 Context Aware - Maintains conversation history for coherent interactions