offline-first

offline-first is a skill for Claude Code, Codex from piyushverma0/android-agent-skills. It costs 113 tokens per session (2,019 once invoked), scanned A, original, MIT.

A guide to offline-first Android design, where the app reads from local storage and synchronizes with online services in the background when possible.

In plain words
What is it for?
Use it when building cache-first screens, local databases with Room, optimistic updates, background synchronization with WorkManager, or conflict-resolution logic.
Why use it?
It helps an app remain useful without an internet connection and handles delayed updates, retries, connectivity changes, and conflicting edits.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when building cache-first screens, local databases with Room, optimistic updates, background synchronization with WorkManager, or conflict-resolution logic.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/piyushverma0/android-agent-skills/offline-first
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.

Any agent
npx skills add piyushverma0/android-agent-skills --skill offline-first
Clone the repo
git clone --depth 1 https://github.com/piyushverma0/android-agent-skills

Made for: Claude Code, Codex.

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 offline-first

README.md
[![agentmods](https://agentmods.dev/badge/skills/piyushverma0/android-agent-skills/offline-first/github.svg)](https://agentmods.dev/skills/piyushverma0/android-agent-skills/offline-first)
Your own site
<a href="https://agentmods.dev/skills/piyushverma0/android-agent-skills/offline-first"><img src="https://agentmods.dev/badge/skills/piyushverma0/android-agent-skills/offline-first/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for offline-first

Your own site · 80×15
<a href="https://agentmods.dev/skills/piyushverma0/android-agent-skills/offline-first"><img src="https://agentmods.dev/badge/skills/piyushverma0/android-agent-skills/offline-first.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 113 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,019 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.00113 $0.02019
Opus 5 $0.00056 $0.01009
Sonnet 5 $0.00023 $0.00404
Haiku 4.5 $0.00011 $0.00202

Measured 9d ago against content hash 859d3bf65877, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

offline-first 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 9d 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.

skills/offline-first/SKILL.md · 278 lines

How it starts

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

Offline-First Architecture

Apps that require internet to work lose 30%+ of users. These patterns make your app work everywhere — with or without connectivity.

Core principle: Local DB is source of truth

User Action → ViewModel → Repository
                               ↓
                         Local DB (Room)  ← single source of truth
                               ↓
                          UI observes Flow from Room
                               ↓ (background)
                         Network sync → update Local DB → UI auto-updates

Rule 1: Single-direction data flow — never mix local + remote in UI

// ✅ Repository: local DB is source of truth, network updates DB silently
class ItemRepositoryImpl @Inject constructor(
    private val itemDao: ItemDao,
    private val api: ItemApiService,
    @IoDispatcher private val dispatcher: CoroutineDispatcher
) : ItemRepository {

    // UI always observes local DB
    override fun getItemsStream(): Flow<List<Item>> =
        itemDao.getAll().map { it.map { entity -> entity.toDomain() } }

    // Sync pulls from network and updates local DB
    override suspend fun sync(): Result<Unit> = withContext(dispatcher) {
        runCatching {
            val remoteItems = api.getItems()
            itemDao.upsertAll(remoteItems.map { it.toEntity() })
        }
    }
}

// ✅ ViewModel triggers sync but observes local DB
@HiltViewModel
class HomeViewModel @Inject constructor(
    private val repository: ItemRepository
) : ViewModel() {

    val items: StateFlow<List<Item>> = repository.getItemsStream()
        .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())

    init { sync() }

    fun sync() {
        viewModelScope.launch {
            repository.sync()   // updates DB → Flow auto-updates UI
        }
    }
}

Rule 2: Optimistic UI updates

// ✅ Apply change locally immediately, sync to server in background
override suspend fun toggleFavorite(itemId: String): Result<Unit> = withContext(dispatcher) {
    // 1. Update local DB immediately (UI updates instantly)
    val item = itemDao.getByIdOnce(itemId) ?: return@withContext Result.failure(NotFoundException())
    val newValue = !item.isFavorite
    itemDao.updateFavorite(itemId, newValue)

    // 2. Sync to server in background
    runCatching {
        api.patchItem(itemId, mapOf("is_favorite" to newValue))
    }.onFailure {
        // 3. Rollback local change if server fails
        itemDao.updateFavorite(itemId, !newValue)
    }
}

Read the full file on GitHub · 278 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. 9d ago First seen · 278 lines · 113 tokens per session scan A 859d3bf65877

Subscribe to this mod's changes

offline-first is a skill published in the GitHub repository piyushverma0/android-agent-skills (15 stars, last pushed 4mo ago), licensed MIT. It adds 113 tokens to every session and 2,019 once invoked, about $0.0006 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.