kotlin-concurrency-expert

Analyze Kotlin coroutines in Android projects for unsafe patterns and lifecycle risks.

Updated Feb 16, 2026
One-click install
npx skills add https://github.com/esteban389/workout --skill kotlin-concurrency-expert-esteban389
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-concurrency-expert
Source: https://github.com/esteban389/workout/tree/main/.agents/skills/kotlin-concurrency-expert
Command: npx skills add https://github.com/esteban389/workout --skill kotlin-concurrency-expert-esteban389

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Kotlin coroutines in Android can suffer from lifecycle leaks, ANRs, and improper cancellation if scopes and dispatchers are misused, leading to unstable apps.

Core Features & Use Cases

  • Review and remediate coroutine usage across Android components (ViewModel, Activity, Fragment) to enforce structured concurrency.
  • Replace hard-coded or global scopes with lifecycle-aware scopes; encapsulate state flows; ensure proper cancellation handling; provide testable patterns and guidelines for scalable async work.
  • Real-world use case: refactor a repository or UI layer that spawns coroutines on GlobalScope to instead use viewModelScope with proper dispatcher and lifecycle safety.

Quick Start

Ask it to review your Android project’s coroutines usage and propose a safe, minimal-change remediation plan.

Frequently Asked Questions about kotlin-concurrency-expert

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

FAQPage Schema
Why do my Kotlin coroutines leak memory or cause ANRs in my Android app?

Kotlin coroutines cause Android lifecycle leaks and ANRs when scopes and dispatchers are misused. Analyzing your codebase identifies unsafe patterns like GlobalScope usage, replacing them with lifecycle-aware scopes to ensure proper cancellation and thread safety.

How do I replace GlobalScope with viewModelScope in Android?

To replace GlobalScope with viewModelScope in Android, refactor your coroutine launching to use lifecycle-bound scopes. This enforces structured concurrency, ensuring coroutines cancel automatically when the ViewModel clears, preventing UI responsiveness issues.

What is the best way to encapsulate MutableStateFlow in Kotlin Android?

The best way to encapsulate MutableStateFlow in Kotlin Android is to expose immutable StateFlow externally while mutating private MutableStateFlow internally. This pattern secures thread safety and prevents external lifecycle components from emitting unauthorized state changes.

How do I use repeatOnLifecycle for Android coroutines?

Use repeatOnLifecycle for Android coroutines to safely collect flows from Activities or Fragments. This lifecycle-aware function suspends and restarts collection based on lifecycle states, preventing background emissions and reducing unnecessary battery or processing drain.

Can I inject testable Dispatchers in Android coroutine projects?

Yes, you can inject testable Dispatchers in Android coroutine projects. By abstracting Dispatchers through dependency injection rather than hard-coding them, you gain reliable testing capabilities and ensure structured concurrency across your ViewModel and repository layers.

When should I not use GlobalScope in Kotlin Android coroutines?

You should not use GlobalScope in Kotlin Android coroutines when operations are tied to UI or business logic lifecycles. GlobalScope outlives components causing leaks; use viewModelScope or lifecycleScope to guarantee proper cancellation and thread safety.