/vibedgames:multiplayerfrom vibedgames
Adds real-time multiplayer to browser games with shared state, per-player state, events, and host authority. Works with Phaser, Three.js, vanilla JS, and React.
Ships in vibedgames. 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; scripts run unread.
Add real-time multiplayer to any browser game with @vibedgames/multiplayer.
npm install @vibedgames/multiplayer
@vibedgames/multiplayer — framework-agnostic MultiplayerClient class (Phaser, Three.js, vanilla JS)@vibedgames/multiplayer/react — React hooks wrapping the clientEvery example assumes this constant. Define it once — in a real game it lives in net/client.ts (see references/architecture.md) — and import it; never repeat the literal per call site:
export const PARTY_HOST = "https://party.vibedgames.com";
The host (first player) runs authoritative game logic. If the host leaves, the next-joined player is reassigned as host.
The SDK also ships the netcode pieces every real-time game needs. Use them rather than hand-rolling a throttle or a lerp:
FixedRate — a steady send clock.client.serverNow() / client.serverClock — one clock every client shares; stamp sends with it.Interpolator — render remote players smoothly from those stamps; its RemoteClock learns each sender's relay delay.Reconciler — correct a guest's own predicted body against the host's copy.And the party server runs the services no single client can do fairly:
client.claim(key): first come, first served, one hop (pellets, pickups, harvests).tickRate + sendInput + onTick: ordered inputs for lockstep/rollback games.interest: { radius }: far players stop receiving each other's state.limits: { hp: { min, max } }: the server drops out-of-range player state.See references/architecture.md → Throttling, Latency, Races, Lockstep and rollback.
By default a room is unlimited. Pass maxPlayers to cap it; when full, the next player overflows into a sibling room ({room}~2, {room}~3, …) and the SDK reconnects them there transparently — extra players get a parallel match instead of being turned away.
const client = new MultiplayerClient({
host: PARTY_HOST,
party: "vg-server",
room: "arena",
maxPlayers: 8, // 9th player lands in "arena~2", 17th in "arena~3", …
});
client.room; // the room you actually landed in — "arena" or an overflow sibling
useMultiplayerRoom takes the same maxPlayers option; read the live id off room.room for "Room #2"-style UI. Enforced server-side and clamped to MAX_ROOM_CAP (64). All clients must pass the same maxPlayers (ship it in shared config). Overflow rooms are independent worlds (separate host, separate sharedState). Omit maxPlayers for unlimited.
For "Play online" without a room code, list rooms in a lobby and quick-match into one:
import { MultiplayerClient, quickMatch } from "@vibedgames/multiplayer";
const lobby = "bomberman"; // one per game, or per mode
const room = await quickMatch({ host: PARTY_HOST, lobby, maxPlayers: 4 });
const client = new MultiplayerClient({
host: PARTY_HOST,
party: "vg-server",
room,
lobby,
maxPlayers: 4,
});
quickMatch returns the fullest unlocked room with a free seat, or a new room id. Players matching at the same moment land together.listRooms({ host: PARTY_HOST, lobby }) returns { room, players, capacity, locked, meta }[], fullest first, for a room browser.client.setRoomInfo({ locked, meta }); everyone reads client.roomInfo. Lock when a round starts, so latecomers get a fresh room instead of joining mid-round, and unlock when it ends. meta (≤ MAX_ROOM_META_CHARS of JSON) is what a room browser shows; it is host-written, so display it, never trust it.lobby and use an unguessable id (crypto.randomUUID()) shared as a link. A room takes its lobby from its first player, so a friend joining with lobby set doesn't list it.updateSharedState is rejected on the server unless the sender is the host. A non-host call is silently swallowed and the server echoes the authoritative sharedState back so the optimistic local mirror gets corrected. Always gate writes behind client.isHost / useIsHost(room).
// Wrong — non-host's mutation gets reverted, the UI flickers.
client.updateSharedState({ score: client.sharedState.score + 10 });
// Right — every player, the host included, asks; the host's onEvent applies it.
client.sendToHost("score_request", { delta: 10 });
// in the client's onEvent:
if (event === "score_request" && client.isHost) {
client.updateSharedState({ score: client.sharedState.score + payload.delta });
}
The pattern: intents go up via sendToHost, state comes down via sharedState patches. The host validates each intent and writes the result. A guest's intent reaches the host alone; the host's own is handled at once, without a server round trip.
updateMyState is not host-gated — players always own their own slot. The corollary bites: the host cannot use updateMyState to mark other players dead/disabled either, because that call only ever writes the caller's own slot. Cross-player flags (deaths, scores, banned-from-round) belong in sharedState.
update()'s delta when the tab is unfocused; a host that integrates delta crawls for every guest. Step the host sim from real elapsed time (a fixed-step loop over performance.now() deltas), not the engine's delta.connectionStatus === "offline"; gate bots and start-screen holds on Object.keys(client.players).length <= 1, never on being offline.updateSharedState merges — your "reset" patch must include every fieldupdateSharedState(patch) does { ...prev, ...patch } on the client and the same on the server. Any field you don't mention is carried over from the previous state. This bites hardest on round-restart logic, where you intend to wipe everything but forget one field:
// Wrong — `deaths`, `winner`, anything else that exists on prev survives.
client.updateSharedState({ grid: newGrid(), bombs: {}, blasts: {} });
// Right — list every resettable field with its empty value.
client.updateSharedState({
grid: newGrid(),
bombs: {},
blasts: {},
deaths: {},
scores: {},
winner: null,
startedAt: Date.now(),
});
Keep a single emptyState() factory whose return type matches your SharedState exactly (so TS errors when you add a field). The function form replaces the whole state instead: updateSharedState(() => emptyState()) resets cleanly, and any key it leaves out is deleted for everyone.
Object.keys(client.players).indexOf(client.playerId) returns -1 between connecting and the first sync message — your local connection has opened but the server hasn't told you who else is in the room (including yourself). If you use the index to assign a spawn point, color, or team slot, both clients race to slot 0 and overlap. Wait for client.playerId to appear in client.players before deriving anything from order:
// Wrong — fires on every state change, including before sync.
useEffect(() => {
const idx = Object.keys(room.players).indexOf(room.playerId!);
setSpawn(SPAWNS[idx]); // idx is -1 on first tick; you spawn at SPAWNS[-1] = undefined
}, [room]);
// Right — wait until the server has confirmed our membership.
if (!room.playerId) return;
const idx = Object.keys(room.players).indexOf(room.playerId);
if (idx < 0) return; // sync hasn't arrived yet
setSpawn(SPAWNS[idx]);
initialState seeds once — runtime-computed worlds seed host-sideinitialState is applied by the first host of a still-empty room and never re-applied on host migration (≥ 0.2.0), so a promoted guest can't wipe the live round. It must be a static literal, though: a random map or startedAt: Date.now() is seeded by the host behind an "already seeded?" guard — see references/architecture.md → Seeding host-side.
useMultiplayerRoom/useMultiplayerState/usePlayerState, targeted + coalesced events, room metadata. Open for a React game.MultiplayerClient in a game loop, read-vs-subscribe rule, Phaser and Three.js examples. Open for any non-React game.net/ adapter layer, host-side seeding, offline ≠ solo, throttling (FixedRate), reconnection UX (offline fallback, stale host), pause in an online game, latency (Interpolator for remotes, Reconciler for your own predicted body, bodyDrive), claims, tick rooms (lockstep/rollback), interest, limits, the automated two-client check, schema discipline + validation. Open before writing net/, and whenever a room freezes, rubber-bands, lags, or resets.Run the game's dev server, open it in two browser tabs with the same room id (use an incognito window for tab 2 if the game reads per-browser storage). Tab 1 is host.
Smoke both directions: move in tab 2, confirm tab 1 renders it; trigger a host write in tab 1, confirm tab 2 receives the patch.
Host migration: close tab 1. Tab 2 must promote to host and the round must survive (if the world resets here, you're re-seeding on promotion — see Seeding host-side).
Latency pass: run the net check against the dev server. It opens two headless clients in a fresh room with 80 ms ± 40 ms one-way lag on the party socket, moves both, and reports how often each drew the other past the newest update (starved) or froze (stalled):
SKILL="${CLAUDE_SKILL_DIR}"
[ -d "$SKILL" ] || for d in .agents/skills .claude/skills ~/.agents/skills ~/.claude/skills; do
[ -d "$d/multiplayer" ] && SKILL=$d/multiplayer && break
done
node "$SKILL/scripts/net-check.mjs" http://localhost:5173 --json
Exit 0 is smooth; 1 is choppy, stalling or never connected; 3 means it couldn't judge (remotes not drawn through Interpolator, or the machine ran a page under 20 fps; with no GPU, as in most containers, add --no-draw for a WebGL game: its draws become no-ops and everything else runs). It needs playwright in the game project, a ?room= query param (rename with --room-param), and keys from your window.__GAME_PLAYTEST__ moves (else arrows + WASD). By hand, the same pass is DevTools → Network → a custom ~200 ms latency profile (it applies to WebSockets) in one of two tabs. Localhost's ~0 ms round trip hides jitter, rubber-banding and event/state races; this is where they show.
Automated two-client check: a Playwright harness with two headless contexts in one room — run one suite at a time, unique room id per run, client.destroy() before closing a context, assert on both clients' state. The full trap list — GPU flags, grace/eviction timing, blips vs leaves, virtual time — is in references/architecture.md → Automated two-client check.
client.sharedState.score = 100 (or pushing into an array read from it) is never sent, and nothing overwrites it: a patch touches only the leaves that changed, so the edit outlives it and this client's copy drifts from the room's. Write through updateSharedState; structuredClone anything read from shared state before editing it.updateMyState. Events are for things that happened.t: client.serverNow() and render through Interpolator (never on client.serverClock with a fixed delay — a stamp arrives a whole relay late).client.claim(key).Reconciler — against where the body was, never where it is now.acc = 0 or frame % n send throttles. They drift, alternate gap lengths, or scale with refresh rate. Use FixedRate.units: { u7: {...} }). Player state is coarser still: updateMyState re-sends any object or array key in full on every call, so keep it to flat primitives.update(). Use the adapter pattern. Single-player should still work after rm -rf net/.Date.now(). Resume mass-expires every fuse. Pause via an offset sim clock; online, pause = spectator.sendEvent("secret_role", …) + filtering in onEvent means every client still receives the payload — anyone can read it in DevTools. Deliver private data with { to: playerId }; the server never sends it elsewhere.vg deploy ./dist --slug my-game → live at https://my-game.vibedgames.com; the party server is shared infrastructure. See the deploy skill for the full flow (use npx -y vibedgames@latest deploy if vg isn't on PATH).
gamepad (@vibedgames/gamepad) — on-screen touch controls (virtual joystick + buttons) so the multiplayer game is playable on phones, not just desktop.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
35 skills in this plugin
/animated-spritesheetsGenerate a character's animation frames (idle, run, attack, death…) as one labeled pose board, then slice, key and pack them into an engine-ready spritesheet./animationMake 2D sprite animation read well: frame budgets per clip, timing and spacing, cancel windows, smears, secondary motion, wiring clips in Phaser. Generating frames is pixel-art / animated-spritesheets./asepriteParse Aseprite files (.ase/.aseprite) — layers, cels, tags, slices, palettes, tilesets — into JSON, durations and bounds for engines and tools.npx claudepluginhub kyh/vibedgames --plugin vibedgamesOther plugins' skills for the same job