kotlin-coroutines-structured-concurrency

Identify and remediate CoroutineScope ownership misuses in Kotlin codebases.

1|Updated Apr 2, 2026
One-click install
npx skills add https://github.com/leogallego/ansible-jane --skill kotlin-coroutines-structured-concurrency-leogallego
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-coroutines-structured-concurrency
Source: https://github.com/leogallego/ansible-jane/tree/main/skills/kotlin-coroutines-structured-concurrency
Command: npx skills add https://github.com/leogallego/ansible-jane --skill kotlin-coroutines-structured-concurrency-leogallego

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Kotlin codebases often suffer from mismanaged CoroutineScope ownership, leading to leaks, unstructured concurrency, and hard-to-diagnose cancellation behavior. This Skill helps you recognize and fix patterns where CoroutineScope is stored in a class, or where launches occur in init blocks or non-suspending APIs, guiding you to suspend functions and lifecycle-bound design.

Core Features & Use Cases

  • Identifies anti-patterns like stored scopes, init launches, and fire-and-forget calls
  • Provides concrete refactoring guidance to convert to suspending APIs and proper lifecycle ownership
  • Useful for code reviews and educational learning to enforce structured concurrency across Kotlin projects

Quick Start

Write suspend functions instead of class-wide CoroutineScope properties and migrate init-time launches to explicit bootstrapping points.

Frequently Asked Questions about kotlin-coroutines-structured-concurrency

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why do my Kotlin coroutines leak when I store a CoroutineScope in a class?

Storing a CoroutineScope in a class often causes leaks because the scope outlives the intended lifecycle. You should convert public APIs to suspend functions and relate launches to a clear lifecycle boundary with proper cancellation handling.

What is structured concurrency in Kotlin and how does it prevent unstructured concurrency?

Structured concurrency in Kotlin ensures child coroutines are tied to a specific lifecycle and cannot outlive their parent scope. This prevents unstructured concurrency by enforcing proper cancellation handling and error propagation, avoiding fire-and-forget calls and unmanaged launches.

How do I refactor a Kotlin init block that launches coroutines?

To refactor init-time launches, migrate them to explicit bootstrapping points with clear lifecycle boundaries. Convert class-wide CoroutineScope properties to suspend functions to ensure proper scope ownership and safe cancellation handling.

Can I use fire-and-forget coroutine launches with non-suspending APIs in Kotlin?

Using fire-and-forget calls with non-suspending APIs creates unstructured concurrency and risks leaks. You should convert public APIs to suspend functions and relate launches to a clear lifecycle boundary for proper error propagation.

What are the best practices for Kotlin coroutine scope management to avoid leaks?

Best practices for Kotlin coroutine scope management include avoiding stored scopes in classes, converting public APIs to suspend, and binding launches to explicit lifecycle boundaries. This ensures proper cancellation handling and prevents leaks.