e↗entertrainment
← All project stories
Developer tools / PROJECT STORY

Claude Swift SDKs

Independent Swift ports for Anthropic APIs, Claude Agent SDK workflows and related tools. Native Swift interfaces built around the upstream products.

Independent SDK ports12 MIN READDEVELOPMENT ARCHIVE · OCT 2026
PROJECT REVIEW · 18 October 2026

Inside the project

Prepared with the project’s development agent from source and retained evidence. This is a project-owner assessment, not an independent customer review. Dated checks were not rerun for this website.

Claude Swift SDKs are a private, independent Swift 6 port of Anthropic's open-source developer kits. They are not an Anthropic product. Two libraries carry the weight. The Anthropic Swift API Library ports the official TypeScript SDK: every Claude API endpoint, streaming, typed structured output, tool runners and cloud access through Amazon Bedrock, Vertex AI, Microsoft Foundry and Claude Platform. The Claude Agent SDK for Swift ports the Python and TypeScript Agent SDKs: it drives Claude Code from Swift with tools, hooks and permission callbacks, and on iPhone and Vision Pro it attaches to a remote Claude Code session. Eight further packages port Anthropic's examples, quickstarts, cookbooks, session stores, security review and Claude Code hooks. They're useful for Swift developers who want Claude in Mac, iOS or server-side Swift apps without leaving the language or adding third-party dependencies. Everything has automated tests on macOS and Linux. Real-world use so far is narrow but genuine: small live runs on Amazon Bedrock, and through the Claude Code CLI. A current compiler crash blocks optimised (release) builds of the API library on Xcode 26, and nothing has been published.

What stands out

  • Breadth: all 201 TypeScript-SDK endpoints (23 GA, 178 beta) and its helpers, in Swift
  • Foundation-only (AnthropicMCP aside), one codebase for every Apple platform and Linux
  • Typed structured output derived from ordinary Decodable Swift types
  • Bedrock verified live, including the AWS aws login/SSO/role credential paths
  • Agent SDK parity checked against the official TypeScript typings (0.3.283): all 33 hook events typed
  • Remote-session transports bring the Agent SDK to iOS and visionOS
  • Zero-warning builds and large test suites (AnthropicSDK 512/508, ClaudeAgentSDK 558, 1,800+ in total)

Current limits

  • Release (optimised) builds of AnthropicSDK crash the Xcode 26 compiler (SIL Mem2Reg, Helpers/BetaToolAdapters.swift:96). Debug builds are fine. This blocks AssistantApp release builds, and as of 18 Oct no fix has been committed.
  • Live-tested only on Bedrock (Haiku 4.5) and through Claude Code CLI 2.1.233. The first-party Claude API, Vertex, Foundry, the cookbooks and the examples have only run against mocks and stubs.
  • ClaudeAgentSDK needs the claude CLI locally; on iOS and visionOS it needs a remote session, and those transports are mock-tested only.
  • Private repo: no release, tag, package listing or public download.
  • No UI, so no screenshots exist.

Features & evidence

Messages (create/stream)

installed-tested

Send a prompt and get a reply, optionally streamed as text arrives

Recorded evidence

Unit tests 2026-09-28 (macOS 512, Linux 508); live on Bedrock eu-west-1 2026-09-27 and 2026-09-29

Structured output (parse)

installed-tested

Turn Claude's answer into a Swift type

Recorded evidence

Live Bedrock parse: Ireland → Dublin, 2026-09-28/29

Tool runner

installed-tested

Claude calls your Swift functions in a loop until done

Recorded evidence

Live Bedrock 2026-09-28 after a bug fix (commit c38ec05)

Cloud clients and AWS credential chain

installed-tested (Bedrock only); component-tested (others)

Use Claude through Bedrock/Vertex/Foundry/Claude Platform with the usual cloud credentials

Recorded evidence

aws login chain live 2026-09-29 (commit fd7be7a); others mock-tested

Beta APIs (managed agents, sessions, environments, memory stores, …)

component-tested

The full beta surface plus environment worker, local agent toolset, skills extraction and memory sync

Recorded evidence

Mock-transport tests; never live

Agent SDK query() / ClaudeSDKClient

installed-tested

Run Claude Code agents from Swift: one-shot or multi-turn

Recorded evidence

Live via claude CLI 2.1.233, Haiku 4.5, 2026-09-27; 558 tests

Agent hooks, permissions, in-process tools

installed-tested

Observe tool calls, approve or deny them, add Swift tools

Recorded evidence

Live PreToolUse hook and canUseTool deny, 2026-09-27

Remote sessions (iOS/visionOS)

component-tested

Attach an Apple-device app to a remote Claude Code session

Recorded evidence

Mock-tested; builds for iOS and visionOS; never live

Examples, quickstarts, cookbooks, session stores, security review, hooks, MCP bridge

component-tested

Swift ports of Anthropic's samples and tools

Recorded evidence

Per-package tests (HANDOFF table); stub or dry runs only

Release build / distribution

unknown / not released

Optimised builds and publishing

Recorded evidence

Release build crashes on Xcode 26 (reported 2026-10-17); private repo, no tag

Review updates & corrections
  • No new commits: swift-sdk-port is still at fd7be7a (checked 2026-10-18).
  • Confirmed, not just reported: the closure the release-build crash points at (BetaToolAdapters.swift:96, and its twin at :109) is still in the source. A patch was proposed to the AssistantApp session but not applied, so AssistantApp release work (landing/sdk-adoption-1-3) stays blocked.
  • Media: still none. The smoke-test source that produced the live transcripts was in a session scratch folder that no longer exists, so the transcripts survive only as text in HANDOFF.md.

Workflow walkthrough

A guide to the native workflow. These steps describe the app; only the recordings and images embedded on this page are available as website demonstrations.

  1. Add the AnthropicSDK package to a Swift project and set ANTHROPIC_API_KEY (or use AnthropicClient.bedrock with AWS credentials).
  2. Call client.messages.create with "Reply with exactly the word: pong": Claude replies "pong".
  3. Switch to messages.stream and print textStream: "1, 2, 3, 4, 5" arrives as it's generated.
  4. Register a get_weather RunnableTool and run toolRunner: Claude calls it and answers "It's 18°C and sunny in Dublin."
  5. Call messages.parse(as: Capital.self): a typed Swift value, Ireland → Dublin.
  6. (Agent SDK) for try await m in query(prompt:) with a canUseTool callback: Claude reads a file, and a denied shell command never runs.
Planned captures · not yet available
  • Proposed: terminal capture of the four-step Bedrock smoke test
  • Not possible on the website: these are libraries and need an API key or cloud credentials

Development biography · earlier archive

Development profile compiled from project source and retained records in October 2026. Dates and test results describe those records; they do not imply a new build, live acceptance test or public release.

Port vs upstream (read first)

  • Upstream products (Anthropic): the Claude API, the Anthropic TypeScript and Python SDKs, the Claude Agent SDK (Python and TypeScript), Claude Code, and Anthropic's examples, quickstarts and cookbooks. Anthropic builds, owns and publishes these.
  • Local ports: independent Swift 6 re-implementations, written in this workspace from 2026-09-25 with AI assistance (Claude Code sessions). They aren't published by Anthropic or endorsed by it.
  • Where they live: branch swift-sdk-port, pushed to the private GitHub repo entertrainment/claude-swift-sdks.
  • Owner: the local workspace owner (Douglas, Entertrainment). No public authorship statement exists in the repo, so treat attribution as "private port by Entertrainment".
  • Site wording: always say "Swift port of …", never "Anthropic's Swift SDK".

Claude Agent SDK for Swift (swift/ClaudeAgentSDK)

Biography (~650 words). Anthropic's Claude Agent SDK packages the engine behind Claude Code as a library: the agent loop, the built-in tools (Read, Write, Bash, …), hooks, permissions and session management. Officially it exists for Python and TypeScript. Swift developers building Mac tools, server-side Swift services or Apple-platform apps had no native way to embed that agent loop. This port fills the gap. It was written in September 2026 as part of a wider effort to port everything convertible in Anthropic's open-source developer material to Swift.

The design follows the Python SDK's architecture and keeps the same wire protocol. The library launches the claude CLI and exchanges newline-delimited JSON control messages with it. Swift idioms replace Python's. query(prompt:options:) returns an AsyncThrowingStream<Message, Error> for one-shot tasks. ClaudeSDKClient is an actor for multi-turn conversations: follow-up questions, interrupts, mid-session model or permission-mode changes, MCP server status, context usage and file rewinds. Cancelling the Swift task or breaking out of the loop stops the CLI. Options are a struct with a closure initializer, so call sites stay short.

The port also has the features that, upstream, only the TypeScript SDK offers. These include capability lists, plugin and skill reloads, settings updates, side questions, conversation rewind, background tasks, session titles, prompt suggestions and progress summaries. On 2026-09-27 the port was checked against the official TypeScript typings (sdk.d.ts, npm @anthropic-ai/claude-agent-sdk 0.3.283). That check added seven controls, elicitation and user-dialog callbacks, and typed inputs and outputs for all 33 hook events. Every system message subtype is typed. Tripwire tests fail if new upstream items appear unhandled.

Custom tools run in-process: you register Swift closures as an MCP server, and Claude calls them with direct access to your app's state. A tool's JSON schema can be derived automatically from a Decodable input type. canUseTool lets an app approve or deny each tool call. environmentPolicy limits which environment variables the CLI inherits.

A distinctive addition is remote sessions. iOS and visionOS can't spawn a CLI, so the SDK ports the npm package's browser transports (SSE and WebSocket). An iPhone or Vision Pro app can attach to a Claude Code session running elsewhere. The transports have resume, liveness timeouts, bounded reconnects and strict frame trust rules.

User journey: a developer adds the package by path or git URL and installs the claude CLI. They write for try await message in query. As Claude works, they see typed assistant, tool-use and result messages, ending with turns taken and cost. Next they switch to ClaudeSDKClient for a conversation, add a PreToolUse hook to log tool calls, and a canUseTool callback that refuses shell commands.

Live evidence is modest but real. On 2026-09-27, against the real Claude Code CLI 2.1.233 on Claude Haiku 4.5 (about $0.001 in total):

  • a one-shot query returned its typed init message;
  • a client session read a file through the Read tool, with the PreToolUse hook firing;
  • a denied Bash command never ran;
  • readFile, getServerInfo and reinitialize worked;
  • the opt-in end-to-end test passed.

Features (authored by the port unless noted):

  • query() and ClaudeSDKClient.
  • Typed messages and hooks.
  • In-process MCP tools; the protocol comes from the upstream MCP spec.
  • Permission callbacks and environment policy.
  • The TS-only session controls.
  • Remote SSE/WebSocket transports.
  • E2E test gated by CLAUDE_AGENT_SDK_E2E=1.

Dependency: the Claude Code CLI (Anthropic's product, not bundled). No Swift package dependencies.

Technical foundations:

  • Swift 6 strict concurrency; Foundation only.
  • Close-on-exec pipes and serialized process launches; the Linux child-process races were found and fixed during the port.
  • swift-testing; 558 tests.

Maturity (dated):

  • Source: implemented (2026-09-26/27).
  • Tests: 558 pass on macOS and Linux .
  • Built: debug builds for macOS, Linux, iOS and visionOS. A release build hasn't been recorded.
  • Runtime: verified live on macOS only, 2026-09-27 (above).
  • Remote transports: tested against mocks, never live.
  • Released: no. Private repo; no tag, version number or package registry listing found.

Limits:

  • Needs the claude CLI locally.
  • Some newer controls (reloadOutputStyles, readMcpResource, updateSettings, projectConfigRoot, permissionPrompts, perTaskStopAffordance) need a CLI newer than 2.1.233.
  • The deprecated V2 session API isn't ported; upstream removed it.
  • No Windows-specific handling.

FAQs:

  • Is it official? No. It's a private Swift port of Anthropic's open-source SDK.
  • Does it need Claude Code installed? Yes, on macOS and Linux. Not for remote sessions.
  • Does it work on iPhone? Only by connecting to a remote Claude Code session.
  • Any dependencies? Foundation only.

Anthropic Swift API Library (swift/AnthropicSDK, module Anthropic)

Biography (~620 words). Anthropic publishes official SDKs for several languages but not Swift. Apple-platform and server-side Swift developers have relied on thin community wrappers that cover the Messages endpoint and little else. This port set out to match the TypeScript SDK feature for feature. That means every endpoint in its api.md, including the large beta surface (managed agents, sessions, environments, memory stores, vaults, tunnels, deployments, organisation admin, webhooks), plus the helpers that make the SDK pleasant to use.

The library reads ANTHROPIC_API_KEY like its upstream. A message is one call: client.messages.create(MessageCreateParams(model: .claudeSonnet5, maxTokens: 1024, messages: [.user("Hello, Claude")])). Streaming gives a textStream to print as text arrives, then the accumulated final message. Structured output turns a reply straight into a Swift type: messages.parse(params, as: MyType.self). The JSON schema is derived from the Decodable type, with no macros. On Apple's newest OSes, Apple's FoundationModels @Generable types work too. Tool runners execute your Swift tools in a loop until Claude finishes. API unions are Swift enums with an unknown case, so newer server responses decode without breaking older apps.

Cloud support is a major part. AnthropicClient.bedrock(BedrockConfiguration(region:)) signs requests with AWS SigV4 and decodes Bedrock's binary event stream. A full AWS credential chain is included: environment variables, profiles, credential_process, web identity, ECS, EC2 metadata, and, since 2026-09-28, aws login, SSO and role profiles via the AWS CLI. Vertex AI, Microsoft Foundry and Claude Platform on AWS and GCP have their own clients.

The port also brings Anthropic's self-hosted environment tooling to Swift. That covers the worker and a local agent toolset (bash, read, write, edit, glob and grep, confined to a working folder). It can download and safely extract agent skills, using its own zip, tar and DEFLATE readers. It also syncs memory stores both ways, following the Python SDK's rules.

User journey: an iOS developer adds the package and calls create with a prompt, then switches to stream to show text as it arrives. They define a struct Recipe: Decodable and call parse(_, as: Recipe.self) to get typed data. A company on AWS swaps in AnthropicClient.bedrock(...) without touching the rest of its code.

Live evidence:

  • On 2026-09-27/28, on Amazon Bedrock (eu-west-1, Claude Haiku 4.5 inference profile), all four smoke-test steps passed: create, stream, the tool runner and structured parse. Total cost was under one cent.
  • The live run exposed a real bug: Bedrock omits a caller field the types required. It was fixed in commit c38ec05 with a regression test.
  • On 2026-09-29, the same four steps passed using only the SDK's own credential chain with an aws login session (commit fd7be7a).
  • The first-party Claude API itself hasn't been called live.

Features (authored port):

  • Full endpoint coverage, with typed models.
  • Streaming, structured output and tool runners (GA, beta and sessions).
  • Batches, files, models and skills.
  • Cloud clients and the AWS/GCP credential chains.
  • Request middleware, a logger and pagination.
  • Webhook verification.
  • Environment worker, agent toolset, skills extraction and memory-store sync.
  • FoundationModels bridge on Apple platforms.

Dependencies: none beyond Foundation. The AWS CLI is optional, used only for aws login/SSO/role profiles.

Technical foundations:

  • Swift 6 strict concurrency.
  • URLSession, with a delegate-based streaming path on Linux.
  • Hand-written AWS SigV4 and event-stream decoding; generated, version-checked model types.

Maturity (dated):

  • Source: complete, 201/201 endpoints (2026-09-26).
  • Tests: 512 pass on macOS and 508 on Linux (2026-09-28).
  • Built: debug builds pass. The release build is currently broken on the Xcode 26 toolchain . There's no fix commit yet.
  • Runtime: verified live on Bedrock only.
  • Released: no. Private repo, no version tag.

Limits:

  • Release builds fail on Xcode 26 until the fix above lands.
  • Not live-tested against api.anthropic.com, Vertex, Foundry or Claude Platform.
  • Not ported: Google external_account and impersonated credentials; the Zod/Standard Schema helpers (Swift types are used instead); OpenTelemetry propagation.
  • Google service-account keys need a token provider on Linux.

FAQs:

  • Official? No. It's a private port of Anthropic's TypeScript SDK.
  • Which platforms? All Apple platforms from 2022-era versions, plus Linux.
  • Bedrock? Yes, verified live. The AWS account must first submit Anthropic's use-case form.
  • Dependencies? None beyond Foundation.

Related ports (short, supporting entries; not separate products)

PackagePorted from (upstream)What it isTests (HANDOFF)
ClaudeAgentExamplesAnthropic agent-sdk demos and workshopAgent SDK demo programs; terminal UIs replace web ones; dry runs only62
ClaudeQuickstartsAnthropic developer quickstartsAll 15 quickstarts, plus a Swift self-hosted sandbox worker (its Docker runtime stage has never run)525
AnthropicExamplesTS SDK examplesAll 34 examples, run against a stub API5
ClaudeCookbooksAnthropic cookbooks89 cookbooks from 86 of 101 notebooks; never run live52
ClaudeSessionStoresAgent SDK session-store examplesS3, Redis and Postgres adapters49
ClaudeSecurityReviewclaude-code security-reviewaudit, comment, eval CLI26
ClaudeCodeHooksclaude-code plugin hooksEvery plugin hook script, in Swift23
AnthropicMCPMCP adapters of other SDKsOfficial Swift MCP SDK ⇄ Claude API types, plus an in-process MCP bridge for Claude Code; the only package with a dependency (modelcontextprotocol/swift-sdk ≥ 0.12.1)18

ClaudeForFoundationModels (swift/ClaudeForFoundationModels) is a clone of Anthropic's anthropics/ClaudeForFoundationModels. Only its local anthropic-sdk branch (rebased onto AnthropicSDK, 244 tests) is local work. Present it as upstream plus a local branch, not as a port.


Roadmap (from HANDOFF "Remaining work")

  • Fix the Xcode 26 release-build compiler crash (urgent; blocks AssistantApp release builds).
  • Live-test against the first-party Claude API, then the cookbooks and examples.
  • Run the Swift sandbox worker in a live session before it replaces the Python worker.
  • Possibly publish: no decision is recorded.

Explore the connections.

Browse all project stories ↗