kotlin-coroutines
Standards for safe, structured concurrency in Kotlin. Use when writing suspend functions, choosing coroutine scopes, handling cancellation in loops, selecting between StateFlow and SharedFlow, debugging coroutine leaks, or asked why GlobalScope is dangerous. (triggers: **/*.kt, suspend, CoroutineScope, launch, async, Flow, StateFlow, SharedFlow, viewModelScope, GlobalScope, Dispatchers, isActive, yield, runBlocking)
Best use case
kotlin-coroutines is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Standards for safe, structured concurrency in Kotlin. Use when writing suspend functions, choosing coroutine scopes, handling cancellation in loops, selecting between StateFlow and SharedFlow, debugging coroutine leaks, or asked why GlobalScope is dangerous. (triggers: **/*.kt, suspend, CoroutineScope, launch, async, Flow, StateFlow, SharedFlow, viewModelScope, GlobalScope, Dispatchers, isActive, yield, runBlocking)
Teams using kotlin-coroutines should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/kotlin-coroutines/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How kotlin-coroutines Compares
| Feature / Agent | kotlin-coroutines | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Standards for safe, structured concurrency in Kotlin. Use when writing suspend functions, choosing coroutine scopes, handling cancellation in loops, selecting between StateFlow and SharedFlow, debugging coroutine leaks, or asked why GlobalScope is dangerous. (triggers: **/*.kt, suspend, CoroutineScope, launch, async, Flow, StateFlow, SharedFlow, viewModelScope, GlobalScope, Dispatchers, isActive, yield, runBlocking)
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Kotlin Coroutines Expert
## **Priority: P0 (CRITICAL)**
**You are a Concurrency Expert.** Prioritize safety and cancellation support.
## Implementation Guidelines
- **Scope**: Use `viewModelScope` (Android) or structured `coroutineScope`.
- **Dispatchers**: Inject dispatchers; never hardcode `Dispatchers.IO`.
- **Flow**: Use `StateFlow` for state, `SharedFlow` for events.
- **Exceptions**: Use `runCatching` or `CoroutineExceptionHandler`.
## Concurrency Checklist (Mandatory)
- [ ] **Cancellation**: Do loops check `isActive` or call `yield()`?
- [ ] **Structured**: No `GlobalScope`? All children joined/awaited?
- [ ] **Context**: Is `Dispatchers.Main` used for UI updates?
- [ ] **Leaks**: Are scopes cancelled in `onCleared` / `onDestroy`?
## Anti-Patterns
- **No GlobalScope**: It leaks. Use structured concurrency.
- **No Async without Await**: Don't `async { ... }` without `await()`.
- **No Blocking**: Never `runBlocking` in prod code (only tests).
## References
- [Advanced Patterns & Flow Examples](references/advanced-patterns.md)Related Skills
kotlin-springboot
Get best practices for developing applications with Spring Boot and Kotlin.
kotlin-mcp-server-generator
Generate a complete Kotlin MCP server project with proper structure, dependencies, and implementation using the official io.modelcontextprotocol:kotlin-sdk library.
create-spring-boot-kotlin-project
Create Spring Boot Kotlin Project Skeleton
apollo-kotlin
Guide for building applications with Apollo Kotlin, the GraphQL client library for Android and Kotlin. Use this skill when: (1) setting up Apollo Kotlin in a Gradle project for Android, Kotlin/JVM, or KMP, (2) configuring schema download and codegen for GraphQL services, (3) configuring an `ApolloClient` with auth, interceptors, and caching, (4) writing queries, mutations, or subscriptions,
kotlin-coroutines-expert
Expert patterns for Kotlin Coroutines and Flow, covering structured concurrency, error handling, and testing.
kotlin-testing
Kotlin testing patterns with Kotest, MockK, coroutine testing, property-based testing, and Kover coverage. Follows TDD methodology with idiomatic Kotlin practices.
kotlin-patterns
Idiomatic Kotlin patterns, best practices, and conventions for building robust, efficient, and maintainable Kotlin applications with coroutines, null safety, and DSL builders.
kotlin-ktor-patterns
Ktor server patterns including routing DSL, plugins, authentication, Koin DI, kotlinx.serialization, WebSockets, and testApplication testing.
kotlin-exposed-patterns
JetBrains Exposed ORM patterns including DSL queries, DAO pattern, transactions, HikariCP connection pooling, Flyway migrations, and repository pattern.
kotlin-coroutines-flows
Kotlin Coroutines and Flow patterns for Android and KMP — structured concurrency, Flow operators, StateFlow, error handling, and testing.
Kotlin Multiplatform — Shared Business Logic for Mobile
## Overview
kotlin-tooling
Standards for Gradle Kotlin DSL, Version Catalogs, and MockK for Kotlin projects. Use when configuring build.gradle.kts, setting up libs.versions.toml, adding MockK for tests, or choosing between Kotlin-compatible test assertion libraries. (triggers: build.gradle.kts, libs.versions.toml, detekt.yml, mockk, kts, version catalog, kotest)