Implements browser game save/load with versioned format, migrations, atomic writes, slots, backups, autosave, cross-device conflict resolution, and corruption checks. Covers server vs. browser storage decisions.
Ships in game-dev. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Target stack: browser client, Bun server, Postgres through Drizzle 0.45, Redis. Database setup and migrations come from postgres-game-schema; this skill adds only the save table and the save rules.
| The save holds | Store it | Why |
|---|---|---|
| Currency, items, ranked progress, anything another player or the shop cares about | Normalized server tables (postgres-game-schema), written by server logic | The client is under the player's control. The server decides and stores state; the client sends inputs only. |
| Single-player progress the player would be upset to lose | Server save slot (boilerplate/server-save.ts) plus a local copy | Browser storage can be deleted without asking (next section). The server copy also roams between devices. |
| Settings, key bindings, a guest session before sign-in | Browser only (boilerplate/browser-save-store.ts) | Losing it costs little. |
Rules that follow from the table:
redis-game-patterns).betterauth-integration), never from the request body.navigator.storage.persist() when the player first saves, inside the click handler of the save button. Chrome grants or refuses by engagement without a prompt; Firefox shows a permission prompt. A persistent origin is not evicted under pressure.QuotaExceededError. Catch it, tell the player, and offer to delete old slots or export the save.SecurityError when the player blocks site data (often by blocking cookies) and on file: and data: origins. Wrap it if you use it for settings.onupgradeneeded. A tab still on the old version blocks the upgrade until it closes its connection, so handle onblocked and close the database in onversionchange. openSaveDb closes it and calls your onVersionChange, so the game can tell the player to reload the tab. Store layout versions and save payload versions are separate numbers.showSaveFilePicker() needs HTTPS and a click, and MDN marks it experimental and not Baseline: check the compatibility table and fall back to a download link.Copy boilerplate/save-envelope.ts. Each save is an envelope: format, version, savedAt, playedMs, sha256, and the payload as a JSON string. loadSave reads an envelope; migrateAndValidate runs the same version window, migrations and validation on bare data, such as a server row.
minLoadable is the oldest version this build migrates; older saves get a clear "too old" message, not a guess. Raise it when old migrations cost more than they are worth.loadSave takes a validate function shaped like a Zod .safeParse(), which returns a result instead of throwing; a hand-written type guard works too. For Zod itself, see https://zod.dev/basics. Validate before writing as well: createSave refuses data that would fail to load.Map, Set, Date, BigInt or class instances; convert them to numbers, arrays and strings. Plain data also matches what game-state-sync already requires of live state.procedural-gen has the rule (store what the player changed, regenerate what the player only observes) and the table shapes; store the generator version beside the seed.load(save(state)) equals state for states from real play.readwrite transaction per save. It commits all its requests or, on abort, rolls all of them back. writeSlot moves the current save to <slot>:backup and writes the new one in the same transaction. Firefox can fire complete before the data reaches the disk, which is one more reason to keep the backup.revision; writeSlot takes the revision this tab loaded, compares it inside the transaction, and returns stale without writing on a mismatch. Treat stale like a server conflict: show both saves and let the player choose.db.transaction. A committed transaction is written to permanent storage before the commit is reported. saveToSlot locks the row with SELECT ... FOR UPDATE, copies the old version into save_slot_history, updates the slot and prunes old history, all in one transaction.rename keeps the target name pointing at either the old or the new file throughout. Bun's file I/O docs do not say that Bun.write is atomic, so do not assume it.:backup key in the browser, and on the server the last KEEP_HISTORY rows of save_slot_history (5 is this skill's default; tune it to save size and how far back players need to go). On load, if the current save fails loadSave, try the backup and tell the player which save was restored. The next browser write after such a recovery passes { keepBackup: true } to writeSlot, so the bad current record is replaced and the good backup stays; a normal write would rotate the bad record over it.listSlotHistory(db, playerId, slot) lists the rows, and restoreFromHistory writes the chosen one through the same revision check and transaction, so the version it replaces goes into history too. It runs migrateAndValidate on the row first and refuses with unloadable a row that no longer loads (for example after minLoadable rose), leaving the slot unchanged.visibilitychange when document.visibilityState becomes hidden: it is the last event a page can rely on, and unload does not fire on mobile when the player closes the tab from the tab switcher or closes the browser. This save is best-effort; the browser may end the page before the write finishes. autosaveOnHide wires it.beforeunload listener only while there are unsaved changes, and remove it after saving. Attached all the time, it hurts performance and the back/forward cache.document.wasDiscarded: the browser may have discarded the page to save memory, and the game should restore from the last save.Last write wins erases progress. Use a revision check instead:
revision.If-Match and an ETag). saveToSlot updates only if the stored revision still matches and returns conflict with the server save's metadata otherwise. Answer the client with 409 or 412.expectedRevision set to the server.revision from the conflict result, or 0 when server is null (the slot was deleted). Keep the server's save: call loadSlot and drop the local one.loadSave checks a SHA-256 digest of the exact payload string before parsing (crypto.subtle.digest, secure contexts only). A mismatch means damage in storage or transfer; fall back to the backup.jsonb, whose stored form differs from the client's string.Only where the game ships there:
boilerplate/save-envelope.ts. Define the save type, its validator, current = 1, minLoadable = 1.boilerplate/browser-save-store.ts. Call requestPersistence on the first manual save; wire autosaveOnHide; catch QuotaExceededError.boilerplate/server-save.ts. Add save_slots and save_slot_history to the schema module with a foreign key from player_id to players.id, and generate the migration with drizzle-kit. Save route: player id from the session, a request body size cap (for example 1 MiB, a placeholder: set it from your largest real save), loadSave on the uploaded envelope, saveToSlot with the migrated data and formatVersion = spec.current, 409 on conflict. Load route: loadSlot, then migrateAndValidate(spec, row.formatVersion, row.payload).minLoadable up.current, add the migration step, add a fixture.QuotaExceededError. The save silently fails. Catch every write. Source: web.dev storage article.unload. It does not fire on mobile. Save on visibilitychange. Source: Chrome Page Lifecycle article.redis-game-patterns.boilerplate/save-envelope.ts: copy when defining the save format. Envelope type, createSave, loadSave (digest check, then migrateAndValidate: version window, migration chain, validation) and an example spec with one migration.boilerplate/browser-save-store.ts: copy when the game saves in the browser. IndexedDB open with upgrade handling, readSlot, writeSlot (revision check, backup and write in one transaction; returns stale for an out-of-date tab), decideLocalWrite, requestPersistence, autosaveOnHide.boilerplate/server-save.ts: copy when saves live on the server. save_slots and save_slot_history tables, saveToSlot with the revision check and history, restoreFromHistory, loadSlot, listSlotHistory. Takes the database first (GameDb), like postgres-game-schema.references/sources.md: read when checking where a claim comes from.postgres-game-schema: table conventions, valued state, drizzle-kit migrations.game-state-sync: live replication between server and clients; this skill covers storage only.redis-game-patterns: live state, and why Redis is not the record.procedural-gen: seed plus changes, generator versions.betterauth-integration: the session that supplies the player id.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/game-dev:game-save-loadfrom game-dev
npx claudepluginhub fcsouza/agent-skills --plugin game-dev39 skills in this plugin
/betterauth-integrationCovers the game-specific layer of Better Auth: player, moderator and admin roles, session checks on game routes and WebSocket handshakes, and keeping the auth session apart from the game session. Use when a game needs player login, moderator or admin powers, or authenticated real-time connections, and the project uses Better Auth./bullmq-game-queuesBackground job design for game backends on BullMQ and Redis: one queue per game domain, idempotent reward fulfilment, and cron schedulers for daily rewards and season ends. Use when a game needs matchmaking requests, reward grants, match results, notifications or analytics processed off the request path, or recurring and timed jobs such as daily login rewards, leaderboard snapshots and season rollovers./character-design-narrativeCovers designing game characters: NPCs, companions, antagonists, player avatars, character bibles and branching dialogue. Use when a game needs a new character written, an NPC feels flat or interchangeable, or dialogue needs a branching format with conditions and effects./ci-cd-gameGitHub Actions pipeline rules for a Bun game backend on Neon and Fly.io: migrations before deploy, one Neon database branch per pull request, a smoke test after deploy, and a pinned Bun version. Use when a game project needs CI, a deploy workflow, preview databases for pull requests, or a safe order for schema migrations and server deploys./elevenlabs-sound-musicCovers generating game audio with ElevenLabs (voice lines, sound effects, music) and Google Lyria 2 (instrumental music clips), and playing it in the browser through an audio state machine with crossfades, per-layer volume and an unlock on the first user input. Use when a game needs sound effects, NPC voice lines or a soundtrack, when music must follow game state (menu, exploration, combat, boss) without hard cuts, when audio stays silent on a phone until the player taps, or when choosing between ElevenLabs and Lyria for music./game-anti-cheatCovers how a developer defends their own online game against cheating: server-side input validation, withholding hidden state, lag-compensation limits, dupe-proof transfers, detection from server data and reports, and enforcement with delayed bans, appeals and refunds to victims. Use when a multiplayer game has speed hacks, wallhacks, aimbots, bots, item or currency dupes, real-money trading, boosting or win trading, or when planning how to detect and ban cheaters.Other plugins' skills for the same job