kotlin-coroutines-skill

kotlin-coroutines-skill is a skill for Claude Code, Codex from santimattius/structured-coroutines. It costs 71 tokens per session (5,631 once invoked), scanned A, original, Apache-2.0.

A guide for writing and reviewing Kotlin coroutine code, which runs tasks that can pause and resume without blocking a thread. It focuses on safe concurrency, cancellation, errors, data streams, Android lifecycles, and testing.

In plain words
What is it for?
Use it when writing, reviewing, or debugging Kotlin coroutines, Flow streams, timeouts, dispatchers, exception handling, lifecycle-aware Android code, or coroutine tests.
Why use it?
It helps identify leaks, blocked threads, incorrect thread choices, lost errors, broken cancellation, and other bugs in asynchronous Kotlin code.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: mentions Claude Code.

Part of the kotlin-coroutines-skill plugin — 1 skill shipped together

Good fit Use it when writing, reviewing, or debugging Kotlin coroutines, Flow streams, timeouts, dispatchers, exception handling, lifecycle-aware Android code, or coroutine tests.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/santimattius/structured-coroutines/kotlin-coroutines-skill
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 santimattius/structured-coroutines --skill kotlin-coroutines-skill
Clone the repo
git clone --depth 1 https://github.com/santimattius/structured-coroutines

Made for: Claude Code, Codex.

Or install kotlin-coroutines-skill, the plugin that ships this one along with the rest of its 1 skill.

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-skill

