Building a coding agent in Swift: a 9-part series

I just published a 9-part series that builds a Claude Code-style coding agent from scratch in Swift. Each stage adds one capability and walks through the design trade-offs:

  • Stage 0: Project bootstrap and Anthropic Messages API client
  • Stage 1: Agent loop (the core invariant kernel)
  • Stage 2: Tool dispatch (read_file, write_file, edit_file)
  • Stage 3: Todo persistence and file-based state
  • Stage 4: Subagents (spawning child agents for scoped tasks)
  • Stage 5: Skill loading (dynamic capability injection)
  • Stage 6: Context compaction (summarizing conversation history)
  • Stage 7: Task DAG (dependency-ordered execution)
  • Stage 8: Background tasks via Swift actors

The codebase uses Swift 6.2 strict concurrency, raw HTTP via AsyncHTTPClient. The code is kept intentionally simple for learning.

The thesis driving it: coding agents work because of architectural restraint - a small set of good tools, a thin loop, and heavy reliance on the model.

Series starts here: Bootstrapping the Project
Repo: github.com/ivan-magda/swift-claude-code

Thanks!

4 Likes