Implements skill-based matchmaking for multiplayer games: rating systems (Elo, Glicko-2, TrueSkill), dynamic skill brackets, atomic queue claiming, and lobby lifecycle. Uses Redis and BullMQ.
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.
Pairs players by skill from a Redis sorted set, widens the skill bracket as they wait, claims each pair atomically, and runs the lobby until the match ends.
| System | Pick it when | What it tracks |
|---|---|---|
| Elo | Matches are plentiful and you can keep matchmaking tight | One number. Menke: needs more matches to converge than Glicko or TrueSkill. |
| Glicko-2 | Players compete alone and you want an uncertainty that grows while a player is away (RD rises in a rating period with no games) | Rating, rating deviation (RD), volatility; a draw scores 0.5. Menke, on Glicko: converges faster than Elo, not naturally adapted to teams. |
| TrueSkill | Team modes, more than two teams, or draws | Mean mu and uncertainty sigma per player; team skill is the sum of its players. Menke: designed for teams and draws, converges in the fewest matches of the three. |
Starting values with a source:
No Elo K-factor is given here because no source was checked. Pick one and tune it against your own win-prediction data.
Persist ratings in Postgres after each match (postgres-game-schema) and cache them in Redis for the queue.
queuedAt, with a TTL so a crashed client does not stay queued forever.findMatch; if nothing fits, it adds a delayed copy of itself, so the search runs again with a wider bracket.initial + floor(wait / interval) * step, capped at a maximum. Derive it from queuedAt on every search; do not store it, so it cannot go stale and needs no separate "widen" job.startMatch deletes it, unmaps every player and returns the connected ones in requeue. Requeue them with their original queuedAt so their bracket stays wide. A leave before IN_PROGRESS dissolves the lobby the same way; leaveLobby returns the ids to requeue.Build the queue from boilerplate/matchmaker.ts.
Build the lobby from boilerplate/lobby-manager.ts.
import { Redis } from 'ioredis';
import { MatchmakingEngine, startMatchmaking } from './matchmaker';
import { LobbyManager } from './lobby-manager';
const url = process.env.REDIS_URL ?? 'redis://localhost:6379';
// Request path: by default ioredis holds a command through 20 reconnect
// attempts (maxRetriesPerRequest: 20); 1 fails the request fast when Redis is
// down, as `bullmq-game-queues` does for producers.
const redis = new Redis(url, { maxRetriesPerRequest: 1 });
// Worker connection: BullMQ requires maxRetriesPerRequest: null here.
const workerRedis = new Redis(url, { maxRetriesPerRequest: null });
const engine = new MatchmakingEngine(redis);
const lobbies = new LobbyManager(redis);
const { queue } = startMatchmaking(workerRedis, engine, async (match) => {
await lobbies.createLobby(match);
});
await engine.enqueue({
playerId: 'player_123',
rating: 1500,
deviation: 350,
gamesPlayed: 0,
gameMode: 'ranked-1v1',
region: 'eu-west',
queuedAt: Date.now(),
});
await queue.add(
'search',
{ gameMode: 'ranked-1v1', region: 'eu-west', playerId: 'player_123' },
{ removeOnComplete: true },
);
Reading candidates and then removing them in separate calls lets two workers pick the same opponent, and both matches go ahead. A MULTI/EXEC of two ZREMs does not fix this: if one member is already gone, the other is still removed, and Redis transactions have no rollback.
The boilerplate's claim script checks both members with ZSCORE, then ZREMs both and DELs both hashes, all inside one script. Redis runs a script atomically, so a second worker sees the pair gone and moves to its next candidate. Pass every key the script touches as a key argument. Every matchmaking key shares the {mm} hash tag because the scripts touch a pool and the global per-player markers together; on Redis Cluster that puts all matchmaking state in one slot.
WAITING -> COUNTDOWN -> IN_PROGRESS -> COMPLETE. A leave or a failed presence check before IN_PROGRESS dissolves the lobby: it is deleted in the same compare-and-set write, every player is unmapped, and the remaining ids go back to the caller to requeue. A lobby short of its match size never starts. A leave after IN_PROGRESS is an abandon, not a lobby change.
Every transition reads the lobby JSON, applies a change and writes it back with a compare-and-set script. Without that, two players readying up at once overwrite each other and the lobby never leaves WAITING.
Give IN_PROGRESS a TTL longer than your longest match, or the lobby expires mid-game.
Check both in your own match data before you change anything: compare predicted and actual win rate by games played, and by party size.
newPlayerGames away from players over veteranGames. It is a stopgap with tunable thresholds, not a measured fix.queuedAt so the bracket stays wide.entryTtlSeconds and the player drops out silently. Refresh it from the client heartbeat or raise the TTL.startMatchmaking handles an onMatch failure by calling engine.requeue (one script, original rating and queuedAt), restarting both searches and rethrowing. Do the same if you call findMatch yourself. cancel leaves a marker for cancelMarkerSeconds so that requeue skips a player who cancelled while the match was being set up; a fresh enqueue clears it._ and -.startMatch throws LobbyChangedError and you call it again when the new countdown ends.priority, give every search job a priority.boilerplate/matchmaker.ts: copy when building the queue (MatchmakingEngine, startMatchmaking). It takes the ioredis client as a parameter.boilerplate/lobby-manager.ts: copy when building the lobby (LobbyManager). It takes the same client.references/sources.md: read when citing a number or claim from this skill.bullmq-game-queues (queue and worker setup)redis-game-patterns (Redis client, presence)postgres-game-schema (rating and match history)game-state-sync (takes over once the match starts)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/game-dev:matchmaking-systemfrom 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./Other plugins' skills for the same job