swift-concurrency-pro
twostraws/swift-concurrency-agent-skill
Reviews Swift code for concurrency correctness, modern async/await patterns, and common pitfalls.
What is swift-concurrency-pro?
A code review skill that analyzes Swift concurrency code for correctness, modern API usage, and adherence to Swift 6.2 best practices. Use it when reading, writing, or reviewing Swift code that uses async/await, actors, task groups, or other concurrency features.
- Detects actor reentrancy bugs and isolation violations
- Identifies unstructured concurrency that should use task groups
- Validates cancellation handling and propagation
- Reviews async streams and continuation usage
- Checks bridging between sync and async code
- Flags strict-concurrency compiler errors with fixes
How to install swift-concurrency-pro
npx skills add https://github.com/twostraws/swift-concurrency-agent-skill --skill swift-concurrency-proHow to use swift-concurrency-pro
- 1.Provide the Swift code file(s) to review
- 2.Specify the target Swift version (defaults to 6.2)
- 3.Indicate if strict concurrency checking is enabled in the project
- 4.Request a full review or focus on specific areas (actors, task groups, cancellation, etc.)
- 5.Review the output organized by file with before/after code fixes
Use cases
- Review a pull request adding async/await to an existing codebase
- Audit actor implementations for reentrancy and state safety issues
- Migrate legacy GCD or completion-handler code to structured concurrency
- Validate that task groups are used instead of loops creating unstructured tasks
- Check async test implementations for race conditions and timing issues
- Swift developers writing concurrent code
- Code reviewers checking concurrency correctness
- Teams migrating to Swift 6.2 strict concurrency
- Developers learning async/await patterns
swift-concurrency-pro FAQ
GCD is acceptable in low-level code, framework interop, or performance-critical synchronous work. The skill will not flag GCD as an error in these contexts, but prefers Swift concurrency for new code.
The skill will not suggest @unchecked Sendable to fix compiler errors, as it silences diagnostics without fixing underlying races. Instead, use actors, value types, or sending parameters.
The skill targets Swift 6.2 or later with strict concurrency checking. Reviews are based on modern concurrency best practices for that version.
Yes. The skill includes patterns for async test strategy with Swift Testing, race detection, and guidance on avoiding timing-based tests.
The skill will compare concurrency build settings across targets and prefer structured concurrency (task groups) over unstructured (Task {}) where appropriate, noting legitimate uses of each.
Full instructions (SKILL.md)
Source of truth, from twostraws/swift-concurrency-agent-skill.
name: swift-concurrency-pro description: Reviews Swift code for concurrency correctness, modern API usage, and common async/await pitfalls. Use when reading, writing, or reviewing Swift concurrency code. license: MIT metadata: author: Paul Hudson version: "1.0"
Review Swift concurrency code for correctness, modern API usage, and adherence to project conventions. Report only genuine problems - do not nitpick or invent issues.
Review process:
- Scan for known-dangerous patterns using
references/hotspots.mdto prioritize what to inspect. - Check for recent Swift 6.2 concurrency behavior using
references/new-features.md. - Validate actor usage for reentrancy and isolation correctness using
references/actors.md. - Ensure structured concurrency is preferred over unstructured where appropriate using
references/structured.md. - Check unstructured task usage for correctness using
references/unstructured.md. - Verify cancellation is handled correctly using
references/cancellation.md. - Validate async stream and continuation usage using
references/async-streams.md. - Check bridging code between sync and async worlds using
references/bridging.md. - Review any legacy concurrency migrations using
references/interop.md. - Cross-check against common failure modes using
references/bug-patterns.md. - If the project has strict-concurrency errors, map diagnostics to fixes using
references/diagnostics.md. - If reviewing tests, check async test patterns using
references/testing.md.
If doing a partial review, load only the relevant reference files.
Core Instructions
- Target Swift 6.2 or later with strict concurrency checking.
- If code spans multiple targets or packages, compare their concurrency build settings before assuming behavior should match.
- Prefer structured concurrency (task groups) over unstructured (
Task {}). - Prefer Swift concurrency over Grand Central Dispatch for new code. GCD is still acceptable in low-level code, framework interop, or performance-critical synchronous work where queues and locks are the right tool – don't flag these as errors.
- If an API offers both
async/awaitand closure-based variants, always preferasync/await. - Do not introduce third-party concurrency frameworks without asking first.
- Do not suggest
@unchecked Sendableto fix compiler errors. It silences the diagnostic without fixing the underlying race. Prefer actors, value types, orsendingparameters instead. The only legitimate use is for types with internal locking that are provably thread-safe.
Output Format
Organize findings by file. For each issue:
- State the file and relevant line(s).
- Name the rule being violated.
- Show a brief before/after code fix.
Skip files with no issues. End with a prioritized summary of the most impactful changes to make first.
Example output:
DataLoader.swift
Line 18: Actor reentrancy – state may have changed across the await.
// Before
actor Cache {
var items: [String: Data] = [:]
func fetch(_ key: String) async throws -> Data {
if items[key] == nil {
items[key] = try await download(key)
}
return items[key]!
}
}
// After
actor Cache {
var items: [String: Data] = [:]
func fetch(_ key: String) async throws -> Data {
if let existing = items[key] { return existing }
let data = try await download(key)
items[key] = data
return data
}
}
Line 34: Use withTaskGroup instead of creating tasks in a loop.
// Before
for url in urls {
Task { try await fetch(url) }
}
// After
try await withThrowingTaskGroup(of: Data.self) { group in
for url in urls {
group.addTask { try await fetch(url) }
}
for try await result in group {
process(result)
}
}
Summary
- Correctness (high): Actor reentrancy bug on line 18 may cause duplicate downloads and a force-unwrap crash.
- Structure (medium): Unstructured tasks in loop on line 34 lose cancellation propagation.
End of example.
References
references/hotspots.md- Grep targets for code review: known-dangerous patterns and what to check for each.references/new-features.md- Swift 6.2 changes that alter review advice: default actor isolation, isolated conformances, caller-actor async behavior,@concurrent,Task.immediate, task naming, and priority escalation.references/actors.md- Actor reentrancy, shared-state annotations, global actor inference, and isolation patterns.references/structured.md- Task groups over loops, discarding task groups, concurrency limits.references/unstructured.md- Task vs Task.detached, when Task {} is a code smell.references/cancellation.md- Cancellation propagation, cooperative checking, broken cancellation patterns.references/async-streams.md- AsyncStream factory, continuation lifecycle, back-pressure.references/bridging.md- Checked continuations, wrapping legacy APIs,@unchecked Sendable.references/interop.md- Migrating from GCD,Mutex/locks, completion handlers, delegates, and Combine.references/bug-patterns.md- Common concurrency failure modes and their fixes.references/diagnostics.md- Strict-concurrency compiler errors, protocol conformance fixes, and likely remedies.references/testing.md- Async test strategy with Swift Testing, race detection, avoiding timing-based tests.
Related skills
More from twostraws/swift-concurrency-agent-skill and the wider catalog.

swift-testing-pro
Write, review, and improve Swift Testing code using modern APIs and best practices.

swiftdata-pro
Write, review, and improve SwiftData code using modern APIs and best practices.

swiftui-pro
Comprehensively reviews SwiftUI code for best practices, modern APIs, and performance.

typefully
Create, schedule, and manage social media posts across X, LinkedIn, Threads, Bluesky, Mastodon, and Substack Notes.

typesafe-ai
Build AI features with typed judgments instead of text generation—compose System One models like programming primitives.
adhd
Parallel divergent ideation for coding agents—explore unconventional solutions across 5 cognitive frames.