datastore

datastore is a skill for Claude Code from rcosteira79/android-skills. It costs 98 tokens per session (915 once invoked), scanned A, original, MIT.

Guidance for using Jetpack DataStore, an Android and Kotlin Multiplatform library for storing small settings or typed data. It explains when to choose simple preferences, typed storage, or Room, a database library for relational data.

In plain words
What is it for?
Use it when storing settings, defining a typed data file, handling corruption or I/O failures, or deciding whether data belongs in DataStore or Room.
Why use it?
It helps avoid choosing the wrong storage method and covers common errors involving file access, data corruption, and platform-specific paths.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the android-skills plugin — 21 skills shipped together

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 skills/rcosteira79/android-skills/datastore
Any agent
npx skills add rcosteira79/android-skills --skill datastore
Clone the repo
git clone --depth 1 https://github.com/rcosteira79/android-skills

Made for: Claude Code.

Or install android-skills, the plugin that ships this one along with the rest of its 21 skills.

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 datastore

README.md
[![agentmods](https://agentmods.dev/badge/skills/rcosteira79/android-skills/datastore.svg)](https://agentmods.dev/skills/rcosteira79/android-skills/datastore)
Your own site
<a href="https://agentmods.dev/skills/rcosteira79/android-skills/datastore"><img src="https://agentmods.dev/badge/skills/rcosteira79/android-skills/datastore.svg" alt="Measured on agentmods" height="20"></a>
Per session 98 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 915 The whole file, excluding the scripts and references it only reads on demand.
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.1 $0.00098 $0.00915
Opus 5 $0.00049 $0.00458
Sonnet 5 $0.00020 $0.00183
Haiku 4.5 $0.00010 $0.00092

Measured 6d ago against content hash 0b826747050d, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

datastore 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 6d 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.

plugins/android-skills/skills/datastore/SKILL.md · 61 lines

How it starts

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

Jetpack DataStore for Android and KMP

Reactive coroutine-based key-value / typed storage; the same androidx.datastore:datastore-preferences-core runs on Android, iOS, and JVM — only the file-path producer is platform-specific. (Web support is 1.3.0-alpha only, and it's sessionStorage/OPFS-backed there, not file-path-based.) This reference covers the storage-choice call plus the two error/path traps, not the basics of Preferences keys, edit { }, or Serializer<T>. Adapted from Meet-Miyani/compose-skill; MIT. Related: android-skills:android-data-layer, android-skills:kmp-boundaries, android-skills:kotlin-flows.

Preferences vs Typed vs Room

Need Storage
Key-value flags (theme, locale, onboarding done) Preferences DataStore
One typed object, many related fields, schema evolution Typed DataStore + Serializer<T>
Relational data, indexes, WHERE / JOIN, >100 entries, paging Room
Payloads above ~50KB per write Room / filesystem — DataStore rewrites the whole file on every edit

Rule of thumb: if a WHERE clause would be useful, use Room.

The two traps

.catch must match IOException specifically — never a broad catch. A bare catch { emit(emptyPreferences()) } swallows CancellationException (breaking structured concurrency) and hides serializer/corruption errors behind a silent empty state.

val settings: Flow<UserSettings> = dataStore.data
    .catch { e -> if (e is IOException) emit(emptyPreferences()) else throw e }
    .map { p -> UserSettings(p[Keys.DARK_MODE] ?: false, p[Keys.LOCALE] ?: "en") }

Typed-DataStore corruption recovery triggers on CorruptionException, NOT IOException. The serializer's readFrom must wrap parse failures in CorruptionException, and the store needs a ReplaceFileCorruptionHandler — without it, one corrupt file makes every read fail permanently.

object AppSettingsSerializer : Serializer<AppSettings> {
    override val defaultValue = AppSettings()
    override suspend fun readFrom(input: InputStream): AppSettings =
        try { Json.decodeFromString(input.readBytes().decodeToString()) }
        catch (e: SerializationException) { throw CorruptionException("Cannot read AppSettings", e) }
    override suspend fun writeTo(t: AppSettings, output: OutputStream) =
        output.write(Json.encodeToString(t).encodeToByteArray())
}
val store = DataStoreFactory.create(
    serializer = AppSettingsSerializer,
    corruptionHandler = ReplaceFileCorruptionHandler { AppSettings() },
    produceFile = { File(context.filesDir, "app_settings.json") },
)

Read the full file on GitHub · 61 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. 6d ago First seen · 61 lines · 98 tokens per session scan A 0b826747050d

Subscribe to this mod's changes

datastore is a skill published in the GitHub repository rcosteira79/android-skills (136 stars, last pushed 11d ago), licensed MIT. It adds 98 tokens to every session and 915 once invoked, about $0.0005 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