swift-concurrency-pro

Swift concurrency code reviewer that catches reentrancy bugs, isolation violations, and async/await pitfalls. Scans for dangerous patterns across actors, structured/unstructured tasks, cancellation handling, and async streams using a 12-step review process Targets Swift 6.2+ with strict concurrency checking, comparing build settings across multiple targets when needed Prioritizes structured concurrency (task groups) over unstructured tasks and async/await over closure-based APIs and GCD for new code Validates actor isolation correctness, reentrancy safety, and proper cancellation propagation with before/after code fixes Covers bridging between sync and async code, legacy concurrency migrations, and async test patterns with race detection

INSTALLATION
npx skills add https://github.com/twostraws/swift-concurrency-agent-skill --skill swift-concurrency-pro
Run in your project or agent environment. Adjust flags if your CLI version differs.

SKILL.md

$29

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/await and closure-based variants, always prefer async/await.
  • Do not introduce third-party concurrency frameworks without asking first.
  • Do not suggest @unchecked Sendable to fix compiler errors. It silences the diagnostic without fixing the underlying race. Prefer actors, value types, or sending parameters 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.
BrowserAct

Let your agent run on any real-world website

Bypass CAPTCHA & anti-bot for free. Start local, scale to cloud.

Explore BrowserAct Skills →

Stop writing automation&scrapers

Install the CLI. Run your first Skill in 30 seconds. Scale when you're ready.

Start free
free · no credit card