swift-coding-agent

作者 ivan-magda已验证

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

178
Stars
11
Forks
Swift
语言
2026/8/23
添加时间

⚠️ 第三方软件声明

本 Skill 为第三方开源软件,独立托管于 GitHub。SkillTip 仅为信息目录,不控制或维护底层仓库。所显示的安全检查为自动化且范围有限,安装前请自行审查源码。

阅读服务条款

安装

添加到你的 Claude Code skills 目录:

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

快速入门

使用 swift-coding-agent 等 Skills 的指南。

安全报告

已验证

上次扫描:—

{
  "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

常见问题

What is swift-coding-agent?

swift-coding-agent 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 178 GitHub stars.

Is swift-coding-agent safe to use?

Yes. swift-coding-agent 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-coding-agent?

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

What programming language is swift-coding-agent written in?

swift-coding-agent 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-coding-agent?

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-coding-agent against similar tools.

评论 (0)

暂无评论,成为第一个分享想法的人!

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 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

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 智能体ai-agentsanthropicclaude-code
查看详情

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 智能体claude-codeai-tools
查看详情

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 智能体
查看详情

开发者还喜欢

基于喜欢此 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 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

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 服务器apisai-tools
查看详情

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 智能体ai-agentsanthropicclaude-code
查看详情

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 智能体claude-codeai-tools
查看详情