Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add chrisbanes/skills --skill kotlin-concurrency-and-flow -a claude-code
Open on GitHub

What 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 launch out from behind a plain function
  • pick between Channel and SharedFlow for one-shot events
  • check whether an event is lost during a collector gap
  • decide if stateIn is needed and which SharingStarted fits

Example prompts for the agent

  • Review this ViewModel: who owns the scope and what happens on cancellation?
  • Should this be a SharedFlow or a Channel(Channel.BUFFERED)?
  • Check the state updates for a race between _state.value and stateIn.

How to install kotlin-concurrency-and-flow

1Skills CLI (Vercel)

npx skills add chrisbanes/skills --skill kotlin-concurrency-and-flow -a claude-code

2Manually: put the files in place

~/.claude/skills/kotlin-concurrency-and-flow/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/kotlin-concurrency-and-flow/

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

Similar skills

All skills for Programming languages →

From the same set17

compose-ui-testing-patterns Guides Jetpack Compose UI testing for semantics, screenshots, keyboard input, focus, and interaction state. CX Codex +1 2,200installs compose-focus-navigation This skill guides focus navigation in Jetpack Compose for TV, keyboards, desktop, accessibility, and D-pad input. It helps with initial and restored focus. CX Codex +1 1,900installs compose-animations Helps write and review Jetpack Compose motion across common UI states. Useful when picking between AnimatedVisibility, AnimatedContent, animate*AsState, and rememberTransition. CX Codex +1 1,800installs shepherd Monitors open pull requests and merge requests, triages review feedback, addresses CI failures, and batches local fixes. CX Codex +1 1,200installs compose-performance A skill for investigating Jetpack Compose recomposition cost: find the phase causing the work and fix it at the boundary where it starts. CX Codex +1 1,100installs compose-state-and-effects This skill guides state ownership and side-effect choices in Jetpack Compose. It keeps UI state at the lowest responsible layer and matches effect lifecycles to their owners. CX Codex +1 1,100installs using-chrisbanes-skills Reads a Kotlin or Jetpack Compose task and loads the right skill from the chrisbanes set. Useful when several concerns overlap in one change. CX Codex +1 1,100installs kotlin-control-flow A skill that steers your coding agent through Kotlin branching: when expressions, guard conditions, sealed-type exhaustiveness, smart casts. CX Codex +1 1,100installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor