kotlin-coroutines-structured-concurrency

kotlin-coroutines-structured-concurrency is a skill for Claude Code, Codex from ashtanko/compose-android-template. It costs 42 tokens per session (5,273 once invoked), scanned A, a copy of kotlin-coroutines-structured-concurrency, MIT.

A guide for organizing Kotlin coroutines, which are Kotlin's way to run asynchronous work. It focuses on making the code's lifetime, cancellation, errors, and ownership clear.

In plain words
What is it for?
Use it when reviewing stored `CoroutineScope` values, launches in `init`, non-suspending functions that launch work, `runBlocking`, or broad catches around suspend calls.
Why use it?
It helps avoid background work that outlives the object or cannot be cancelled correctly. It also identifies unsafe patterns such as stored coroutine scopes, broad exception handling, and `runBlocking` in code that can already be asynchronous.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: installed under .agents/ (shared by several agents).

Good fit Use it when reviewing stored CoroutineScope values, launches in init, non-suspending functions that launch work, runBlocking, or broad catches around suspend calls.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/ashtanko/compose-android-template/kotlin-coroutines-structured-concurrency
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add ashtanko/compose-android-template --skill kotlin-coroutines-structured-concurrency
Clone the repo
git clone --depth 1 https://github.com/ashtanko/compose-android-template

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for kotlin-coroutines-structured-concurrency

README.md
[![agentmods](https://agentmods.dev/badge/skills/ashtanko/compose-android-template/kotlin-coroutines-structured-concurrency/github.svg)](https://agentmods.dev/skills/ashtanko/compose-android-template/kotlin-coroutines-structured-concurrency)
Your own site
<a href="https://agentmods.dev/skills/ashtanko/compose-android-template/kotlin-coroutines-structured-concurrency"><img src="https://agentmods.dev/badge/skills/ashtanko/compose-android-template/kotlin-coroutines-structured-concurrency/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for kotlin-coroutines-structured-concurrency

Your own site · 80×15
<a href="https://agentmods.dev/skills/ashtanko/compose-android-template/kotlin-coroutines-structured-concurrency"><img src="https://agentmods.dev/badge/skills/ashtanko/compose-android-template/kotlin-coroutines-structured-concurrency.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 42 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 5,273 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin 91% copy Near-identical to another mod in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00042 $0.05273
Opus 5 $0.00021 $0.02636
Sonnet 5 $0.00008 $0.01055
Haiku 4.5 $0.00004 $0.00527

Measured 10d ago against content hash c4bf2985ec7c, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-10, from the pricing page.

Security

Grade A, and why

kotlin-coroutines-structured-concurrency scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 10d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

This is a copy

91% identical to kotlin-coroutines-structured-concurrency — 5 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

.agents/skills/kotlin-coroutines-structured-concurrency/SKILL.md · 441 lines

How it starts

The opening of the file, as written. The whole thing — 441 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Kotlin coroutines: structured concurrency

Core principle

A well-structured coroutine is a self-contained unit of asynchronous work — single entry, single exit, scoped to a lifecycle known at the call site.

Scopes should usually be tied to the caller's lifecycle, not stored as a property on the callee. A stored CoroutineScope is a strong review signal: the class must prove it owns cancellation, error reporting, restart behavior, and lifecycle. Most repositories, managers, use cases, and data sources cannot prove that, so they should expose suspend APIs instead.

The fix is almost always the same: make the API suspend and let the caller own the scope.

When to use this skill

You're writing or reviewing Kotlin code and you see any of these:

  • A class with private val scope: CoroutineScope (constructor param stored as a property)
  • An init { scope.launch { ... } } block
  • A non-suspending public function whose body is scope.launch { ... }
  • runBlocking { ... } in suspend-capable application code, or in tests where runTest should apply
  • runCatching { suspendCall() } or a catch on Exception / Throwable around a suspend call without rethrowing CancellationException
  • A catch (e: CancellationException) (or equivalent) around suspension that does not rethrow

The silent-cancellation bug

The reason an unowned CoroutineScope property is so dangerous: once a scope is cancelled, every future launch on it silently completes as cancelled — no exception, no log, nothing. The work just doesn't happen. This is one of the hardest coroutine bugs to diagnose, and it appears when a class holds a long-lived reference to a lifecycle it does not own.

If APIs are suspend, this can't happen: the caller's scope is either alive (work runs) or the call site cancels (the caller knows).

Anti-patterns and fixes

1. CoroutineScope stored as a property

// ❌ BAD
@Inject
class UserRepository(
    private val scope: CoroutineScope,
    private val api: UserApi,
) {
    fun refresh() {
        scope.launch { _state.value = api.fetchUser() }
    }
}

// ✅ GOOD
@Inject
class UserRepository(
    private val api: UserApi,
) {
    suspend fun refresh(): User = api.fetchUser()
}

Read the full file on GitHub · 441 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 10d ago First seen · 441 lines · 42 tokens per session scan A c4bf2985ec7c

Subscribe to this mod's changes

kotlin-coroutines-structured-concurrency is a skill published in the GitHub repository ashtanko/compose-android-template (10 stars, last pushed 6d ago), licensed MIT. It adds 42 tokens to every session and 5,273 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. It is 91% identical to kotlin-coroutines-structured-concurrency, differing in 5 lines, and is treated as a copy.

Related

Other skills, from other repositories

compose-animations

Use when writing or reviewing Jetpack Compose motion: visibility enter/exit, animating one property toward a target, color or size transitions, multiple properties from one state, switching composable content, or choosing between AnimatedVisibility, animateAsState, rememberTransition, AnimatedContent, and Crossfade.

chrisbanes/skills · 64 tokens

compose-focus-navigation

Use when writing or reviewing Jetpack Compose UI for TV, keyboard, desktop, accessibility focus, D-pad navigation, FocusRequester, focusProperties, key events, or initial focus behavior.

chrisbanes/skills · 41 tokens

kotlin-control-flow

Use when writing or reviewing Kotlin branching and control flow: when expressions, guard conditions, sealed type exhaustiveness, smart casts, nullable branching, early returns, or replacing complex if/else chains.

chrisbanes/skills · 44 tokens

release-kotlin-library

Use when preparing, publishing, or checking readiness for a new Kotlin library version in a repository using gradle-maven-publish-plugin, including release changelog reconciliation, API snapshots, and publication verification.

chrisbanes/skills · 45 tokens

using-chrisbanes-skills

Use when debugging, benchmarking, or profiling leads into Kotlin or Jetpack Compose source before the cause is known, or when one task spans multiple Kotlin or Compose concerns, especially plain Kotlin Flow or navigation delivery plus sealed branching.

chrisbanes/skills · 52 tokens

kotlin-concurrency-and-flow

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.

chrisbanes/skills · 60 tokens