CLAUDE.md for Android & Kotlin Multiplatform: 12 Rules to Keep AI from Shipping LiveData in 2026
The fix is not “write better prompts every time.” It is a CLAUDE.md checked into the root of your repo — a file the model reads on every turn.
重點摘要
Use stateless Compose UIs with state hoisting.
Prefer StateFlow/SharedFlow, KSP, and kotlinx.serialization over older Android-era defaults.
Set Kotlin-specific guardrails in CLAUDE.md for lifecycle, testing, KMP, and Gradle conventions.
This article argues that AI coding tools often regress Kotlin projects to outdated patterns, such as LiveData, kapt, Gson reflection, runBlocking, and raw String IDs. Instead of relying on better prompts, the author recommends checking a CLAUDE.md file into the repo root so the model reads project rules on every turn. The piece outlines 12 guardrails for modern Kotlin stacks across Android, JVM backends, and KMP, covering Compose state hoisting, StateFlow and SharedFlow, constructor DI, inline value classes, lifecycle-aware coroutines, typed error handling, KSP, kotlinx.serialization, runTest, expect/actual restraint, CI lint gates, and Gradle Kotlin DSL with version catalogs.
面向 Android 和 Kotlin Multiplatform 的 CLAUDE.md:阻止 AI 在 2026 年继续提交 LiveData 的 12 条规则
解决办法不是每次都写更好的提示词,而是在仓库根目录提交一个 CLAUDE.md,让模型每轮都读取它。
重點摘要
用 CLAUDE.md 统一 AI 与团队的 Kotlin 代码规范。
采用 StateFlow、KSP、kotlinx.serialization 等现代方案。
覆盖 Compose、依赖注入、测试、KMP、CI 和 Gradle 最佳实践。
这篇文章指出,Claude Code、Cursor 和 Copilot 在 Kotlin 代码库中容易把技术栈倒退到旧做法,例如 LiveData、kapt、Gson 反射、runBlocking 和原始 String ID。作者认为,真正的修复方式不是反复优化提示词,而是把 CLAUDE.md 放在仓库根目录,让模型每次生成代码时都遵守项目规则。文中给出 12 条适用于 Android、JVM 后端和 KMP 的准则,涵盖 Compose 状态上提、StateFlow/SharedFlow、构造函数注入、inline value class、生命周期绑定协程、类型化错误、KSP、kotlinx.serialization、runTest、expect/actual 的限制、CI 中的 detekt/ktlint,以及 Gradle Kotlin DSL 和版本目录。
Android 與 Kotlin Multiplatform 的 CLAUDE.md:12 條防止 AI 在 2026 年繼續送出 LiveData 的規則
解法不是每次都寫更好的提示,而是在專案根目錄放入 CLAUDE.md,讓模型每次都讀取這份規則檔。
重點摘要
以 CLAUDE.md 為團隊與 AI 的共用規範。
改用 StateFlow、KSP、kotlinx.serialization 等現代 Kotlin 寫法。
涵蓋 Compose、DI、測試、KMP、CI 與 Gradle 的實務守則。
本文指出,Claude Code、Cursor 或 Copilot 在 Kotlin 專案中常把架構退回過時做法,例如 LiveData、kapt、Gson 反射、runBlocking 與原始 String ID。作者認為真正的解法不是每次重新調整提示,而是將 CLAUDE.md 提交到專案根目錄,讓模型每輪都遵守相同規範。文章整理 12 條面向 Android、JVM 後端與 KMP 的原則,涵蓋 Compose 狀態上提、StateFlow/SharedFlow、建構子注入、inline value class、生命週期感知協程、型別化錯誤、KSP、kotlinx.serialization、runTest、expect/actual 使用邊界、CI lint 閘門,以及 Gradle Kotlin DSL 與版本目錄。