Where the cloud usually sits

A Local Coding Agent with apfel

A series on building a coding agent in Swift whose language model runs entirely on your own Mac — from the apfel CLI to integration with Xcode 27.

Every Apple Silicon Mac running macOS 26 (Tahoe) ships with a Foundation Model that is currently used only by Siri and a few system functions. apfel exposes this model as a CLI and as an OpenAI-compatible server. This series builds a Swift coding agent on top of it: a Plan/Act/Observe loop, tool calling, MCP integration, a Hummingbird server, and integration with Xcode 27 via its local provider slot. No API key, no cloud endpoint, no token bill — but no cloud pace either: two critical interludes (Article 6 and Article 11) take a close look at what the small on-device model can handle and what platform dependency the local route entails. Code lives openly on Codeberg, with a tag per article to follow along. Thirteen articles plus a prologue.

  1. 0

    The Model Is Already There — A Prologue to the Local Coding Agent

    A series takes a close look at the Foundation Model every Apple Silicon Mac running macOS 26 ships with — and builds on it a coding agent in Swift that runs locally.
    2. Jun 2026
  2. 1

    apfel from the command line

    We install apfel, walk through the three modes (prompt, serve, chat), and see where the on-device model holds up and where it gives way — Article 1 of the series "A Local Coding Agent with apfel".
    3. Jun 2026
  3. 2

    The serve mode and the OpenAI protocol

    We start apfel as a local OpenAI-compatible server, walk through every endpoint and see where the protocol diverges from OpenAI — Article 2 of the series "A Local Coding Agent with apfel".
    3. Jun 2026
  4. 3

    The Swift client: first connection to the model

    We set up a Swift package, build an async HTTP client against apfel --serve and process SSE streaming token by token — Article 3 of the series "A Local Coding Agent with apfel".
    4. Jun 2026
  5. 4

    Understanding tool calling: from schema to round-trip

    We teach the agent to call tools — the tool definition in the OpenAI schema, the round-trip of invocation, execution and continuation, and a tool abstraction in Swift. Article 4 of the series "A Local Coding Agent with apfel".
    7. Jun 2026
  6. 5

    The first real tools: file system and shell

    We build the first tools the agent uses to change things, and lock them down — a path sandbox, a confirmation gate, a diff before writing, and defense-in-depth for the shell. Article 5 of the series "A Local Coding Agent with apfel".
    7. Jun 2026
  7. 6

    The local coding agent put to the eval

    A reproducible eval of 15 tasks across five categories measures where the local Foundation Model carries as a coding agent and where it breaks. With a cloud sample and a separate measurement of what the model claims about its own success. Article 6 of the series "A Local Coding Agent with apfel".
    8. Jun 2026
  8. 7

    Editing that works: constrained output instead of tool guessing

    The naive file edit fails on the small model. We build the agent around that weakness, with constrained output and a two-stage edit workflow, and measure how much can be recovered. Article 7 of the series "A Local Coding Agent with apfel".
    8. Jun 2026
  9. 8

    The agent loop with a done-check

    The naive agent loop ends when the model goes quiet, and that is just a self-report. We build a loop whose stop condition is a machine check, with an iteration limit and a context budget as guards. Article 8 of the series "A Local Coding Agent with apfel".
    9. Jun 2026
  10. 9

    The interactive terminal session

    The one-shot command becomes an interactive REPL session. The key to testability is the strict separation of render logic and terminal I/O. Article 9 of the series "A Local Coding Agent with apfel".
    10. Jun 2026
  11. 10

    Tools the agent doesn't write: MCP

    MCP moves writing tools out of the agent into separate servers. We build a small MCP server, attach it to apfel, and measure what MCP solves and what it doesn't. Article 10 of the series "A Local Coding Agent with apfel".
    11. Jun 2026
  12. 11

    The agent in the browser

    The agent gets a third surface. Behind a Hummingbird server it streams its work into the browser over Server-Sent Events, confirmation by click included. The same core as in the terminal, only a different sink. Article 11 of the series "A Local Coding Agent with apfel".
    12. Jun 2026
  13. 12

    Sovereignty on borrowed ground

    The local agent runs without a key and without the cloud. But what does that independence rest on? Two releases from the same week, a cloud handoff from Anthropic and Apple's MLX stack, bring the question into focus. A sober assessment. Article 12 of the series "A Local Coding Agent with apfel".
    12. Jun 2026
  14. 13

    Where the cloud usually sits

    For the finale we place the local agent where Claude or ChatGPT usually sit inside Xcode. Apple showed the local provider slot at WWDC26, and we installed macOS 27 and Xcode 27 on purpose to put it to the test. How far does the borrowed small model get there? Article 13 of the series "A Local Coding Agent with apfel".
    20. Jun 2026