compose-anti-patterns

compose-anti-patterns is a cursor rule for coding agents from RoninForge/roninforge-kotlin-compose. It costs 2,163 tokens per session, scanned A, original, MIT.

A checklist of common mistakes in Android apps built with Kotlin and Jetpack Compose. It gives incorrect patterns and their preferred replacements.

In plain words
What is it for?
Use it to review Compose code for lifecycle problems, unsafe values, outdated Material imports, missing list keys, and incorrect side effects.
Why use it?
It catches code that can leak resources, behave incorrectly when screens change, or mix old XML-based Android UI with Compose. It also flags patterns that make lists and screen updates unreliable.

Cursor rule

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.

agentmods
npx agentmods add rules/roninforge/roninforge-kotlin-compose/compose-anti-patterns
Clone the repo
git clone --depth 1 https://github.com/RoninForge/roninforge-kotlin-compose

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 compose-anti-patterns

README.md
[![agentmods](https://agentmods.dev/badge/rules/roninforge/roninforge-kotlin-compose/compose-anti-patterns.svg)](https://agentmods.dev/rules/roninforge/roninforge-kotlin-compose/compose-anti-patterns)
Your own site
<a href="https://agentmods.dev/rules/roninforge/roninforge-kotlin-compose/compose-anti-patterns"><img src="https://agentmods.dev/badge/rules/roninforge/roninforge-kotlin-compose/compose-anti-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 2,163 This file is loaded in full into every session.
When invoked 2,163 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
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 $0.02163 $0.02163
Opus 5 $0.01081 $0.01081
Sonnet 5 $0.00433 $0.00433
Haiku 4.5 $0.00216 $0.00216

Measured 3d ago against content hash 6716a59c3ac2, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

compose-anti-patterns 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 3d 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.

rules/compose-anti-patterns.mdc · 314 lines

How it starts

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

Compose / Kotlin Android Anti-Patterns

Reject these in generated code. Each entry has a BAD example and the CORRECT replacement.

1. View-system leak: findViewById in a Compose project

// BAD
val btn = findViewById<Button>(R.id.submit)
btn.setOnClickListener { ... }

// CORRECT
Button(onClick = { ... }) { Text("Submit") }

Mixing XML layouts and Compose in the same screen forces both engines to run. New screens should be pure Compose.

2. setContentView(R.layout.x) instead of setContent { ... }

// BAD
class MainActivity : AppCompatActivity() {
    override fun onCreate(b: Bundle?) {
        super.onCreate(b)
        setContentView(R.layout.activity_main)
    }
}

// CORRECT
class MainActivity : ComponentActivity() {
    override fun onCreate(b: Bundle?) {
        super.onCreate(b)
        setContent { AppTheme { AppNavHost() } }
    }
}

3. GlobalScope.launch { }

// BAD - leaks, no lifecycle
GlobalScope.launch { repo.sync() }

// CORRECT - viewModelScope / lifecycleScope / rememberCoroutineScope
viewModelScope.launch { repo.sync() }

GlobalScope survives configuration changes, screen destruction, and process death. Anything started in it leaks until the process dies.

4. LiveData when StateFlow is the default

// BAD
val name: LiveData<String> = MutableLiveData("")
val displayName by vm.name.observeAsState("")

// CORRECT
private val _name = MutableStateFlow("")
val name: StateFlow<String> = _name.asStateFlow()

// in composable
val displayName by vm.name.collectAsStateWithLifecycle()

LiveData works but is legacy. New code uses StateFlow for state, SharedFlow for events.

5. Public MutableStateFlow / MutableState

// BAD
val count = MutableStateFlow(0)   // anyone can mutate

// CORRECT
private val _count = MutableStateFlow(0)
val count: StateFlow<Int> = _count.asStateFlow()

Same rule as Java: expose the read-only contract, keep the mutator private.

6. Force-unwrap !!

Read the full file on GitHub · 314 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. 3d ago First seen · 314 lines · 2,163 tokens per session scan A 6716a59c3ac2

Subscribe to this mod's changes

compose-anti-patterns is a cursor rule published in the GitHub repository RoninForge/roninforge-kotlin-compose (1 stars, last pushed 2mo ago), licensed MIT. It adds 2,163 tokens to every session, about $0.0108 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-31.