session

P2P battles win prompt credits inside your agentic session.

session

Created At

ETHGlobal Mumbai

Winner of

Chainlink Labs

Chainlink - Best use of Chainlink CCIP 2.0

Project Description

Session is a multiplayer layer that lives inside a coding-agent session. Two people, on Cursor or Claude Code, leave their agents working on a prompt and use the wait to find each other and play. A prompt often runs for several minutes. User A might have about four minutes left and User B about three. During that overlap they battle in the editor: chess on one shared board, a game of flappy on the same course, or a puzzle that opens the moment the prompt is submitted. The person plays. The agent keeps writing code.

Each session has an id and a display name. On the same Wi-Fi, sessions advertise themselves and show up as nearby. From anywhere else, a room code, a ping, or the prompt itself drops both players into one queue. The first prompt waits. The second prompt starts the round. Chess uses five-minute clocks. Flappy gives both players the same pipes. They fly on their own machines, and the higher score wins. Solo boards (sudoku, a crossword, KenKen, a maze, a mate) come from the games chosen in settings and rotate on every new prompt.

The prize is tied to that prompt. A win or a solved board adds token credits, and those credits count only while the agent is still working. When the turn finishes, the cents become claimable. A claim pays them out as USDC, so the match can cover the prompt that was running beside it. Head-to-head games can also move a five-cent stake from the loser to the winner. Players can wear a name.session.eth subname, and the lobby of open challenges, room codes, and finished matches stays readable after the game.

How it's Made

The repo is a pnpm workspace. packages/core is a TypeScript MCP server on stdio (@modelcontextprotocol/sdk). Cursor and Claude Code start it and call tools such as session_me, session_peers, session_ping, session_move, and session_poll. That process opens a WebSocket to one relay. The relay is Express plus ws, deployed on Railway at wss://sessionrelay-production.up.railway.app/ws. It is the authority for presence, room codes, pings, chess (FEN and clocks), flappy scores, and the USDC ledger. A 200ms sweep runs the clocks. Same-LAN discovery is separate: bonjour-service publishes a _session mDNS record whose TXT fields carry the session id, name, and host. Nearby is only a flag on the peer list. Every move still goes through the relay, which is what lets a Cursor window and a Claude Code window share one match.

Cursor is two installs on that same socket. The agent plugin is a skill, a rule, and a stop hook: after a build step the agent polls, and if it is this session's chess turn it plays one UCI move and shows the unicode board from the tool reply. The editor UI is a VS Code webview extension (sidebar, board tab, credits), shipped as a .vsix and listed on Open VSX. Claude Code gets a real terminal pane on the same protocol. /session opens it. The person clicks pieces or flaps. The agent does not play.

The hack that ties play to the prompt is a pair of files in ~/.session. A Cursor beforeSubmitPrompt hook writes agent-work.json with phase working and a generation counter, and writes puzzle-trigger.json with the next selected game. The extension watches those files, deals the board, and awards cents only while the phase is working. The stop hook marks the turn done, and the pending cents become claimable. The hook always prints {} and fails open, so a bad prefs file never blocks the prompt. Flappy is the other local trick. Physics run in the pane, frame by frame, using a mulberry32 stream seeded by the relay. Both machines generate the same pipes. Nothing is sent until the bird crashes, and the relay compares the two scores.

USDC sits in SessionTreasury on Base mainnet (0xE2ca5C8ed8589Dc61abE1B2c2Dae309d2f86410c), written in Solidity 0.8.24 with Foundry and called through viem. Deposits are plain USDC transfers. The relay credits each one once by scanning Transfer logs to the treasury over a rolling window of Base blocks and storing balances in a JSON bank. A claim is signed only by the relay's owner key. One cent of credit is 0.01 USDC, with a daily cap. On Base, sendReward is a direct transfer. For Ethereum, Arbitrum, Optimism, and Polygon, the same function is a Chainlink CCIP 2.0 send whose receiver is the player's wallet, so there is no per-chain payout contract. The CCIP 2.0 extra-args are packed off-chain as a short blob (ExtraArgsV3: gas 0, finalized finality, empty verifier fields) and forwarded unchanged, so a Chainlink encoding change does not need a new treasury. forge test runs that blob through Chainlink's CCIP Local Simulator. An earlier wager path, SessionLock and SessionPayout, locks equal stakes on Base Sepolia and settles them on Ethereum Sepolia over CCIP.

The opening coin-flip is Chainlink CRE plus VRF, so the relay is not the source of the random color. When two players pair, the relay spawns cre workflow simulate with the pair as an HTTP payload. The TypeScript workflow (@chainlink/cre-sdk) hashes both session ids, builds a report, and writeReports it to SessionMatchDraw on Base. That contract requests one VRF v2.5 word. An even word makes the player who waited white. The relay tails DrawFulfilled logs and applies the color. Names are a permissioned ENSv2-style registry: the subname owner is the only key that can edit the address and text records under session.eth. Arkiv stores the durable lobby. Challenges, rooms, and finished matches are wallet-owned entities filtered by kind, expiresAt, room code, and opponent, and the pane, the web lobby, and the board read those same entities. Live moves stay on the WebSocket, because a chess clock cannot wait on an entity write. The public site is Vite and React: a landing page for the extension, and a table view of who is in the room.

background image mobile

Join the mailing list

Get the latest news and updates

session | ETHGlobal