kotlin-concurrency-and-flow — Claude Code skill: coroutines and Flow
A skill for writing and reviewing Kotlin coroutine code: scope ownership, cancellation, StateFlow, SharedFlow and Channel.
npx skills add chrisbanes/skills --skill kotlin-concurrency-and-flow -a claude-codeWhat kotlin-concurrency-and-flow does
The skill fires when you write or review Kotlin code that touches coroutines: CoroutineScope ownership, raw Thread or Executor work, init { launch }, runBlocking, cancellation, plus StateFlow, SharedFlow, Channel, stateIn and SharingStarted.
It walks through a seven-step procedure. First you map every coroutine owner, cancellation boundary, producer, consumer, durable state and transient event. Then it tells you to compare the API's existing caller-visible contract against the required owner and lifetime: if a suspend function already hands cancellation, result and failure to its caller, leave it alone. Picking the right primitive gets its own step. A Channel delivers each event to one consumer; a configured SharedFlow broadcasts to active consumers. For a one-consumer navigation handoff that must survive a collector gap, the skill points to Channel(Channel.BUFFERED) exposed as receiveAsFlow().
A topic router sends structured-concurrency signals to references/structured-concurrency.md and state-or-event questions to references/flow-state-events.md. To validate a change it routes you to ../gradle-run/SKILL.md and rules out running ./gradlew directly. Compose collection and UI effects belong to the neighbouring compose-state-and-effects skill. Install runs through npx skills add.
What it helps with
- trace who owns a coroutine and when it gets cancelled
- strip fire-and-forget
launchout from behind a plain function - pick between
ChannelandSharedFlowfor one-shot events - check whether an event is lost during a collector gap
- decide if
stateInis needed and whichSharingStartedfits
Example prompts for the agent
- Review this ViewModel: who owns the scope and what happens on cancellation?
- Should this be a
SharedFlowor aChannel(Channel.BUFFERED)? - Check the state updates for a race between
_state.valueandstateIn.
How to install kotlin-concurrency-and-flow
1Skills CLI (Vercel)
npx skills add chrisbanes/skills --skill kotlin-concurrency-and-flow -a claude-code2Manually: put the files in place
~/.claude/skills/kotlin-concurrency-and-flow/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/kotlin-concurrency-and-flow/
1Skills CLI (Vercel)
npx skills add chrisbanes/skills --skill kotlin-concurrency-and-flow -a codex2Manually: put the files in place
.agents/skills/kotlin-concurrency-and-flow/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add chrisbanes/skills --skill kotlin-concurrency-and-flow -a cursor2Manually: put the files in place
.cursor/skills/kotlin-concurrency-and-flow/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install chrisbanes/skills kotlin-concurrency-and-flow2Manually: put the files in place
.github/skills/kotlin-concurrency-and-flow/SKILL.md1Skills CLI (Vercel)
npx skills add chrisbanes/skills --skill kotlin-concurrency-and-flow -a gemini-cli2Platform CLI
gemini skills install https://github.com/chrisbanes/skills --path skills/kotlin-concurrency-and-flowManually: put the files in place
.devin/skills/kotlin-concurrency-and-flow/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add chrisbanes/skills --skill kotlin-concurrency-and-flow -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about kotlin-concurrency-and-flow
How do I install kotlin-concurrency-and-flow in Claude?
Run npx skills add chrisbanes/skills --skill kotlin-concurrency-and-flow -a claude-code. The skill file lands at ~/.claude/skills/kotlin-concurrency-and-flow/SKILL.md.
What does kotlin-concurrency-and-flow do?
It guides writing and reviewing Kotlin coroutine code: scope ownership, cancellation boundaries, and the choice between durable state and transient events in Flow.
How does the skill distinguish Channel from SharedFlow?
A Channel hands each event to one consumer, while a configured SharedFlow broadcasts to every active consumer. When the consumer contract is unknown, the skill asks you to settle that first.
Source text
SKILL.md · Apache-2.0
---
name: kotlin-concurrency-and-flow
description: Use when writing or reviewing Kotlin coroutine scope ownership, raw Thread or Executor work, init launches, non-suspending launch APIs, runBlocking, cancellation, StateFlow, SharedFlow, Channel, stateIn, SharingStarted, state updates, or one-shot events.
---
# Kotlin concurrency and Flow
## Core principle
Give asynchronous work an explicit owner and lifetime, then model durable state
and transient events with primitives whose delivery and replay semantics match
the product contract.
## Procedure
1. Identify each coroutine owner, cancellation boundary, producer, consumer,
durable state, and transient event.
2. Before changing an API, compare its existing caller-visible contract with
the required owner and lifetime. If a suspend API already gives its caller
cancellation, result, and failure ownership, finish with no change; do not
add a scope, `launch`, callback, or deferred wrapper merely for convenience.
3. Select a scope whose lifecycle owns the work; do not retain arbitrary scopes
or hide unstructured launches behind non-suspending APIs.
4. Model renderable, current data as state and imperative one-shot work as an
event only when its loss and replay behavior are explicitly acceptable.
Ask whether one consumer handles each event or every active consumer must
receive it. A `Channel` hands each event to one consumer; a configured
`SharedFlow` broadcasts to active consumers. If that consumer contract is
unknown, state both options and the decision needed before choosing one.
For a one-consumer navigation handoff that must survive a collector gap,
choose a bounded `Channel(Channel.BUFFERED)` (not `UNLIMITED`) exposed as
`receiveAsFlow()`; do not preserve a
replay-zero `SharedFlow` after identifying event loss as the defect.
5. Choose Flow sharing and buffering semantics from the producer and consumer
lifetimes rather than from a default.
6. Read the focused reference for the material concern below.
7. Finish when cancellation, restart, replay, and failure behavior are all
observable from the public API and no caller must guess who owns the work.
## Topic router
| Signal | Read |
|---|---|
| Stored `CoroutineScope`, raw `Thread` or `Executor` work, `init { launch }`, fire-and-forget API, `runBlocking`, broad catch, or cancellation boundary | [Structured concurrency](references/structured-concurrency.md) |
| `StateFlow`, `SharedFlow`, `Channel`, `stateIn`, `SharingStarted`, `.value`, state updates, sentinel values, or one-shot events | [Flow state and events](references/flow-state-events.md) |
| Running Gradle to validate a change | [Gradle run](../gradle-run/SKILL.md); never raw `./gradlew` |
| Compose collection or UI effect handling | [Compose state and effects](../compose-state-and-effects/SKILL.md) |
© chrisbanes · Apache-2.0 · chrisbanes/skills