Free guide
How to make a multiplayer game with AI
Play Capybara Kart free: leverageai.io/play/capybara-kart
Ask Claude Code to build a small game against computer players, then add private rooms with a code you can send to friends. Give the host a Start button, finish each round with results, and test the whole thing on two phones. Cloudflare can host small rooms on its free plan, within limits.
- Room codes and share links
- Choose your computer players
- Free hosting limits explained
Published · Updated
Start buildingHow to make a multiplayer game with AI
We used Claude Code to plan and Codex to build our first versions. Capybara Kart races up to six karts. Hide in Paint has hide-and-seek rounds. Their builds and later fixes are the examples below. You can use Claude Code for the whole job.
What multiplayer adds
A solo game keeps everything on your device. With friends, you need a shared place everyone sees, a way to find each other, and someone to keep score fairly.
The shared place is a room. A code or invite link brings your friends into it. The host is the person who sets it up; they choose the settings and start play. The server, a program everyone connects to, keeps the shared rules and score.
Give each room one server referee; the io game guide explains how to build that part.
You can also make a game with no winner. In Capybara Hot Spring, friends build a shared place together. It needs invites and saved progress, but no race countdown or computer rivals.
What you need
- Claude Code, with access through your own plan or account.
- Optionally, Codex to build a small task or review a change.
- Node.js for the local tools, and a free Cloudflare account.
- A computer to build on and two devices to test with. Use phones if your friends will play on phones.
This guide is free. Your coding tool's cost is separate from hosting. Open an empty project folder, ask the tool to save working changes with Git, then work through one step at a time. The prompts below are requests for your own game, based on what we built.
The steps
Step 1: Make it fun alone first
Pick one thing players do over and over. Race around a track, chase someone, or find a hiding spot. Start with plain shapes and computer players, often called bots. Friends won't rescue controls that feel wrong.
Make a small browser racing game with computer rivals. Start with
simple shapes and one short track. Write a short plan, then build a
playable race. Give me the install and preview commands so I can try it.
Play a full race before asking for rooms. You should know where to go, feel each turn, and reach a finish. Watch the rivals too: they need to give you a reason to keep playing.
Our first computer karts in Capybara Kart trailed far behind the player. We had to improve their pace before the race felt like a contest. Play badly for a lap as well as trying to win.
Step 2: Add Practice with a computer-player choice
Practice gives you something to play while your friends are busy. Let the player choose one or more computer players, within the game's limit. Label them clearly so nobody mistakes them for people online.
Add Practice. Let me choose one to five computer players.
Keep six seats total, including mine. Remember my choice.
Practice should work without connecting to the room server.
Choose one rival, play, go back, then choose more. The number on the track should match the menu. Leave space for your own seat. For hide and seek, check both playing as the hider and playing as the seeker.
In Capybara Kart, Practice originally gave you a fixed field of computer karts. Having a Practice button wasn't enough; we later added the choice of how many to race.
These computer players use game code. They don't need to send prompts to a paid AI service while you play.
Step 3: Make rooms easy to join
Add Create room, Join with code and Copy link. Keep private rooms out of public matchmaking, which puts strangers together. A friend opening an invite should land in your room without having to hunt through menus.
Add private rooms on Cloudflare's free plan, with a short code and a
Copy link button. Use one SQLite-backed Durable Object per room.
Show who's waiting. Explain a bad code or full room in plain words.
A Durable Object is Cloudflare's place for one room's shared data and connections. Ask the tool to show you two local browser windows in the same room. Both should list the same people. Copy the link into a fresh window, then try a code that doesn't exist.
In Capybara Hot Spring, joining an unknown code could leave stored data behind. We changed the join checks to refuse missing rooms. A mistyped invite should only show a useful message.
Step 4: Give the host clear choices
In a room with friends, zero computer players is a useful choice. Two people may want a race between themselves. Show the host's choice to everyone, and keep the Start button with the host.
Let the private-room host choose zero or more computer players and
when to start. Guests can see the choice but can't change it.
Keep people plus computers within the seat limit. Check this on the server.
In Sinkhole Soi, the host can choose up to three computer players, with fewer available as friends join. Try zero first, then add some. Use the guest's window to check that it cannot change the room's settings.
A review of Sinkhole Soi caught a version that let any room member change the computer count. Hiding a button from guests didn't protect the rule; the server had to check who asked.
Decide who takes over if the host leaves. Passing the role to someone still waiting is easier on friends than making everyone create a new room.
Step 5: Give rounds a start, an end and a way back
A round needs a clear flow: wait for friends, start together, play, show results, then offer another go. Decide what happens to late arrivals too. Letting them watch until the next round is a fair starting point.
Add a waiting room, a shared countdown, a round end and results.
Let late arrivals watch until the next round. Play again should keep
our friends together in the private room, with the same computer choice.
Finish a round in both windows. Each player should see the same winner, even if one finishes early. Then use Play again and check the room code and player list. Also try a round where nobody reaches the finish.
In Capybara Kart, a review found that a race run to the full time limit could end with "That room is closed" instead of results. The room's end timer started a moment too early. We moved it so results always come first.
For a shared building game, replace results with saved progress and a way to return to the same place.
Step 6: Handle sleeping phones and people leaving
Someone will lock their phone, answer a message or lose signal. Pick what the others should see while that person is away. A race can hand their kart to a computer; a hiding game needs a different rule.
Handle a phone sleeping or losing signal mid-round. Give the player
a short chance to return to the same seat. Show when they're away.
Keep the round going, free abandoned seats, and stop retrying if the room closes.
Lock one phone while the other keeps playing. Unlock it, then repeat the test and leave it locked. A return should restore the seat or explain why it is gone. Nobody else should wait forever for an absent player to finish.
In Hide in Paint, an early idle rule would kick a hider who stayed still. Staying still is the point of hiding. We changed the check so silence from movement alone didn't mean the person had left.
Step 7: Keep the free plan free
On 19 November 2026, a review of Sinkhole Soi found that two forgotten tabs could keep a room playing round after round with nobody there. A few rooms like that could have used up the free plan. We now close quiet rooms and limit how many rooms one person can open.
Stop empty and abandoned rooms. Computers must not keep games running
alone forever. Limit room creation and connection attempts per person,
while allowing friends on one Wi-Fi. Stop background retries after failure.
Leave a room, close both tabs, then check that the server stops its game loop. Ask the tool to test forgotten open tabs too. Closing the screen is only half the job if the server keeps playing.
For a shared building game, stop live work while keeping saved buildings. Ask the tool to check saved-data writes as well as connections, so moving a cursor doesn't save the whole place each time.
Read 19 November 2026: Cloudflare Workers pricing includes 100,000 Worker requests a day and 10 milliseconds of CPU work per call on Free. Static asset requests, for the game page and files, are free and unlimited. Workers Paid starts at $5 USD a month, plus usage above its included amounts.
Rooms have separate limits: Durable Objects pricing lists 100,000 requests and 13,000 GB-seconds of active time a day, plus SQLite storage allowances. GB-seconds are the memory a room is given (128 MB) multiplied by the time it stays active. Free accounts need SQLite-backed objects; hitting a free limit makes affected operations fail.
The io guide has the full hosting allowance table; check account-wide usage in Cloudflare's dashboard after your friends play.
Step 8: Test with friends on phones, then share
Two windows help you find room bugs. Two people on phones help you find the awkward bits: tiny buttons, steering under a thumb, or an invite that opens the wrong screen. Have one friend join from a different internet connection too.
Help me test on two real phones: invite, join, choose computers,
start, finish, play again and leave. Check portrait and landscape.
Then prepare the game page and room server for my own Cloudflare account,
with local checks and publishing commands explained before I run them.
Follow the invite from your chat app, play a whole round, and swap who hosts. Try Practice when online play is unavailable. Only share the game more widely once a friend can get from link to results without you explaining the menus.
The first phone controls in Capybara Kart steered the wrong way. A working connection and a finished race didn't catch that. Someone had to drive it and say what felt wrong.
Old tabs need a clear reload message after some updates; use the io guide's reload step for that check.
If something looks off
If friends see different computer counts, ask the tool to show the room's computer count in both menus. If Play again splits the group, keep it tied to the private room. If the free allowance drops while nobody plays, check for rooms that keep ticking or retrying saves.
About the examples and tools
The examples come from our builds, play checks and code reviews, including the room fixes on 19 November. You can play all four linked games. The video shows Capybara Kart against computer players.
The game code and art aren't included in this free guide.
For big public arenas with strangers, use How to make an io game with AI.
For your first solo game, start with How to make a web game with AI.
For a bigger 3D project with the full source, the kart kit is $39.
Questions people ask
Can I make a multiplayer game without knowing how to code?
An AI coding tool can write the code, but you still need to choose the rules and play each change. Start with one small game against computer players. Add rooms once that feels good.
Can I make an online multiplayer game for free?
Cloudflare's Workers Free plan can host the game page and small multiplayer rooms within its limits. Your AI coding tool has separate access costs. The Workers Paid plan starts at $5 USD a month plus usage above its included amounts. Pricing read 19 November 2026.
Do computer players need a paid AI API?
No. Ask the coding tool to write ordinary game rules for them, such as steering towards the next corner or looking for a hiding spot. They run as part of your game.
How many computer players should Practice and private rooms allow?
Practice should let the player choose one or more, up to the game's seat limit. A private room should let the host choose zero or more, so friends can play by themselves.