README.md
[![agentmods](https://agentmods.dev/badge/skills/santimattius/structured-coroutines/kotlin-coroutines-skill/github.svg)](https://agentmods.dev/skills/santimattius/structured-coroutines/kotlin-coroutines-skill)
Your own site
<a href="https://agentmods.dev/skills/santimattius/structured-coroutines/kotlin-coroutines-skill"><img src="https://agentmods.dev/badge/skills/santimattius/structured-coroutines/kotlin-coroutines-skill/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-skill

Your own site · 80×15
<a href="https://agentmods.dev/skills/santimattius/structured-coroutines/kotlin-coroutines-skill"><img src="https://agentmods.dev/badge/skills/santimattius/structured-coroutines/kotlin-coroutines-skill.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 71 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 5,631 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. Third-party audits
  • NVIDIA SkillSpector warn 7 Sept 2026
SkillSpector: 1 finding, up to medium

These are SkillSpector’s own severities. On a checked sample its high-severity flags on skills were ~96% false positives — a documented command, a public API, a “never do X” rule — so we show them as a caution to read, not a verdict. Why →

  • medium Prompt Injection · line 109
    Large whitespace padding was detected (a block of blank lines or a long run of spaces). This can push injected instructions below or to the right of the visible area so a human reviewer never sees them while the agent still reads them. Manual review of the hidden content is recommended.
    Fix: Remove the large whitespace padding (blank-line blocks or long space runs) and review any content hidden below or to the right of it. Keep skill files compact and reviewable so no instructions can be
How audits are shown
Origin original No closer match found 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.00071 $0.05631
Opus 5 $0.00036 $0.02815
Sonnet 5 $0.00014 $0.01126
Haiku 4.5 $0.00007 $0.00563

Measured 11d ago against content hash 900338b0fca2, 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-skill 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 11d 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.

kotlin-coroutines-skill/SKILL.md · 318 lines

How it starts

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

Kotlin Coroutines

Overview

This skill provides expert guidance on Kotlin Coroutines, covering structured concurrency, scopes, Dispatchers (including main-safe suspend and dispatcher injection), cancellation (including withTimeout semantics), exception handling (CoroutineExceptionHandler, launch vs async), Channels, Flow (cold vs hot, collectLatest, SharedFlow configuration, blocking in flow {}), lifecycle-aware collection on Android, and testing (virtual time, setMain/resetMain). Use this skill to help developers write safe, maintainable concurrent code aligned with Kotlin 1.9+/2.0+ conventions and official best practices.

Agent Behavior Contract (Follow These Rules)

  1. Identify the practice or error from the user's code or question (e.g. GlobalScope, runBlocking in suspend, swallowing CancellationException) and open the corresponding reference from the Triage table in references/.
  2. Apply the strict rules below in every response. Do not suggest or leave code that violates them.
  3. Respond in the required format: Analysis → Erroneous code → Optimized code → Explanation. If the user only asks a conceptual question (no code), skip erroneous/optimized snippets and focus on analysis and explanation.
  4. Do not recommend GlobalScope in production. Use framework scopes (viewModelScope, lifecycleScope, rememberCoroutineScope), injected scopes, or local scopes ( coroutineScope { }, withContext { }). If an external scope is required, justify and document it.
  5. Use async only when a return value is needed; if await() is never called, use launch. Preserve structured concurrency: inside suspend functions use coroutineScope { } + async/ launch; do not launch in an external scope from suspend unless work must outlive the flow, and then document it.
  6. Never use runBlocking inside suspend functions or coroutine-based code. Avoid ending a suspend function with coroutineScope { launch { } } as the last line when the intent is fire-and-forget — coroutineScope waits for all children and blocks the caller; use an explicit external scope and document it if the work must truly run in the background beyond the caller's lifetime.
  7. Use explicit Dispatchers: Dispatchers.Default for CPU-bound work, Dispatchers.Main/ Main.immediate for UI, withContext(Dispatchers.IO) for blocking I/O. Never perform blocking I/O on Default or Main. Do not use Dispatchers.Unconfined in production unless for a rare, documented case. Make suspend functions main-safe: move blocking work into withContext(Dispatchers.IO) so callers on Main are never blocked. Inject CoroutineDispatcher as a constructor parameter (default to real dispatcher; replace with TestDispatcher in tests).
  8. Never pass Job() or SupervisorJob() directly to builders (e.g. launch(Job()) { }). Use supervisorScope { } or a scope defined with SupervisorJob() for supervisor semantics. When running independent tasks with awaitAll, use supervisorScope instead of coroutineScope so one failure does not cancel sibling deferreds.
  9. Cancellation handling (apply all):
    • Never swallow CancellationException; rethrow it in catch blocks.
    • Do not use CancellationException for domain errors; use normal exceptions instead.
    • In long loops and repeating/polling work, add yield(), ensureActive(), or while (isActive) with delay(interval) so the coroutine responds to cancellation.
    • For suspend calls in finally, use withContext(NonCancellable) { }.
    • Do not reuse a scope after scope.cancel(); use coroutineContext.job.cancelChildren() to stop only children while keeping the scope alive.
    • Prefer withTimeoutOrNull over withTimeout to avoid unintentionally cancelling the parent scope. If using withTimeout, catch TimeoutCancellationException explicitly. Always ensure resources opened inside withTimeout are cleaned up in finally.
  10. Exception handling:
    • Uncaught exceptions in launch propagate to CoroutineExceptionHandler; in async, the exception is stored in the Deferred and only thrown on await(). Always call await() on async blocks to avoid silently losing exceptions.
    • Use CoroutineExceptionHandler at scope level for launch uncaught exceptions.
  11. In tests use kotlinx-coroutines-test: runTest, virtual time, advanceTimeBy, advanceUntilIdle, and inject TestDispatcher/StandardTestDispatcher; avoid real delay() with runBlocking. Replace Dispatchers.Main using Dispatchers.setMain(TestDispatcher()) in @Before and Dispatchers.resetMain() in @After.
  12. Prefer produce { } for channels so they close when the coroutine ends. Do not share consumeEach across multiple consumers; use for (x in channel) per consumer.
  13. Flow best practices:
    • Keep flow { } builder non-blocking; use flowOn(Dispatchers.IO) or suspend APIs.
    • Use StateFlow for shared UI state (replays last value); use SharedFlow for events with explicit replay, extraBufferCapacity, and onBufferOverflow configuration.
    • Use collectLatest only when cancelling in-progress work is intentional (e.g. search); use collect when each item must be processed to completion.
    • On Android, collect flows with repeatOnLifecycle(Lifecycle.State.STARTED) or flowWithLifecycle to stop collection when the UI goes to background.
  14. When several practices apply (e.g. GlobalScope + wrong Dispatchers), use each relevant reference and combine the fixes in one optimized snippet.

Read the full file on GitHub · 318 lines

Files

What ships with it

59 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 11d ago First seen · 318 lines · 71 tokens per session scan A 900338b0fca2

Subscribe to this mod's changes

kotlin-coroutines-skill is a skill published in the GitHub repository santimattius/structured-coroutines (147 stars, last pushed today), licensed Apache-2.0. It adds 71 tokens to every session and 5,631 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

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