ghuntley /how-to-build-a-coding-agent

A workshop that teaches you how to build your own coding agent. Similar to Roo code, Cline, Amp, Cursor, Windsurf or OpenCode.

★ 5,923⑂ 678👁 32⑃ 18● 2▤ 0
GoCreated 2025-07-24ghuntley.com/agent/
+1
日增长
5,923
stars
678
forks
32
watchers
18
prs
2
issues
0
releases

README

🧠 Build Your Own Coding Agent via a Step-by-Step Workshop

Welcome! 👋 This workshop will guide you through building your own AI-powered coding assistant — starting from a basic chatbot, and adding powerful tools like file reading, shell command execution, and code searching.

You don’t need to be an AI expert. Just follow along and build step-by-step!

🌐 Want a detailed overview? Check out the blog post: ghuntley.com/agent

---

 🎯 What You'll Learn

By the end of this workshop, you’ll understand how to:

- ✅ Connect to the Anthropic Claude API
- ✅ Build a simple AI chatbot
- ✅ Add tools like reading files, editing code, and running commands
- ✅ Handle tool requests and errors
- ✅ Build an agent that gets smarter with each step

---

 🛠️ What We're Building

You’ll build 6 versions of a coding assistant. 

Each version adds more features:

1. Basic Chat — talk to Claude
2. File Reader — read code files
3. File Explorer — list files in folders
4. Command Runner — run shell commands
5. File Editor — modify files
6. Code Search — search your codebase with patterns

mermaid
graph LR
    subgraph "Application Progression"
        A[chat.goBasic Chat] -- B[read.go+ File Reading]
        B -- C[list_files.go+ Directory Listing]
        C -- D[bash_tool.go+ Shell Commands]
        D -- E[edit_tool.go+ File Editing]
        E -- F[code_search_tool.go+ Code Search]
    end
    
    subgraph "Tool Capabilities"
        G[No Tools] -- H[read_file]
        H -- I[read_filelist_files]
        I -- J[read_filelist_filesbash]
        J -- K[read_filelist_filesbashedit_file]
        K -- L[read_filelist_filesbashcode_search]
    end
    
    A -.- G
    B -.- H
    C -.- I
    D -.- J
    E -.- K
    F -.- L


At the end, you’ll end up with a powerful local developer assistant!



---

 🧱 How It Works (Architecture)

Each agent works like this:

1. Waits for your input
2. Sends it to Claude
3. Claude may respond directly or ask to use a tool
4. The agent runs the tool (e.g., read a file)
5. Sends the result back to Claude
6. Claude gives you the final answer

We call this the event loop — it's like the agent's heartbeat.

mermaid
graph TB
    subgraph "Agent Architecture"
        A[Agent] -- B[Anthropic Client]
        A -- C[Tool Registry]
        A -- D[getUserMessage Function]
        A -- E[Verbose Logging]
    end
    
    subgraph "Shared Event Loop"
        F[Start Chat Session] -- G[Get User Input]
        G -- H{Empty Input?}
        H --|Yes| G
        H --|No| I[Add to Conversation]
        I -- J[runInference]
        J -- K[Claude 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 -- J
        M -- G
    end
    
    subgraph "Tool Execution Loop"
        N -- Q[Find Tool by Name]
        Q -- R[Execute Tool Function]
        R -- S[Capture Result/Error]
        S -- T[Add to Tool Results]
        T -- U{More Tools?}
 

Top issues

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON