# Vibe Coding Games Without the Chaos — Git, Tests and a Closed Loop

Vibe code a game without breaking it every week. Git branches, pull requests, tests the agent writes, and a loop where the agent checks its own work.

_Last updated: 2026-11-23_

You can vibe code a game without the chaos if you stop treating the AI agent as a chat partner and start treating it as a developer on your team. That means three things: every change goes through Git on its own branch, every feature the agent builds is covered by tests the agent writes, and the agent checks its own work in the running editor before it hands anything back. Then your job shrinks to dropping in tasks, reviewing results and saying what to fix.

The term vibe coding comes from a February 2025 post by Andrej Karpathy, who described giving in to the vibes and forgetting that the code even exists. Collins Dictionary made it its word of the year for 2025. It is a great way to get a prototype on screen in an evening. It is also the fastest way we know to end up with a game where fixing the jump breaks the camera, and nobody can tell which prompt did it.

This post is the workflow we use on our own projects. It is opinionated: these are our recommendations from building games with agents every day, not the only way to do it.

## Why Vibe Coding Games Turns Into Chaos

Games are harder to vibe code than a web form, for a few reasons:

- Systems are tightly coupled. Movement, physics, camera, animation and input all touch each other, so a small change in one leaks into the others.
- Many bugs are invisible in code. A collider that is two centimetres off or a jump that feels floaty compiles fine and reads fine.
- State lives outside the code. Scenes, prefabs, materials and project settings change too, and an agent can edit them as easily as a script.
- The agent forgets. A new chat does not remember the decision you made yesterday, so it happily makes the opposite one today.

The usual vibe coding loop has no defence against any of this: you prompt, it edits, you glance at the game, you prompt again. After a week you have a pile of changes with no history, no tests and no way back. The fix is not to vibe less. The fix is to put a structure around the agent so that its speed works for you.

## Rule 1: Git Is Your Undo Button

In our experience, Git is the single biggest difference between vibe coding that ends in a shipped game and vibe coding that ends in a fresh empty project. Use it even if you work alone.

1. Put the project under Git before the first prompt, with a .gitignore for your engine (Unity's Library and Temp folders, Godot's .godot folder, Unreal's Intermediate, Saved and Binaries folders).
2. Give every task its own branch. One feature, one branch, one agent.
3. Have the agent commit in small steps, with messages that say why, not only what.
4. Merge into main only through a pull request, after you have looked at the diff and the tests are green.

A branch per task is what makes the rest possible. If the agent goes off in the wrong direction, you delete the branch and lose nothing. If two agents work in parallel, they do not overwrite each other's files. And the history tells you exactly which task introduced a bug.

```bash
git switch -c feature/glide
# the agent works and commits in small steps
git diff main --stat
git push -u origin feature/glide
gh pr create --fill
```

Use Git LFS for large binary assets such as textures, audio and models, so the repository stays fast. For several agents on one machine, git worktree gives each one its own folder on its own branch without a second clone.

Review image and model changes, not only code. In the AI Game Developer app, Source Control shows a side-by-side comparison for changed images, so you see how a texture changed before you commit it. We walk through it in ai-game.dev/blog/ai-game-dev-workspace-panes-previews-git.

## Rule 2: Make the Agent Cover Every Feature with Tests

The real chaos in vibe coding is not the first bug. It is the feature that worked on Monday and quietly broke on Thursday because another prompt touched the same code. Tests are how you stop that. The good news is that agents are very good at writing them, and they do not get bored.

Our rule is simple: a feature is not done until the agent has written a test that would fail if the feature broke. Put it in the task itself, for example "Add a glide, and cover the fall speed cap and the stamina refill with tests."

What to test in a game, from cheapest to most expensive:

- Pure logic: damage formulas, inventory rules, save file round trips, level generation seeds. Fast edit mode or unit tests.
- Gameplay rules in a running scene: the player cannot fall through the floor, a pickup adds score, a door opens with the key. Play mode tests.
- Regressions you already fixed: every bug the agent fixes gets a test, so it never comes back.

A play mode test in Unity is short:

```csharp
using System.Collections;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

public class GlideTests
{
    [UnityTest]
    public IEnumerator Glide_CapsFallSpeed()
    {
        var player = Object.Instantiate(Resources.Load<PlayerController>("Player"));
        player.transform.position = new Vector3(0f, 20f, 0f);

        player.SetGlideHeld(true);
        yield return new WaitForSeconds(1f);

        Assert.LessOrEqual(-player.Velocity.y, player.GlideMaxFallSpeed + 0.01f);
        Object.Destroy(player.gameObject);
    }
}
```

The agent should run the whole suite, not only the new test, before it says a task is done. With AI Game Developer in Unity, the agent runs edit mode and play mode tests itself with the tests-run tool and reads the failures, so "run the tests and fix what fails" is a complete instruction. Godot and Unreal projects can use their own test frameworks the same way, and CI should run the same suite on every pull request.

## Rule 3: Close the Loop So the Agent Checks Its Own Work

This is where vibe coding stops being chaotic and starts being fast. In a closed loop, the agent does not stop after writing code. It develops, tests, looks for bugs, fixes them and repeats, on its own, until the task is really done. You come back to a finished branch, not to a half-working idea.

For the loop to close, the agent needs to reach the engine, not only the files. Through the AI Game Developer plugins it can:

- Act inside the live editor by writing a short piece of code and running it right away: C# in Unity and Godot, Python in Unreal. It reads the result and decides the next step.
- Read the console after compiling and after play mode, so errors come back to the agent instead of waiting for you.
- Enter and leave play mode and run tests.
- Look at the result. Screenshot tools render one object in isolation from a chosen angle, or capture the scene view, the game view or a camera's view.

Vision is the part people underestimate. In our workflow, agents look at the scene from several angles, study a level from above and from the player's height, build and generate levels, build mechanics, and play the game to check that a mechanic works and that the balance feels right. A screenshot catches what a test does not: a wall that is floating, a pink material with a missing shader, a pickup hidden behind a crate.

In Unity, screenshot-isolated is on by default, and the scene view, game view and camera captures are hidden by default to keep the tool list small. Turn on the ones you need:

```bash
unity-mcp-cli configure ./MyGame --enable-tools screenshot-game-view,screenshot-scene-view
```

A good closed-loop task names the checks the agent must pass before it reports back:

1. Implement the change on its own branch.
2. Write or update tests for it and run the full suite until it is green.
3. Enter play mode, check the console for errors and warnings.
4. Take screenshots from the angles that matter and compare them with what was asked.
5. Review its own diff for anything risky, fix what it finds, and commit.
6. Open a pull request with a short summary of what changed and how it was checked.

## Your Part: Drop Tasks In, Review, Say What to Fix

When the loop works, the human role is small but important. You drop in tasks from time to time, you review the results, and you say what to fix. That is it. Here is how to do each part well.

### Write Tasks the Agent Can Finish

- Describe the goal and how you will judge it, not the steps: "Wren can glide for 3 seconds while holding jump; stamina refills on landing."
- Keep one task to one feature. A task that touches the whole game is a task that cannot be reviewed.
- For anything that touches more than a couple of files, ask for a plan first. In the AI Game Developer app, plan mode refuses every change until you approve the plan, which we show step by step in ai-game.dev/blog/plan-mode-ai-agent-game-development.
- Write decisions down where the next session will find them. The app's Knowledge Base keeps design rules as Markdown notes in the project, committed to Git, so the agent reads yesterday's decision instead of reinventing it.

### Review Like a Lead, Not a Proofreader

You do not need to read every line the agent wrote. Check what matters:

- Is the diff limited to the files the task should touch?
- Did the agent add a test, and did it fail before the fix and pass after?
- Are the tests and the CI checks green?
- Does it look right on the screenshots, and does it feel right when you play it for a minute?

Then reply with what to fix, in plain words, on the same branch. The agent goes around the loop again. Merge only when every check is green.

## If You Need X, Pick Y

- If you prototype a throwaway idea in one evening: pure vibe coding is fine, but still run git init first, so you can keep the parts that worked.
- If the game will live longer than a week: branches, pull requests and tests from day one. Adding them later costs more than starting with them.
- If you run several agents at once: one branch and one worktree per agent, and one feature per agent.
- If a bug keeps coming back: ask the agent for a failing test first, then the fix.
- If the agent cannot see what it did: enable the screenshot tools, and ask it to look before it reports.
- If cost matters, DeepSeek V4.1 Flash comes close to Claude Opus 5.5 at about 65 times lower cost in our usage; Opus 5.5 is best if money is no object (ai-game.dev/blog/best-ai-model-for-game-development).

## The Honest Trade-offs

This workflow is not free. Here is what gets better and what gets worse:

- Better: you can always go back, regressions get caught by tests instead of by players, and you can leave the agent working for an hour and trust what you come back to.
- Worse: each task takes longer than a raw prompt, because the agent writes tests, runs them and takes screenshots. You pay for that in time and in tokens.
- Worse at first: you need a minimal test setup and a CI job. The agent can set up both, but you have to ask for them once.
- Limit: tests and screenshots tell you a mechanic works, not that it is fun. Feel and balance still need you to play the game.

Token cost is where the tools you give the agent matter. Our RQL query tools let the agent read and change many objects in one query, which cuts the tokens it spends on engine data and makes a closed loop affordable; the benchmark is at ai-game.dev/docs/rql.

## Try It with AI Game Developer

AI Game Developer is a desktop app with a built-in AI agent and plugins for Unity, Unreal, Godot, Three.js, Bevy and BRUTAL. It gives the agent what a closed loop needs: code execution inside the live editor, tests, screenshots and console logs, plus plan mode, a Knowledge Base and Source Control in the app. It also works with Claude Code, Codex, Cursor and other MCP clients.

Download it at ai-game.dev/download, read the best practices for your engine at ai-game.dev/docs/best-practices, and start your next feature on a new branch with one extra line in the prompt: cover it with tests and show me a screenshot.

## Related

- Plan mode for AI agents: https://ai-game.dev/blog/plan-mode-ai-agent-game-development
- A game dev workspace for AI: https://ai-game.dev/blog/ai-game-dev-workspace-panes-previews-git
- A knowledge base for your game project: https://ai-game.dev/blog/game-project-knowledge-base-for-ai
- Best practices: https://ai-game.dev/docs/best-practices
- Download the app: https://ai-game.dev/download

---

Source (HTML): https://ai-game.dev/blog/vibe-coding-games
