kotlin-concurrency-expert

Audit Kotlin coroutine usage for threading and lifecycle issues in Android apps.

Updated Dec 4, 2025
One-click install
npx skills add https://github.com/thinhtt264/Snaplet-App --skill kotlin-concurrency-expert
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-concurrency-expert
Source: https://github.com/thinhtt264/Snaplet-App/tree/main/.cursor/skills/kotlin-concurrency-expert
Command: npx skills add https://github.com/thinhtt264/Snaplet-App --skill kotlin-concurrency-expert

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps Android developers review and remediate Kotlin Coroutine usage to improve thread safety, lifecycle alignment, and non-blocking behavior.

Core Features & Use Cases

  • Audit and refactor coroutine usage for structured concurrency and proper scope management.
  • Enforce lifecycle safety with viewModelScope, lifecycleScope, and repeatOnLifecycle.
  • Improve cancellation handling and state encapsulation (StateFlow) to prevent leaks and crashes.
  • Use case: When debugging a crash caused by a leaked GlobalScope coroutine in a long-running activity.

Quick Start

Ask the Kotlin concurrency expert to audit the Android module at path app/src/main for coroutine usage issues and propose the smallest safe refactor to enforce structured concurrency and proper lifecycle safety.

Frequently Asked Questions about kotlin-concurrency-expert

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

FAQPage Schema
How do I fix GlobalScope coroutine leaks in Android?

Fix GlobalScope coroutine leaks by replacing them with viewModelScope or lifecycleScope to enforce structured concurrency. Auditing your Android module ensures proper scope management and prevents leaked background tasks when activities are destroyed.

How do I ensure lifecycle safety with Kotlin coroutines and StateFlow?

Ensure lifecycle safety with Kotlin coroutines by applying repeatOnLifecycle for StateFlow collection. This guarantees state encapsulation and proper cancellation, preventing crashes when users navigate away from your Android UI-heavy modules.

What is structured concurrency in Kotlin and when do I need it?

Structured concurrency in Kotlin is a pattern where coroutines are scoped to specific lifecycles, ensuring automatic cancellation and thread safety. You need it in Android apps to prevent memory leaks and crashes from unmanaged background tasks.

Can I use viewModelScope and lifecycleScope for dispatcher refactoring?

Yes, you can use viewModelScope and lifecycleScope for dispatcher refactoring. Auditing coroutine usage ensures proper dispatcher alignment for thread safety, enforcing non-blocking behavior and correct cancellation within your Android lifecycle boundaries.

Why does my Android app crash from leaked coroutines during background tasks?

Your Android app crashes from leaked coroutines because unscoped background tasks continue running after lifecycle destruction. Refactoring to structured concurrency with proper cancellation and StateFlow encapsulation prevents these leaks and stabilizes your app.