A minimal AI coding agent built with Claude. ~200 lines of Python running in a loop with LLM tokens.
Inspired by Geoffrey Huntley's workshop.
- Create a virtual environment and install dependencies:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install anthropic- Install ripgrep (for code search):
brew install ripgrep # macOS
apt install ripgrep # Ubuntu/Debian- Set your API key:
export ANTHROPIC_API_KEY=your-api-key-herepython main.pyThen chat with Claude:
You: what files are in this directory?
You: search the code for "ToolDefinition"
You: read agent.py and explain how the loop works
You: create a fizzbuzz.py that prints fizzbuzz from 1 to 100
You: run python fizzbuzz.py
You: fix the bug in fizzbuzz.py
Use Ctrl+C to quit.
| Tool | Description |
|---|---|
list_files |
List files and directories at a given path |
read_file |
Read the contents of a file |
edit_file |
Edit a file by replacing text, or create new files |
bash |
Execute shell commands (dangerous commands blocked) |
code_search |
Search code with ripgrep |
edit_file β Uses string replacement. Pass old_str="" to create a new file.
bash β Blocks dangerous patterns: rm -rf, sudo, > /dev, mkfs, dd if=, :{(). Times out after 30 seconds.
code_search β Requires ripgrep (rg). Returns matching lines with file paths and line numbers.
βββ main.py # Entry point, sets up and runs the agent
βββ agent.py # Agent loop and tool execution
βββ tools.py # Tool definitions
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Agent Loop β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 1. Get user input β
β 2. Send conversation to Claude β
β 3. If Claude returns text β print it β
β 4. If Claude returns tool_use β execute tool β
β 5. Add tool result to conversation β
β 6. Go to step 2 (until no more tool calls) β
β 7. Go to step 1 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