swift-claude-code

by ivan-magdaVerified

A Swift reimplementation of a Claude Code-style coding agent, built stage by stage to explore what makes coding agents work

173
Stars
10
Forks
Swift
Language
8/23/2026
Added
View on GitHubDownload ZIP

⚠️ Third-Party Software Notice

This skill is third-party open-source software developed and hosted independently on GitHub. SkillTip is an informational directory and does not control or maintain the underlying repository. Any security checks displayed are automated and limited in scope. Review the source code before installing.

Read the Terms of Service

Installation

Add to your Claude Code skills directory:

# Add to your Claude Code skills
git clone https://github.com/ivan-magda/swift-claude-code

Getting Started

Guides for using skills like swift-claude-code.

Security Report

Verified

Last scanned: —

{
  "status": "PASSED",
  "issues": []
}

README.md

swift-coding-agent

Exploring the architecture of coding agents by rebuilding a Claude Code-style CLI from scratch in Swift.

demo

Learning Series

A 9-part learning series covers the build on ivanmagda.dev.

Start the series →

Why This Exists

Claude Code works better than most coding agents I've used, and I think the reason is restraint. I studied its tool surface and traced its loop to isolate which design choices do the work.

My working theory: coding agents benefit more from a small set of excellent tools and a tight loop than from large orchestration layers.

Claude Code ships few tools, and the ones it has are simple: a search tool, a file editor. They work well. The system trusts the model and skips the scaffolding most agents pile on.

This project rebuilds those mechanics in Swift, one stage at a time, to find out how little architecture the job needs.

Hypothesis

This project tests a few specific ideas about coding agents:

  • A small number of high-quality tools beats a large tool catalog
  • The model should do the heavy lifting; orchestration stays thin
  • Explicit task state improves reliability more than prompt-only planning
  • Controlled context injection matters more than persistent memory
  • Context compaction is a product feature, not a token optimization

Each stage isolates one mechanism so I can see what it enables.

The Agent Loop

The whole thing boils down to one loop:

func run(query: String) async throws -> String {
    messages.append(.user(query))

    while true {
        let request = APIRequest(
            model: model, system: systemPrompt, messages: messages, tools: Self.toolDefinitions
        )
        let response = try await apiClient.createMessage(request)
        messages.append(Message(role: .assistant, content: response.content))

        guard response.stopReason == .toolUse else {
            return response.content.textContent
        }

        var results: [ContentBlock] = []
        for block in response.content {
            if case .toolUse(let id, let name, let input) = block {
                let output = await executeTool(name: name, input: input)
                results.append(.toolResult(toolUseId: id, content: output, isError: false))
            }
        }
        messages.append(Message(role: .user, content: results))
    }
}

The loop is fixed; the tools vary. Every stage adds entries to the tool handler dictionary and injection points before the API call, but the loop body itself stays identical.

Roadmap

Git tags track progress. The roadmap has two phases: core mechanics first, then product-level features.

Phase 1: Core Loop

The minimum viable agent: a loop and a small set of good tools.

StageWhat It AddsTag
00Bootstrap: SPM project, two-target layout, CI00-bootstrap
01Agent loop + bash tool01-agent-loop
02Tool dispatch: read_file, write_file, edit_file with path safety02-tool-dispatch
03Todo tracking with nag reminder injection03-todo-write

Phase 2: Product Mechanics

The features that make an agent feel like a usable product: context, memory management, and persistence.

StageWhat It AddsTag
04Subagents: recursive loop with fresh context04-subagents
05Skill loading: .md files injected as tool results05-skill-loading
06Context compaction: 3-layer strategy (micro, auto, manual)06-context-compaction
07Task system: file-based CRUD with dependency DAG07-task-system
08Background tasks: Task {} + actor-based notification queue08-background-tasks

Architecture

Two-target Swift Package Manager project:

Core is the library: API client, shell executor, agent loop, tools.

CLI is the entry point. The executable is named agent.

The agent talks to POST https://api.anthropic.com/v1/messages over raw HTTP, built on AsyncHTTPClient. It runs on macOS and Linux.

Non-Goals

This project is not:

  • A full Claude Code clone or drop-in replacement
  • A general-purpose multi-agent framework
  • Production-ready IDE tooling

It's a staged exploration of coding-agent architecture. The gaps are deliberate.

Tech Stack

  • Swift 6.2 with strict concurrency
  • AsyncHTTPClient (SwiftNIO-based) for cross-platform HTTP + streaming SSE
  • Foundation Process for shell command execution
  • macOS 10.15+ / Linux

Getting Started

git clone https://github.com/ivan-magda/swift-coding-agent.git
cd swift-coding-agent

# Set up your API key and model
cp .env.example .env
# Edit .env with your ANTHROPIC_API_KEY and MODEL_ID

swift build
swift run agent

References

License

MIT

Frequently Asked Questions

What is swift-claude-code?

swift-claude-code is an open-source ai agents skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by ivan-magda. A Swift reimplementation of a Claude Code-style coding agent, built stage by stage to explore what makes coding agents work. It has 173 GitHub stars.

Is swift-claude-code safe to use?

Yes. swift-claude-code passed SkillsLLM's automated security scan — a dependency vulnerability audit plus prompt-injection heuristics — with no high-severity issues. You can read the full report in the Security Report section on this page.

How do I install swift-claude-code?

Clone the repository with "git clone https://github.com/ivan-magda/swift-claude-code" and add it to your Claude Code skills directory (see the Installation section above).

What programming language is swift-claude-code written in?

swift-claude-code is primarily written in Swift. It is open-source under ivan-magda on GitHub, so you can review or fork the full source.

Are there alternatives to swift-claude-code?

Yes. SkillsLLM lists many other AI Agents skills you can browse and compare side by side. Open the AI Agents category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh swift-claude-code against similar tools.

Comments (0)

No comments yet. Be the first to share your thoughts!

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI Agentsai-agentsanthropicclaude-code
View details
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI Agentsai-agentsbrainstorming
View details

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI Agentsai-agentsanthropicclaude-code
View details

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI Agentsclaude-codeai-tools
View details

claude-code

by anthropics

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

120,03119,897Shell
AI Agents
View details

Developers Also Liked

Based on votes and bookmarks from developers who liked this skill

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI Agentsai-agentsanthropicclaude-code
View details
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI Agentsai-agentsbrainstorming
View details

n8n

by n8n-io

12

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

201,88160,308TypeScript
MCP Serversapisai-tools
View details

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI Agentsai-agentsanthropicclaude-code
View details

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI Agentsclaude-codeai-tools
View details