ronjunevaldoz/kmp-agent-skills/kmp-datastore
Claude Code and agent skill by ronjunevaldoz/kmp-agent-skills
- community
Checking that the SKILL.md file is still in the repository.
Sets up Multiplatform DataStore for KMP: Preferences (key-value) and Proto (typed, schema-driven) variants. Covers createDataStore {} expect/actual per platform, Flow-based reads, coroutine writes, migration from SharedPreferences, and Koin wiring so feature modules never construct DataStore directly.
Install
npx vskill@latest install ronjunevaldoz/kmp-agent-skills/kmp-datastoreSKILL.md
The same SKILL.md was published earlier as ronjunevaldoz/kmp-agent-skills/kmp-datastore.
When to Use This Skill
Use when you need to:
- Store small, typed key-value data that survives app restart (user prefs, tokens, flags)
- Replace
SharedPreferences(Android) orNSUserDefaults(iOS) with a single KMP API - Store structured data with a Protobuf schema (Proto DataStore)
- Read persisted state as a
Flowthat recomposes automatically on change - Wire DataStore into Koin so every feature accesses it without constructing it manually
Trigger keywords: DataStore, Preferences DataStore, Proto DataStore, SharedPreferences KMP, NSUserDefaults KMP, persist settings, key-value KMP, store user preferences, DataStore migration, DataStore Flow, DataStore Koin, local storage KMP, app settings KMP, save user settings, persist app state, user preferences KMP, settings persistence, save preferences, key value storage KMP.
Freshness rule: androidx.datastore KMP artifact names and the createDataStore {} expect/actual API change between alpha versions — recheck the AndroidX releases page before pinning a version. As of mid-2026 the KMP-stable artifact is androidx.datastore:datastore-preferences-core.
Recommendation First
Default to Preferences DataStore for key-value storage, Proto DataStore only when you need schema enforcement or atomic multi-field updates.
Why:
- Preferences DataStore requires zero schema setup — just define typed keys and read/write
Flow<Preferences>integrates directly withStateFlowin the:presenterlayer- The expect/actual pattern is minimal — one
createDataStore {}factory per platform,
wired through Koin so nothing downstream knows about platform paths
- Proto DataStore adds Protobuf compilation to the build; only worth it for complex
structured settings (e.g. user profile cache, feature flag bundles)
Migrate from SharedPreferences using SharedPreferencesMigration — one line, no data loss.
Gradle Setup
libs.versions.toml
Convention plugin: add to GROUP_ID.core.gradle.kts
DataStore lives in :core:datastore — feature modules consume it through a Koin-injected interface, never by constructing DataStore directly.
Module Structure
Preferences DataStore
Key definitions — AppPreferences.kt
Interface — PreferencesDataSource.kt
Implementation — PreferencesDataSourceImpl.kt
expect/actual — Platform DataStore Factory
commonMain — DataStoreFactory.kt
androidMain — DataStoreFactory.android.kt
iosMain — DataStoreFactory.ios.kt
Platform path helpers
Koin Wiring
core/datastore/di/DatastoreModule.kt
Or use the simpler approach — declare the DataStore in platform-specific Koin modules:
Declare the common half in both app entry points:
Reading in a ViewModel
PreferencesDataSource is injected — no DataStore import in :presenter.
Migration from SharedPreferences
Migration runs once automatically on first DataStore access. The SharedPreferences file is deleted after a successful migration.
Proto DataStore (when you need schema enforcement)
Add protobuf plugin to libs.versions.toml
Schema file — src/commonMain/proto/UserSettings.proto
Serializer
Use Proto DataStore when settings have more than ~5 fields or require atomic multi-field updates. For simpler needs, Preferences DataStore is always sufficient.
Related Skills
kmp-feature-scaffold—:core:datastorefollows the same convention plugin patternkmp-dependency-injection— Koin platform-specific modules for Android vs iOS DataStore factorykmp-presenter-module— ViewModels consumePreferencesDataSourcevia constructor injectionkmp-unit-testing— fakePreferencesDataSourcefor ViewModel tests; no DataStore needed in testskmp-expect-actual—createDataStore {}is a canonical expect/actual use case
Common Anti-Patterns
- constructing
DataStorein a feature module — always create it once in:core:datastoreand inject via Koin - calling
dataStore.data.first()in a ViewModel — blocks the coroutine; usecollect {}orstateIn()instead - storing large blobs (images, long lists) in DataStore — it is not a database; use SQLDelight for relational or list data
- using
runBlockingto read DataStore synchronously — always use coroutines; wrap inrunTestin tests - one DataStore instance per feature — a single shared DataStore file per app avoids file-lock conflicts
- not handling
IOExceptionin the.catch {}— DataStore can throw on corrupted files; always emitemptyPreferences()as fallback
If DataStore writes are silently lost, check that edit {} is called inside a coroutine scope that is not cancelled before the write completes (use viewModelScope or a SupervisorJob scope).
Output Style
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/kmp-datastore/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ronjunevaldoz/kmp-agent-skills/kmp-datastore)