I Built a Coding Agent in Swift — The Hardest Bugs Were Concurrency, Not AI
I'm a mobile developer (mostly iOS) and I wanted to understand how coding agents like Claude Code actually work under the hood. Not the API, but the architecture. So I built one from scratch in Swift across 9 stages: file operations, shell execution, subagents, context compaction, task DAGs, background tasks, skill loading. 14 tools total. The biggest surprise: almost none of the hard bugs were AI-related. Linux handles SIGTERM differently inside child processes spawned via Process — macOS timeout strategy silently failed on CI. Swift 6.2's strict concurrency caught real data races at compile time. The nastiest bug: you must read stdout/stderr data before calling waitUntilExit() , or the pipe buffer fills and the process hangs forever. Meanwhile, the actual agent loop is ~20 lines and never changed across all 9 stages. This is Part 0 — the foundation. We're starting with the decisions that saved us from restructuring later. ivan-magda / swift-claude-code A Swift reimplementation of a C
Continue reading on Dev.to Tutorial
Opens in a new tab



