This repository contains demo code for the presentation "How Does a Coding Agent Work?" - a hands-on exploration of the core mechanics behind AI coding agents.
The code is presented together with the Coding Agent Explorer, my open-source .NET tool that shows what a coding agent such as Claude Code sends to the model: every API request, tool call and token count, live in a dashboard. Read more in the blog post Introducing the Coding Agent Explorer (.NET).
Coding agents are increasingly used to automate software tasks, yet how they actually work is often treated as a black box. This talk breaks a coding agent down into its core mechanics: how it is structured, how it communicates with a language model, and how a text-only model can read and modify real source code.
We cover:
- What a coding agent is, mechanically
- How agents communicate with language models
- How tools and MCP calls are executed
- How a text-only model works with source code
- How to build a basic coding agent in C#
This repository contains two implementations of the same coding agent:
The feature-rich version with Spectre.Console UI, showing:
- Formatted request/response tables
- Visual tool call tracking
- Rich console output for debugging
The bare-bones version stripped down to ~210 lines of code, demonstrating:
- How compact a functional coding agent can be
- Core agentic loop pattern
- Essential tool execution without visual flourishes
Both versions implement the exact same functionality:
- Read, write, and list files in a sandboxed folder
- Maintain conversation context with Claude
- Execute tool calls in a loop until completion
- Path security to prevent escaping the working directory
- .NET 10.0 SDK
- Anthropic API key
-
Clone the repository
git clone <repository-url> cd MyCodingAgent.NET
-
Configure API Key
cd MyCodingAgent # or MyCodingAgent-Minimalistic dotnet user-secrets init dotnet user-secrets set "Anthropic:ApiKey" "your-api-key-here"
-
Run
dotnet run
Example prompts to test the agent:
Create a simple fizz buzz application in C#, with program.cs and project file. Do use .NET 10.
Create a simple calculator class with add, subtract, multiply, and divide methods.
Read the fizzbuzz program and add comments explaining how it works.
At its core, a coding agent is just a simple loop:
while (true)
{
var input = GetUserInput();
var response = await agent.SendMessage(input);
// LLM chains tools together (read file -> edit file -> test code)
while (agent.WantsToUseTool(response))
response = await agent.ProcessToolCalls(response);
}The agent exposes three simple tools to Claude:
- read_file - Read contents of a file
- write_file - Write content to a file (creates directories as needed)
- list_files - List all files and directories in a path
All file operations are sandboxed to a working folder (./output by default).
- User provides a prompt
- Agent sends prompt + conversation context + tool definitions to Claude
- Claude responds with text and/or tool calls
- Agent executes tools and sends results back
- Loop continues until Claude has no more tools to call
- User sees the final response
The ResolvePath() method ensures all file paths stay within the working folder:
string? ResolvePath(string relative)
{
var full = Path.GetFullPath(Path.Combine(workFolder, relative));
return full.StartsWith(workFolder, StringComparison.OrdinalIgnoreCase) ? full : null;
}Claude's API supports function calling through the "tool use" pattern. The agent:
- Defines tools with JSON schemas
- Claude responds with
ToolUseBlockobjects - Agent executes tools and returns results as
ToolResultBlockParam
The agent maintains full conversation history in a List<MessageParam>, including:
- User messages
- Assistant responses (text + tool calls)
- Tool results (sent as user messages)
Claude's API is stateless - the agent must send the full conversation context on every request. This allows Claude to "remember" previous interactions.
The agent restricts all file operations to a designated working folder, preventing Claude from accessing or modifying files outside the sandbox.
| Feature | MyCodingAgent | MyCodingAgent-Minimalistic |
|---|---|---|
| Lines of Code | ~295 | ~210 |
| Dependencies | Anthropic SDK, Spectre.Console | Anthropic SDK only |
| Output | Rich formatted tables | Plain console output |
| Debugging | Request/response tracking | Minimal output |
| Use Case | Development & demos | Understanding core concepts |
- Framework: .NET 10.0
- Language Model: Claude Sonnet 4.5
- API Client: Anthropic C# SDK v12
- Max Tokens: 4096 (to limit costs and prevent runaway token usage)
- Tool Execution: Synchronous, sequential
- My personal blog
- TN-Data, my consulting company
- Dometrain author page, my video courses
- LinkedIn profile, feel free to connect!
- .NET Skåne - Local .NET user group
- Coding Agent Explorer on GitHub, the open-source tool for inspecting a coding agent's API calls
- Introducing the Coding Agent Explorer (.NET), the blog post
- Anthropic API Documentation
- Claude Tool Use Guide
- Model Context Protocol (MCP)
- Spectre.Console Documentation
This demo code is provided for educational purposes as part of the presentation "How Does a Coding Agent Work?".
For more talks and presentations, visit my Talks page.