Skip to content
ivanmagda.dev

Building a Coding Agent in Swift

Build a Claude Code-style CLI coding agent in Swift over nine posts: project setup, the agent loop, tool dispatch, task tracking, subagents, skill loading, context compaction, a task DAG, and background tasks.

  1. Building a Coding Agent in Swift, Part 0: Bootstrapping the Project

    Updated:

    Setting up a two-target SPM package, strict concurrency, and AsyncHTTPClient — the foundation for a CLI agent that never needs restructuring.

  2. Building a Coding Agent in Swift, Part 1: The Agent Loop

    The agent loop that drives everything — how a single stopReason check turns an API client into an autonomous agent.

  3. Building a Coding Agent in Swift, Part 2: Tool Dispatch

    Dictionary-based tool dispatch, path sandboxing, and the read/write/edit file tools that let the agent work with code.

  4. Building a Coding Agent in Swift, Part 3: Self-Managed Task Tracking

    A Codable todo system with validation constraints and nag reminders — giving the agent a structured notepad it writes for itself.

  5. Building a Coding Agent in Swift, Part 4: Subagents

    Context isolation through recursive agent loops — spawning child agents with restricted tool sets for focused subtasks.

  6. Building a Coding Agent in Swift, Part 5: Skill Loading

    Two-layer knowledge injection — cheap awareness in the system prompt, full skill bodies loaded on demand via tool results.

  7. Building a Coding Agent in Swift, Part 6: Context Compaction

    A three-layer compression strategy — micro-compaction, auto-compaction, and manual compaction — for infinite conversations.

  8. Building a Coding Agent in Swift, Part 7: Task System

    A file-based task DAG with dependency resolution — durable planning that survives context compaction.

  9. Building a Coding Agent in Swift, Part 8: Background Tasks

    Swift actors for background execution — the one type that truly needs an actor, with notification injection before each API call.