swift-concurrency
Diagnose Swift Concurrency issues, refactor callback-based code to async/await, and guide Swift 6 migration when working with tasks, actors, @MainActor, Sendable, data races, thread safety, or concurrency-related compiler and linter warnings.
Choose how to use this skill
You do not need every option. Choose the path your AI client supports. The stable page stays the same; versioned files are immutable.
1. Native installer
This listing has no registered native installer command. Use the complete package or source fallback below, depending on what your client supports.
Do not guess an installer command or replace an existing version without reviewing the diff.
2. Complete package recommended
Download the ZIP when available. It includes SKILL.md plus the references, security notes and version metadata.
No complete ProSkills package is published for this listing yet.3. Prompt-only
Copy the prompt above when the agent can read the stable page or when you want to adopt the workflow without installing a skill.
Need only the instruction file?
Download SKILL.md only if your client requires a single file. The complete ZIP is safer for a full installation because it preserves the references and release context.
No path installs or executes anything by itself. Your agent still needs access to the project files. Before updating, compare the installed version and review the diff.
// RATINGS
Not yet listed on ClawHub or SkillsMP
// README
Swift Concurrency Agent Skill
Expert guidance for any AI coding tool that supports the Agent Skills open format — safe concurrency, performance, and Swift 6+ migration.
Based on the comprehensive Swift Concurrency Course, distilled into actionable, concise references for agents.
This repository is packaged as a portable Agent Plugin (spec 1.0.0): compatible clients discover the skill automatically from the root plugin.json manifest and the skills/ directory. Client-specific manifests for Claude Code, Cursor, Codex, and pi are included as well, and the plugin is published in the OpenAI Plugins Directory for ChatGPT and Codex.
Who this is for
- Teams migrating to Swift 6 / strict concurrency who need safe defaults and quick triage.
- Developers debugging data races, isolation errors, or flaky async tests.
- Anyone wanting performance-minded concurrency patterns (actors, tasks, Sendable, async streams).
See also my other skills:
How to Use This Skill
Option A: Using skills.sh (recommended)
Install this skill with a single command:
npx skills@latest add https://github.com/avdlee/swift-concurrency-agent-skill --skill swift-concurrency
For more information, visit the skills.sh platform page.
Installed before the Agent Plugins migration? Run
npx skills@latest updateusing skills CLI 1.5.24 or newer. It migrates the saved skill path without treating the skill as deleted.
Then use the skill in your AI agent, for example:
Use the swift concurrency skill and analyze the current project for Swift Concurrency improvements
Option B: ChatGPT & Codex (OpenAI Plugins Directory)
This plugin is published in the universal OpenAI Plugins Directory shared by ChatGPT and Codex:
- In the ChatGPT desktop app, select Codex (or ChatGPT with Work enabled), or use the plugin browser in Codex CLI.
- Open Plugins and search for "Swift Concurrency".
- Install the plugin. The skill becomes available in new chats and sessions.
Option C: Claude Code Plugin
Personal Usage
To install this Skill for your personal use in Claude Code:
-
Add the marketplace:
/plugin marketplace add AvdLee/Swift-Concurrency-Agent-Skill -
Install the Skill:
/plugin install swift-concurrency@swift-concurrency-agent-skill
Project Configuration
To automatically provide this Skill to everyone working in a repository, configure the repository's .claude/settings.json:
{
"enabledPlugins": {
"swift-concurrency@swift-concurrency-agent-skill": true
},
"extraKnownMarketplaces": {
"swift-concurrency-agent-skill": {
"source": {
"source": "github",
"repo": "AvdLee/Swift-Concurrency-Agent-Skill"
}
}
}
}
When team members open the project, Claude Code will prompt them to install the Skill.
Option D: Cursor Plugin
Load the plugin from a local clone by placing it in ~/.cursor/plugins/local, or install it from the Cursor Marketplace once listed. Cursor supports both the portable Agent Plugins manifest (plugin.json) and the Cursor Plugin manifest (.cursor-plugin/plugin.json) included in this repository.
Using another tool?
See INSTALLATION.md for all other installation options: pi, Gemini CLI, Autohand Code, and manual installation.
How to verify:
Your agent should reference the triage/playbook in skills/swift-concurrency/SKILL.md and jump into the relevant reference file for your error or task.
What This Skill Offers
This skill gives your AI coding tool comprehensive Swift Concurrency guidance. It can:
Guide Your Concurrency Decisions
- Choose the right tool for the job (async/await, actors, tasks, task groups)
- Understand when to use
@MainActor, custom actors, ornonisolated - Navigate isolation domains and prevent data races at compile time
- Apply
Sendableconformance correctly for value and reference types
Write Safe Concurrent Code
- Avoid common pitfalls like actor reentrancy and retain cycles
- Prevent data races with proper isolation
- Handle task cancellation and error propagation correctly
- Manage memory safely in concurrent contexts
Optimize Performance
- Choose between serialized, asynchronous, and parallel execution
- Reduce actor contention and unnecessary suspension points
- Understand the tradeoffs of parallelism
Migrate to Swift 6
- Step-by-step migration strategies for existing codebases
- Enable strict concurrency checking incrementally
- Rewrite closure-based code to async/await
- Migrate from Combine/RxSwift to Swift Concurrency
- Use migration tooling for upcoming Swift features
Test Concurrent Code
- Write reliable tests using Swift Testing (recommended) or XCTest
- Handle
@MainActorisolation in tests - Use
withMainSerialExecutorfor deterministic testing - Avoid flaky tests with proper async handling
Integrate with Core Data
- Safely pass data between isolation domains using
NSManagedObjectID - Implement the Data Access Object (DAO) pattern
- Use custom actor executors when needed
- Avoid common Core Data concurrency pitfalls
What Makes This Skill Different
Expert Knowledge: Based on real-world experience migrating large production codebases to Swift 6, distilled from the comprehensive Swift Concurrency Course.
Non-Opinionated: Focuses on industry-standard best practices and compile-time safety, not architectural preferences. Works with any Swift project, coding style, or architecture.
Swift 6.2 Ready: Covers the latest Swift Concurrency features including:
- Default Actor Isolation
isolated deinit- Global Actor Conformance for protocols
nonisolated(nonsending)and@concurrent- Approachable Concurrency build settings
- Concurrency-safe notifications (iOS 26+)
Practical & Concise: Assumes your AI agent is already smart. Focuses on what developers need to know, not what they already understand. Includes code examples for every pattern.
See it in action
Skill Structure
skills/swift-concurrency/
├── SKILL.md # Main skill file with decision trees
└── references/
├── _index.md # Quick navigation index for all reference files
├── actors.md # Actor isolation, global actors, reentrancy
├── async-algorithms.md # AsyncAlgorithms operators: debounce, merge, zip, Combine migration
├── async-await-basics.md # Fundamentals of async/await syntax
├── async-sequences.md # AsyncSequence and AsyncStream patterns
├── core-data.md # Core Data integration patterns
├── glossary.md # Terms & concepts for Swift Concurrency
├── linting.md # Linting rules for strict concurrency
├── memory-management.md # Retain cycles, weak self, isolated deinit
├── migration.md # Step-by-step Swift 6 migration guide
├── observation.md # @Observable isolation, observation tracking, Sendable snapshots
// HOW IT'S BUILT
// FILES
2 files shipped with this skill. Inline text is the catalog copy. The upstream link is the source repository.
skills/swift-concurrency/SKILL.md7.8 KBupstream ↗
--- name: swift-concurrency description: Diagnose Swift Concurrency issues, refactor callback-based code to async/await, and guide Swift 6 migration when working with tasks, actors, @MainActor, Sendable, data races, thread safety, or concurrency-related compiler and linter warnings. --- # Swift Concurrency ## Fast Path Before proposing a fix: 1. Analyze `Package.swift` or `.pbxproj` to determine Swift language mode, strict concurrency level, default isolation, and upcoming features. Do this always, not only for migration work. 2. Capture the exact diagnostic and offending symbol. 3. Determine the isolation boundary: `@MainActor`, custom actor, actor instance isolation, or `nonisolated`. 4. Confirm whether the code is UI-bound or intended to run off the main actor. When spawning unstructured tasks, inspect the synchronous prefix (everything before the first `await`): start on `@MainActor` only when that prefix truly needs main-actor access; otherwise use `Task { @concurrent in ... }` and hop back with `MainActor.run` only after the suspension. A trivial non-main line (for example, `print`) followed by main-actor work in the same prefix is not a reason to use `@concurrent`. For delayed retries, timers, and backoff tasks, separate the waiting from the UI mutation. The sleep often belongs off the main actor even when the final state update belongs on it. Project settings that change concurrency behavior: | Setting | SwiftPM (`Package.swift`) | Xcode (`.pbxproj`) | |---|---|---| | Language mode | `swiftLanguageVersions` or `-swift-version` (`// swift-tools-version:` is not a reliable proxy) | Swift Language Version | | Strict concurrency | `.enableExperimentalFeature("StrictConcurrency=targeted")` | `SWIFT_STRICT_CONCURRENCY` | | Default isolation | `.defaultIsolation(MainActor.self)` | `SWIFT_DEFAULT_ACTOR_ISOLATION` | | Upcoming features | `.enableUpcomingFeature("NonisolatedNonsendingByDefault")` | `SWIFT_UPCOMING_FEATURE_*` | | Approachable Concurrency | N/A (use individual upcoming features) | `SWIFT_APPROACHABLE_CONCURRENCY` | > **Xcode 26 note**: New projects created in Xcode 26 will often start with `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor` and `SWIFT_APPROACHABLE_CONCURRENCY = YES` enabled by default. Treat these as likely defaults for newly created projects, not as confirmed settings. If any of these are unknown, ask the developer to confirm them before giving migration-sensitive guidance. Do not guess, even for new Xcode 26 projects. Guardrails: - Do not recommend `@MainActor` as a blanket fix. Justify why the code is truly UI-bound. - Prefer structured concurrency over unstructured tasks. Use `Task.detached` only with a clear reason. - If recommending `@preconcurrency`, `@unchecked Sendable`, or `nonisolated(unsafe)`, require a documented safety invariant and a follow-up removal plan. - Optimize for the smallest safe change. Do not refactor unrelated architecture during migration. - Course references are for deeper learning only. Use them sparingly and only when they clearly help answer the developer's question. ## Quick Fix Mode Use Quick Fix Mode when all of these are true: - The issue is localized to one file or one type. - The isolation boundary is clear. - The fix can be explained in 1-2 behavior-preserving steps. Skip Quick Fix Mode when any of these are true: - Build settings or default isolation are unknown. - The issue crosses module boundaries or changes public API behavior. - The likely fix depends on unsafe escape hatches. ## Common Diagnostics | Diagnostic | First check | Smallest safe fix | Escalate to | |---|---|---|---| | `Main actor-isolated ... cannot be used from a nonisolated context` | Is this truly UI-bound? | Isolate the caller to `@MainActor` or use `await MainActor.run { ... }` only when main-actor ownership is correct. | `references/actors.md`, `references/threading.md` | | `Actor-isolated type does not conform to protocol` | Must the requirement run on the actor? | Prefer isolated conformance (e.g., `extension Foo: @MainActor SomeProtocol`); use `nonisolated` only for truly nonisolated requirements. | `references/actors.md` | | `Sending value of non-Sendable type ... risks causing data races` | What isolation boundary is being crossed? | Keep access inside one actor, or convert the transferred value to an immutable/value type. | `references/sendable.md`, `references/threading.md` | | `SwiftLint async_without_await` | Is `async` actually required by protocol, override, or `@concurrent`? | Remove `async`, or use a narrow suppression with rationale. Never add fake awaits. | `references/linting.md` | | `wait(...) is unavailable from asynchronous contexts` | Is this legacy XCTest async waiting? | Replace with `await fulfillment(of:)` or Swift Testing equivalents. | `references/testing.md` | | Core Data concurrency warnings | Are `NSManagedObject` instances crossing contexts or actors? | Pass `NSManagedObjectID` or map to a Sendable value type. | `references/core-data.md` | | `@Observable` isolation or Sendable errors | Is the `@Observable` class annotated with the correct actor? | Add `@MainActor` for UI state; pass Sendable snapshots across boundaries. | `references/observation.md` | | `Thread.current` unavailable from asynchronous contexts | Are you debugging by thread instead of isolation? | Reason in terms of isolation and use Instruments/debugger instead. | `references/threading.md` | | SwiftLint concurrency-related warnings | Which specific lint rule triggered? | Use `references/linting.md` for rule intent and preferred fixes; avoid dummy awaits. | `references/linting.md` | | `... cannot satisfy conformance requirement for a 'Sendable' type parameter` (`SendableMetatype`) | Does the conformance carry global-actor isolation? | Remove actor isolation from the conformance, or avoid passing the metatype across isolation boundaries. See `SendableMetatype` section in `references/actors.md`. | `references/actors.md` | ## When Quick Fixes Fail 1. Gather project settings if not already confirmed. 2. Re-evaluate which isolation boundaries the type crosses. 3. Route to the matching reference file for a deeper fix. 4. If the fix may change behavior, document the invariant and add verification steps. ## Smallest Safe Fixes Prefer changes that preserve behavior while satisfying data-race safety: - **UI-bound state**: isolate the type or member to `@MainActor`. - **Shared mutable state**: move it behind an `actor`, or use `@MainActor` only if the state is UI-owned. - **Background work**: when work must hop off caller isolation, use an `async` API marked `@concurrent`; when work can safely inherit caller isolation, use `nonisolated` without `@concurrent`. When spawning a `Task`, match entry isolation to its synchronous prefix. If nothing before the first `await` needs the main actor, use `Task { @concurrent in ... }` and hop back via `await MainActor.run { ... }` for the UI update. If the prefix mixes a trivial non-main statement with main-actor work, keep the inherited `@MainActor` start—splitting the cheap line off-main is not worth an extra hop. - **Sendability issues**: prefer immutable values and explicit boundaries over `@unchecked Sendable`. ## Concurrency Tool Selection | Need | Tool | Key Guidance | |---|---|---| | Single async operation | `async/await` | Default choice for sequential async work | | Fixed parallel operations | `async let` | Known count at compile time; auto-cancelled on throw | | Dynamic parallel operations | `withTaskGroup` | Unknown count; structured — cancels children on scope exit | | Sync → async bridge | `Task { }` | Inherits actor context; use `Task.detached` only with documented reason | | Shared mutable state | `actor` | Prefer over locks/queues; keep isolated sections small | | UI-bound state | `@MainActor` | Only for truly UI-related code; justify isolation | ### Common Scenarios **Network request with UI update** ```swift Task { @concurrent in let data = try awaREADME.mdupstream ↗
Contents are not inlined in the catalog. Open the upstream file.
Plain-text copy, no login: /skill-bundles/avdlee-swift-concurrency-agent-skill-skills-swift-concurrency.md
