Agent skill

Choosing Derivedstateof

by skydoves in skydoves/compose-performance-skills

A skill your agent uses to decide when Jetpack Compose derivedStateOf is the right tool and when it is pure overhead.

Apache-2.0Auto-check passedMobile

Install Choosing Derivedstateof

skills CLI
$ npx skills add skydoves/compose-performance-skills --skill choosing-derivedstateof -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install skydoves/compose-performance-skills choosing-derivedstateof --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/skydoves/compose-performance-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/recomposition/choosing-derivedstateof .claude/skills/choosing-derivedstateof && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
choosing-derivedstateof
GitHub stars
512
Token cost
~2.9k tokens
SKILL.md length
985 words
Files
1
Skills in repo
2
Repo updated
First seen
Licence
Apache-2.0

At a glance

A skill your agent uses to decide when Jetpack Compose derivedStateOf is the right tool and when it is pure overhead.

  • Decide when Jetpack Compose derivedStateOf is the right tool and when it is pure overhead
  • SKILL.md covers When to use this skill, When NOT to use this skill, Prerequisites and Workflow, plus 4 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • The developer mentions derivedStateOf

What it does

Choosing Derivedstateof is an agent skill from skydoves/compose-performance-skills. Use this skill to decide when Jetpack Compose derivedStateOf is the right tool and when it is pure overhead. Covers the "input frequency must exceed output frequency" rule, the mandatory remember { derivedStateOf { } } wrapper, the canonical pitfall of capturing non-state variables by initial value (and the remember(key) fix), and the snapshotFlow alternative for fire-and-forget side effects on derived values. Use when the developer mentions derivedStateOf, scroll-position-driven booleans, threshold checks…

Its SKILL.md is about 2.9k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Mobile, covering Android development. It works with Jetpack Compose. The repository describes itself as: ⚡️ A curated library of Agent Skills focused on Jetpack Compose performance. The licence is Apache-2.0.

When your agent uses it

  • Decide when Jetpack Compose derivedStateOf is the right tool and when it is pure overhead
  • The developer mentions derivedStateOf
  • Scroll-position-driven booleans
  • Threshold checks

Example prompts

  • “input frequency must exceed output frequency”
  • “show FAB on scroll”
  • “/choosing-derivedstateof”

What it can do on your machine

Read from SKILL.md and the folder at commit 1b32f81. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are kotlin).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • medium.com
    • developer.android.com
    • blog.zachklipp.com

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Choosing Derivedstateof loads about 2.9k tokens when it runs. Until then it costs about 179 tokens; SKILL.md has 985 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~179
When it runs · the whole SKILL.md, loaded when a task matches
~2.9k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from skydoves/compose-performance-skills at commit 1b32f81, republished under its Apache-2.0 licence (© skydoves). 985 words, ~2,937 tokens.

Download SKILL.mdSave it as .claude/skills/choosing-derivedstateof/SKILL.md (or your agent's skills folder).
name
choosing-derivedstateof
description
Use this skill to decide when Jetpack Compose derivedStateOf is the right tool and when it is pure overhead. Covers the "input frequency must exceed output frequency" rule, the mandatory remember { derivedStateOf { } } wrapper, the canonical pitfall of capturing non-state variables by initial value (and the remember(key) fix), and the snapshotFlow alternative for fire-and-forget side effects on derived values. Use when the developer mentions derivedStateOf, scroll-position-driven booleans, threshold checks, firstVisibleItemIndex, "show FAB on scroll", recomposition counts that don't drop after wrapping a value, or asks whether a computed string concatenation should use derivedStateOf.
license
Apache-2.0. See LICENSE for complete terms.
metadata.author
Jaewoong Eum (skydoves)
metadata.keywords
jetpack-compose, performance, recomposition, derivedstateof, snapshotflow, lazylist, scroll-perf, state

Choosing derivedStateOf — Filter Hot Inputs into Cold Outputs

derivedStateOf produces a State whose readers only invalidate when the derived result changes, even if the input states change far more often. Use it when input frequency exceeds output frequency. Use it for any other shape and it is pure overhead — an extra snapshot subscription with no filtering benefit. This skill teaches Claude when to reach for it, when to refuse, and how to avoid the canonical capture-by-initial-value pitfall.

When to use this skill

  • The developer asks whether a value should be wrapped in derivedStateOf.
  • A scroll position drives a boolean (firstVisibleItemIndex == 0, scrollState.value > threshold, "show FAB on scroll").
  • A high-frequency input (drag delta, animation progress) feeds a low-frequency output (boolean threshold, bucketed integer).
  • A derivedStateOf exists in the code but recomposition counts didn't drop, or the value never updates after the first composition (the capture-by-initial-value bug).
  • The developer wants a one-shot side effect (analytics, logging, snackbar) when a derived value flips.

When NOT to use this skill

  • The state read is in the wrong phase (e.g. Modifier.alpha(state.value)). Fix that with ../deferring-state-reads/SKILL.md first — derivedStateOf does not address phase issues.
  • Diagnosing whether a parameter is unstable. That is ../../stability/diagnosing-compose-stability/SKILL.md.
  • Input frequency equals output frequency (e.g. "$first $last" from two name states). derivedStateOf is pure overhead in that case — use a direct read or a plain remember.

Prerequisites

  • Familiarity with state-read-driven recomposition: a snapshot read inside a restartable composable subscribes that composable's restart scope to the state.
  • Compose runtime ≥ 1.0 (the API is foundational; behavior described here is stable).
  • Ability to confirm recomposition counts via Layout Inspector or @TraceRecomposition from skydoves/compose-stability-analyzer.

Workflow

  • 1. Identify the input state(s) and the value the UI actually consumes. Write down both update frequencies. Example: listState.firstVisibleItemIndex (changes every list item scrolled past) → Boolean (changes once when the user crosses index 0).

  • 2. Compare frequencies. Apply the rule:

    • Input updates much more often than output → derivedStateOf is the right tool.
    • Input and output update at roughly the same rate → derivedStateOf adds an extra snapshot subscription for nothing. Use a direct read or a plain remember(input1, input2).
  • 3. Wrap the derivation in remember { derivedStateOf { … } }. A bare derivedStateOf { } would be re-created on every composition, defeating the cache. The remember is mandatory.

  • 4. If the lambda captures non-state variables (function parameters, locals, props), pass them as remember keys. A captured non-state variable is read once at first composition and frozen forever — the derivation will silently use the stale value. The fix is remember(threshold) { derivedStateOf { … > threshold } }.

  • 5. For one-shot side effects on a derived value (logging, analytics, snackbar), prefer snapshotFlow { … }.collect { … } inside LaunchedEffect. That avoids subscribing the composable's restart scope to the derived state; the side effect runs in a coroutine, off the composition path.

  • 6. Verify in Layout Inspector / @TraceRecomposition. The consuming composable's recomposition count MUST only increment when the derived result changes — not on every input tick. If it still climbs per input tick, either (a) the derivedStateOf is missing, (b) the remember is missing, or (c) something else (a sibling state read, a wrong-phase modifier) is invalidating the same scope.

Patterns

Pattern: scroll-to-top FAB — input >> output
kotlin
// WRONG
val showFab = listState.firstVisibleItemIndex > 0
// WRONG because: this reads firstVisibleItemIndex on every recomposition; the consuming composable invalidates per scrolled item, not just when the boolean flips.
kotlin
// RIGHT
val showFab by remember {
    derivedStateOf { listState.firstVisibleItemIndex > 0 }
}

firstVisibleItemIndex updates on every list item scrolled past; showFab only flips when the user crosses index 0. The remember keeps the derived state alive across compositions; the derivedStateOf filters out every input change that does not flip the boolean.

Pattern: pure overhead — input ≈ output
kotlin
// WRONG
val first by remember { mutableStateOf("Ada") }
val last by remember { mutableStateOf("Lovelace") }
val fullName by remember { derivedStateOf { "$first $last" } }
// WRONG because: first and last change at the same rate as fullName; derivedStateOf adds a snapshot subscription with zero filtering benefit.
kotlin
// RIGHT — direct read, no derivedStateOf needed
val first by remember { mutableStateOf("Ada") }
val last by remember { mutableStateOf("Lovelace") }
val fullName = "$first $last"

If a memoization cost concern exists (the concatenation is expensive), use remember(first, last) { computeFullName(first, last) } — derivedStateOf is still the wrong shape because there is nothing to filter.

Show full SKILL.md (399 more words)Show less
Pattern: captured non-state variable — the silent bug
kotlin
// WRONG
@Composable
fun Header(threshold: Int, listState: LazyListState) {
    val isLarge by remember {
        derivedStateOf { listState.firstVisibleItemIndex > threshold }
    }
    // WRONG because: threshold is captured inside remember { ... } at first composition; later threshold changes are ignored, and the derivation reuses the stale value forever.
}
kotlin
// RIGHT — threshold is a remember key, so a new derivedStateOf is created when it changes
@Composable
fun Header(threshold: Int, listState: LazyListState) {
    val isLarge by remember(threshold) {
        derivedStateOf { listState.firstVisibleItemIndex > threshold }
    }
}

The rule: any non-State value captured by the derivedStateOf lambda MUST be a key on the surrounding remember. Otherwise the derivation locks in the value from first composition.

Pattern: one-shot side effect → snapshotFlow
kotlin
// WRONG
@Composable
fun Feed(listState: LazyListState, onScrolledPastFold: () -> Unit) {
    val pastFold by remember {
        derivedStateOf { listState.firstVisibleItemIndex > 5 }
    }
    if (pastFold) onScrolledPastFold()
    // WRONG because: side effects in a composable body run on every (re)composition, can fire multiple times for the same flip, and tie the side effect to the composition lifecycle.
}
kotlin
// RIGHT — fire-and-forget side effect via snapshotFlow
@Composable
fun Feed(listState: LazyListState, onScrolledPastFold: () -> Unit) {
    LaunchedEffect(listState) {
        snapshotFlow { listState.firstVisibleItemIndex > 5 }
            .distinctUntilChanged()
            .filter { it }
            .collect { onScrolledPastFold() }
    }
}

snapshotFlow reads snapshot state inside a coroutine and emits when the read-set's combined value changes. The LaunchedEffect keys the collection to listState, and distinctUntilChanged() ensures one emission per flip. No restart scope is involved — the consuming composable never recomposes for this signal.

Pattern: derive across many inputs to one bucket
kotlin
// RIGHT
val priceBucket by remember {
    derivedStateOf {
        when {
            cartTotal.value < 10_000 -> Bucket.Small
            cartTotal.value < 50_000 -> Bucket.Medium
            else -> Bucket.Large
        }
    }
}

cartTotal may tick by single won/cents; priceBucket flips at most twice across the entire range. This is the canonical use case.

Mandatory rules

  • MUST wrap every derivedStateOf in remember { … }. A bare derivedStateOf { } is re-created every composition and provides no filtering.
  • MUST add captured non-state variables (function parameters, local vals, props) as remember keys. Otherwise the derivation freezes the values from first composition.
  • MUST NOT use derivedStateOf when input and output frequency match. It is pure overhead; use a direct read or remember(keys) { … }.
  • MUST NOT wrap the result of collectAsState() / collectAsStateWithLifecycle() in derivedStateOf "just to be safe" — that adds a subscription layer for nothing. Filter upstream with .distinctUntilChanged() or .map { } on the flow.
  • PREFERRED: snapshotFlow { … } over derivedStateOf for fire-and-forget side effects. It keeps the composition free of the signal entirely.
  • PREFERRED: measure recomposition counts before AND after the change. The whole point of derivedStateOf is to reduce them; if they didn't drop, something else is wrong (often a wrong-phase read — see ../deferring-state-reads/SKILL.md).

Verification

  • Layout Inspector shows the consuming composable recomposes only when the derived result changes (e.g. once when the FAB appears, once when it disappears) — not on every input tick.
  • Every derivedStateOf in the file is inside a remember { … } (or remember(keys) { … }) call.
  • Every derivedStateOf lambda's captured non-state variables appear as remember keys, OR the lambda only reads State objects.
  • Side effects on derived values run via LaunchedEffect { snapshotFlow { … }.collect { } }, not by reading the derived state in the composable body.
  • A grep for derivedStateOf { shows no occurrences where input and output frequencies match (no "$first $last"-shaped uses).

References

© skydoves, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in recomposition/choosing-derivedstateof of skydoves/compose-performance-skills.

Open the folder on GitHubat commit 1b32f81

Compare with similar skills

Choosing Derivedstateof next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Choosing Derivedstateof compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Choosing Derivedstateof this skillskydoves/compose-performance-skills512—~2.9kAutomated safety check: PassApache-2.0
Compose Multiplatform Patternsmonta-app/ocpp-emulator1805 repos~2kAutomated safety check: PassApache-2.0
Deferring State ReadsrosuH/EasyWatermark1.9k1 repos~3.8kAutomated safety check: PassApache-2.0
Android Developmentdpconde/claude-android-skill336—~1.7kAutomated safety check: PassMIT
Footgun Scanmaxrave-dev/kotlin-footguns1k1 repos~518Automated safety check: PassGPL-3.0
Diagnosing Compose StabilityrosuH/EasyWatermark1.9k1 repos~3.3kAutomated safety check: PassApache-2.0

Similar skills

  • Compose Multiplatform Patterns

    monta-app/ocpp-emulator

    Compose Multiplatform and Jetpack Compose patterns for KMP projects — state management, navigation, theming, performance, and platform-specific UI.

    180 GitHub starsUsed in 5 repos~2k tokens
    MobileAuto-check passed
  • Deferring State Reads

    rosuH/EasyWatermark

    A skill your agent uses to push frequently-changing Jetpack Compose state reads (scroll position, animation values, drag offsets) out of the Composition phase and down into Layout or Draw using…

    1.9k GitHub starsUsed in 1 repo~3.8k tokens
    MobileAuto-check passed
  • Android Development

    dpconde/claude-android-skill

    Create production-quality Android applications following Google's official architecture guidance and NowInAndroid best practices.

    336 GitHub stars~1.7k tokensUpdated 10 mo ago
    MobileAuto-check passed
  • Footgun Scan

    maxrave-dev/kotlin-footguns

    Scan a Kotlin or Compose Multiplatform diff for known footgun shapes and open the matching trap to confirm each hit.

    1k GitHub starsUsed in 1 repo~518 tokens
    MobileAuto-check passed
  • Diagnosing Compose Stability

    rosuH/EasyWatermark

    A skill your agent uses to diagnose Jetpack Compose stability problems by enabling and reading the Compose Compiler Reports (classes.txt, composables.txt, composables.csv, module.json).

    1.9k GitHub starsUsed in 1 repo~3.3k tokens
    MobileAuto-check passed
  • Styles

    arindamxd/camerax-android

    A skill your agent uses to integrate the Jetpack Compose Styles API into an Android project.

    132 GitHub starsUsed in 4 repos~2.3k tokens
    MobileAuto-check passed

More from skydoves/compose-performance-skills

  • Collecting Flows Safely

    skydoves/compose-performance-skills

    A skill your agent uses to migrate Compose UI from collectAsState() to collectAsStateWithLifecycle(), hoist Flow<T parameters out of composables, and apply .conflate() / .distinctUntilChanged() /…

    512 GitHub stars~3.1k tokensUpdated 3 mo ago
    Auto-check passed

Works with

Categories

Questions about Choosing Derivedstateof

What does Choosing Derivedstateof do?

A skill your agent uses to decide when Jetpack Compose derivedStateOf is the right tool and when it is pure overhead. Choosing Derivedstateof is an agent skill from skydoves/compose-performance-skills. Use this skill to decide when Jetpack Compose derivedStateOf is the right tool and when it is pure overhead.

When should I use Choosing Derivedstateof?

Choosing Derivedstateof fits situations like: decide when Jetpack Compose derivedStateOf is the right tool and when it is pure overhead; the developer mentions derivedStateOf; scroll-position-driven booleans; threshold checks.

How do I install Choosing Derivedstateof in Claude Code?

Run `npx skills add skydoves/compose-performance-skills --skill choosing-derivedstateof -a claude-code`. Or copy the skill folder (recomposition/choosing-derivedstateof in skydoves/compose-performance-skills) into .claude/skills/choosing-derivedstateof in your project. Claude Code loads it when a task matches its description.

How do I install Choosing Derivedstateof in Codex?

Run `npx skills add skydoves/compose-performance-skills --skill choosing-derivedstateof -a codex`. Or copy the skill folder (recomposition/choosing-derivedstateof in skydoves/compose-performance-skills) into .agents/skills/choosing-derivedstateof in your project. Codex loads it when a task matches its description.

Can I use Choosing Derivedstateof in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add skydoves/compose-performance-skills --skill choosing-derivedstateof -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/choosing-derivedstateof, .gemini/skills/choosing-derivedstateof, .github/skills/choosing-derivedstateof and .opencode/skills/choosing-derivedstateof in your project.

What does Choosing Derivedstateof need to run?

SKILL.md names no scripts, command-line tools or credentials: Choosing Derivedstateof is instructions for the agent only.

Does Choosing Derivedstateof access the network?

SKILL.md names 3 domains. As links in the text: medium.com, developer.android.com and blog.zachklipp.com. This is read from the text; nothing was executed.

Is Choosing Derivedstateof safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Choosing Derivedstateof use?

Choosing Derivedstateof is published under the Apache-2.0 licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Choosing Derivedstateof use?

About 2.9k tokens (SKILL.md is roughly 12k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Choosing Derivedstateof?

Skills that share tags, products or a category with Choosing Derivedstateof: Compose Multiplatform Patterns (monta-app/ocpp-emulator, 180 stars), Deferring State Reads (rosuH/EasyWatermark, 1.9k stars), Android Development (dpconde/claude-android-skill, 336 stars) and Footgun Scan (maxrave-dev/kotlin-footguns, 1k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Choosing Derivedstateof?

skydoves (a GitHub user) maintains it in skydoves/compose-performance-skills, which has 512 GitHub stars. The repository holds 2 skills in this directory. The repository was last updated on June 16, 2026.

Source: skydoves/compose-performance-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.