Skip to content

drumwell/code-editing-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Code Editing Agent

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.

Setup

  1. Create a virtual environment and install dependencies:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install anthropic
  1. Install ripgrep (for code search):
brew install ripgrep      # macOS
apt install ripgrep       # Ubuntu/Debian
  1. Set your API key:
export ANTHROPIC_API_KEY=your-api-key-here

Usage

python main.py

Then 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.

Tools

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

Tool Details

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.

Project Structure

β”œβ”€β”€ main.py      # Entry point, sets up and runs the agent
β”œβ”€β”€ agent.py     # Agent loop and tool execution
└── tools.py     # Tool definitions

How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    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                                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages