swift-ai-provider-kit
CLAUDE.md1 starsChanged 8 months agoMITView on GitHub
This is a Swift Package with the following library products: AIClient (actor) is the main entry point. It owns a ToolRegistry, SkillRegistry, and RecipeRegistry (all actor-based). When send(_:) is called and the model returns a toolUse stop reason, AIClient executes the tools concurrently via withThrowingTaskGroup and sends a follow-up request automatically — this loop repeats until the model stops requesting tools. AIProvider protocol is the only integration point for new providers. Implement send(_:) for request/response and optionally StreamableProvider for SSE…
- Reads credentials
We split this CLAUDE.md into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 38
ClaudeProviderinternals: follow a mapper pattern: - Very specific: line 49
Add a library + target in Package.swift (see commented-out OpenAI entries as a template)
- Very specific: line 50
Create a folder under Sources/ with a mapper pair (XRequestMapper, XResponseMapper), an HTTPClient implementation, and the provider class …
- Very specific: line 65
Use async/await and actors throughout.
≈ “Common” is an estimate: at least 1 in 5 of the 25,680 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
Build & Test Commands
# Build all targets
swift build
# Run all tests (mocked — no API key required)
swift test
# Run a specific test target
swift test --filter AIProviderKitTests
swift test --filter ClaudeProviderTests
# Run a single test by name
swift test --filter AIClientTests/sendForwardsRequest
# Run integration tests against the real Claude API (requires ANTHROPIC_API_KEY)
ANTHROPIC_API_KEY=<YOUR_ANTHROPIC_API_KEY> swift package integration-testsArchitecture
This is a Swift Package with the following library products:
AIProviderKit— Core protocols, models, builders, registries, and theAIClientactor. Has no external dependencies.ClaudeProvider— Anthropic Messages API implementation. Depends onAIProviderKit.AIProviderKitPersistence— SwiftData-backed conversation persistence with.chatexport/import. Depends onAIProviderKit.AIProviderKitUI— Optional SwiftUIAILogViewfor in-app log viewing. Depends onAIProviderKit.
Key design patterns
AIClient (actor) is the main entry point. It owns a ToolRegistry, SkillRegistry, and RecipeRegistry (all actor-based). When send(_:) is called and the model returns a toolUse stop reason, AIClient executes the tools concurrently via withThrowingTaskGroup and sends a follow-up request automatically — this loop repeats until the model stops requesting tools.
AIProvider protocol is the only integration point for new providers. Implement send(_:) for request/response and optionally StreamableProvider for SSE streaming. No changes to AIClient or any core type are needed.
ClaudeProvider internals follow a mapper pattern:
ClaudeRequestMapper— convertsAIRequest→ Claude-specific request bodyClaudeResponseMapper— converts Claude response / SSE data →AIResponse/AIStreamEventHTTPClientprotocol (implemented byURLSessionHTTPClient) is injected, enabling test substitution viaMockHTTPClient
ContentBlock is the universal currency for message content (.text, .image, .toolUse, .toolResult). All providers map to/from this type.
JSONValue is the untyped value type used for tool inputs/outputs, avoiding Any.
Adding a new provider
- Add a library + target in
Package.swift(see commented-out OpenAI entries as a template) - Create a folder under
Sources/with a mapper pair (XRequestMapper,XResponseMapper), anHTTPClientimplementation, and the provider class conforming toStreamableProvider - Extend
AIModelwith provider-specific model constants - See
Documentation/AddingAProvider.mdfor a full walkthrough
Testing conventions
Tests use Swift Testing (@Suite, @Test, #expect). Each test follows given / when / then with comments. Mocks live in Tests/<Target>/Mocks/:
MockAIProvider— configurable stub that records received requestsSequentialMockProvider— returns a queue of pre-configured responses (used for multi-turn tool-use tests)MockHTTPClient— stubs HTTP at the network layer forClaudeProvidertests
Platform & language requirements
- Swift 6, full
Sendablecompliance,StrictConcurrencyandExistentialAnyupcoming features enabled on all targets - iOS 26+ / macOS 26+ / watchOS 11+ / tvOS 26+ / visionOS 2+
- Use
async/awaitand actors throughout; avoid callback-based or GCD patterns
Documentation conventions
- Diagrams — always use Mermaid for any architecture, sequence, or flow diagram. Never use ASCII art. Supported diagram types in this project:
graph(dependency / module graphs),sequenceDiagram(request/response flows),flowchart(decision flows). - Issue files — detailed design for a milestone lives in
Documentation/Issues/<slug>.md. The ROADMAP entry links to it and contains only a one-sentence intro + flat- [ ]checklist. - ROADMAP format — each milestone uses a short intro paragraph (optional) and a flat bullet checklist. No sub-headers, no code blocks, no diagrams inside
ROADMAP.mditself.
Documentation assets
Banner updates: use the /update-banner skill. Canonical palette and layout rules live in .claude/skills/update-banner/SKILL.md — do not duplicate colors here.
In this repository12 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- add-providerSkill
- add-toolSkill
- commitSkill
- lintSkill
- pr-comment-fixerSkill
- swift-architecture-skillSkill
- swift-concurrency-proSkill
- swift-testing-proSkill
- swiftui-proSkill
- testSkill
- update-bannerSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

