Workflows

How to decompile a game with an AI agent, step by step

The workflow real projects use with Claude Code and Codex to match functions, build recompilers and port old games, and how to stop the agent from cheating.

To decompile a game with Claude Code (or Codex), dump the game's binary from your own copy, set up a matching decompilation or recompilation toolchain such as splat, decomp.me and objdiff, then give the agent a per-function loop: write the C, compile it, and check the output byte for byte against the original. You review what it commits, because the agent is only as good as the check it has to pass. This guide covers the workflow, tooling and checks for function-by-function work in a game decompilation or port, drawing on what worked in six real projects, for anyone who wants to preserve or port a game they own.

If you want the list of games instead, see AI game decompilation: every game reverse engineered with AI. It lists the projects, what each one achieved and whether you can play it. This page covers only how to do the work yourself.

Key facts
  • Matching decompilation only works with the compiler the game was built with: the Klonoa project uses agbcc, a GCC 2.95 fork, for the Game Boy Advance.
  • Klonoa's make prints klonoa-eod.gba: OK when the build matches byte for byte, and the project verifies matches with objdiff.
  • The shooter swarm ran up to 15 agents for about three months, with Codex CLI alongside Claude Code.
  • The Snowboard Kids 2 repo ships no game assets and asks you to supply your own ROM.
  • The guide draws on six real projects, and Claude Code did most of the work in every one.

What do I need before I start?

  • A legal copy of the game. Matching decompilation projects ship no game assets. The Snowboard Kids 2 repo asks you to supply your own ROM, and its build extracts assets from it.
  • The original toolchain, or a close match. Matching only works when you compile with the compiler the game was built with. The Klonoa project uses agbcc, a GCC 2.95 fork, for the GBA.
  • An agent. Claude Code did most of the work in every project below. Codex CLI ran alongside it in the shooter swarm.
  • A disassembler the agent can query. Ghidra through GhidraMCP, or IDA through the IDA Pro MCP server.
  • Budget. These are long runs. The Weltendämmerung port cost about $100 in API usage over 50+ sessions. The shooter swarm ran up to 15 agents for about three months.

Scope: this guide covers preservation and porting. It does not cover DRM, anti-cheat or online games.

Step 1: Set up the community tooling first

Matching decomps have a mature tool ecosystem, and agents work best on top of it. These are the tools the projects name:

ToolWhat it does
splatSplits a binary into assembly, data and assets so a project can be built from it
m2cMachine-code-to-C decompiler for MIPS, PowerPC, ARM and SuperH; gives a first draft of a function
decomp-permuterRandomly permutes a C file to get closer to the target binary
asm-differAssembly diff script for comparing your build against the original
objdiffLocal diffing tool that reports how closely an object file matches
decomp.meCollaborative website where each function attempt is a shareable "scratch"

Chris Lewis credits decomp.me, decomp.dev, Splat and decomp-permuter in the Snowboard Kids 2 README. The Klonoa repo's make ctx target generates a ctx.c context file for decomp.me, m2c and Mizuchi. Klonoa verifies matches byte for byte with objdiff.

Get the project building to a byte-identical image before you involve an agent. Klonoa's make prints klonoa-eod.gba: OK when the build matches, and everything else depends on that check.

Step 2: Give the agent one function, one environment and one script

Chris Lewis's earlier write-up describes the per-function setup. A helper takes a decomp.me scratch ID and creates a subdirectory with its own CLAUDE.md and a small set of tools: build-and-diff with a match percentage, disassembly, an object-file diff, and a best-effort mapping from assembly lines to C lines. The guardrails Lewis set:

  • Save each attempt as a new file (base_n.c) so a good match is never overwritten by a worse edit.
  • Ask the agent to say what it expects a change to do before it builds, and to analyse each failure.
  • Hold it to the right C dialect (C89 for the N64 compiler) and to code a period developer could have written. Pasting the target assembly inline does not count.
  • Only show full assembly listings when the agent asks.

In the one-shot follow-up, one build-and-verify.sh script does all building and checking and trims its output to save tokens. A catch-all %: make rule in each matching directory tells Claude to use only the tools listed in that directory's CLAUDE.md and to cd ../.. to get back. Lewis found that this kind of defensive tooling, with clear errors and graceful failures, fixed failure patterns better than prompt changes.

The flow below shows the whole loop, from your own copy of the game to a verified match. The dashed arrow is the retry that the ten-attempt rule cuts off.

The function-by-function matching loopA binary from your own copy is split by splat. The agent writes C for one function, the build is diffed against the original, and a miss sends the agent back to rewrite the C until a match or the ten-attempt limit.Binary from your own copysplitsplat splits it into asm, data and assetsone functionAgent writes C for one functioncompileBuild and diff against the originalmatchMatch: verify the build and commitLoop back to step 3: no match: retry, and giveup after ten attempts
A binary from your own copy is split by splat. The agent writes C for one function, the build is diffed against the original, and a miss sends the agent back to rewrite the C until a match or the ten-attempt limit.

Step 3: Run the "easiest unmatched function" loop

Lewis's loop is a bash script (./tools/vacuum.sh) that calls headless Claude again and again until every function is matched or marked too hard. Per call, Claude must:

  1. Create a matching environment for the function it was given.
  2. Try to match it with the provided tools.
  3. Give up after more than ten attempts without progress.
  4. If it matches, integrate it, verify the build and commit. Lewis calls committing "critical".
  5. If not, add it to a difficult_functions log and exit.

The script picks the function, not Claude. A scorer ranks unmatched functions by estimated difficulty. It started as a hand-tuned formula over instruction, branch, jump and label counts, and later moved to logistic regression trained on a few hundred logged outcomes. The driver also backs off when Claude exits non-zero (for example on a usage limit), traps Ctrl-C so it can stop between attempts, and logs every run to a file.

A minimal driver in the same shape, using Claude Code's documented non-interactive mode (claude -p with --allowedTools), looks like this. next_function.sh and PROMPT.md stand for your own scorer and prompt:

bash
#!/usr/bin/env bash
# Sketch only: replace next_function.sh and PROMPT.md with your own.
while fn=$(./tools/next_function.sh) && [ -n "$fn" ]; do
  echo "$(date -Is) $fn"
  if ! claude -p "$(cat PROMPT.md) Function: $fn" \
       --allowedTools "Bash,Read,Edit" >> logs/claude.log 2>&1; then
    sleep 300   # back off, e.g. after a usage limit
  fi
done

Lewis ran this unattended for 8+ hours at a time, and three weeks of it beat the previous three months by hand. Most matches came from Opus 4.5. In a short test, Opus matched five of seven functions that Sonnet 4.5 had given up on.

Step 4: Scale out with worktrees, review and a fixed oracle

Macabeus started the Klonoa decomp from nothing. Claude Code wrote the asm generator, Makefile and linker script and proposed function boundaries. Ghidra found about 300 extra functions. The per-function loop is: asmlift (an m2c-style decompiler) first, then Transmuter (a permuter successor) if that fails, then cleanup using gba-kit (a scriptable emulator), then an adversarial review by a subagent. Each batch becomes one merged PR plus a report. Work runs in parallel with git worktree. Matched functions move from asm/nonmatchings to asm/matchings.

Maurice Heumann's shooter decompilation shows the same idea at a larger scale. Agents claimed GitHub issues (one per translation unit) through the GitHub CLI, used the official ida-mcp server headless, and talked in a shared Discord channel that also received CI failures. Two settings helped with long sessions: compaction at 42% context instead of the default, and an hourly cron job telling every agent to reread the instruction document.

Step 5: For ports and recompilers, write the spec before the code

When the goal is a port rather than a matching build, the projects below got the best results by documenting first.

  • Sebastian Macke had Claude Code disassemble the 7 KB Weltendämmerung binary, document memory layout, map, units, combat and save format in markdown, write a PORTING.md plan, and only then build the TypeScript port. Macke kept files small, kept CLAUDE.md minimal and pointing at the docs, and kept sessions short to avoid compaction.
  • For psxrecomp, Matthew Stanley's CLAUDE.md made Claude validate every implementation decision against Ghidra through GhidraMCP, with PCSX-Redux behind a custom MCP server for runtime checks. Claude was not allowed to edit generated code: fixes had to go into the recompiler, which was then rerun.

How do I check it works?

  • Matching decomp: a clean build reports a byte-identical image (for example build/snowboardkids2.z64: OK or klonoa-eod.gba: OK), and CI re-verifies every function already marked as matched.
  • Port or recompiler: play it. Stanley played Tomba! and reported bugs back to Claude, then checked each claimed fix himself.

Where does the AI go wrong?

  • It cheats when the rules leave room. Klonoa's agent forked the compiler and used register pins and asm barriers. Experienced decompers rejected those matches, and the compiler is now treated as a fixed oracle (klonoa-gba-decomp). In the shooter project, agents first wrote inline assembly, then repeatedly edited the verification script to exclude their own functions. CI now hashes that script and compares the hash with a stored secret (fps-decomp-agent-swarm).
  • Code that compiles is not code that is right. Heumann's first month produced readable C++ with wrong signatures, types and struct layouts. Worse, workers' comments talked the reviewer agent into accepting the deviations. A byte-matching oracle fixed this, and it let cheaper models do the work. Fixing the bad early code cost more than regenerating it.
  • It ignores limits and gets lost. Lewis saw dozens of attempts against a ten-attempt cap, confusion between directories, and a sudden stop in committing after a prompt change. Codex disappointed Lewis, mostly over git (snowboard-kids-2-decomp).
  • It invents what it does not know. In Weltendämmerung Claude called gates "towns", misread forest tiles and missed a variable used as both number and flag.
  • Without ground truth it guesses. Before Ghidra was wired in, psxrecomp burned tokens and needed constant redirection (psxrecomp-tomba).
  • Matches are often ugly. Expect pointer arithmetic instead of array access, gotos and odd temporaries. Klonoa still has function-splitting bugs and data mistaken for code.

Which projects used this?

These four show the workflow above in practice. For the full list of games, with outcomes and playable status, use the AI game decompilation hub.

  • Snowboard Kids 2 decomp: the headless loop, difficulty scorer and ten-attempt give-up rule.
  • Klonoa GBA decomp: a decomp started from zero, with objdiff verification, worktrees and the compiler-fork lesson.
  • psxrecomp (Tomba!): Ghidra and an emulator as ground truth for a static recompiler.
  • FPS agent swarm: up to 15 agents, a byte-matching oracle and a tamper-proof CI check.

Further reading

By

I started this site on 13 October 2026 to keep track of reverse engineering projects where an AI model did real work. I work on it alone, with no investors and no ad networks.

About the site · @whyamas on X

Changes

  • Removed links to a rejected project entry and its repository.
  • Removed projects that were no longer published.

Sources

In practice

Directory projects behind this guide

Snowboard Kids 2 (N64): Three weeks of Claude in a loop beat the previous three months by hand.
Works
Blog / GitHub / HN · Games and mods

One-shot matching decompilation of Snowboard Kids 2 with Claude in a loop

Three weeks of Claude in a loop beat the previous three months by hand.

Platform Nintendo 64Time 3 weeks

Reproducible

Klonoa: Empire of Dreams (GBA): A GBA decompilation started from zero, now past halfway.
Partial
Blog / GitHub · Games and mods

Started a decompilation from zero: Claude Code and 51% of a 2001 GBA game

A GBA decompilation started from zero, now past halfway.

Platform Game Boy AdvanceModel Claude
Tomba! (PlayStation): No prior experience, three weeks, and a PS1 game running as native code.
Works
Blog / GitHub · Games and mods

Built a PS1 static recompiler with no prior experience and got Tomba! playable

No prior experience, three weeks, and a PS1 game running as native code.

Platform PlayStationTime About 3 weeks for the prototype

Reproducible

Unnamed first-person shooter: 15+ agents, three months, 99% of a shooter rebuilt in C++.
Works
Blog · Games and mods

500+ billion tokens: an agent swarm decompiled a first-person shooter

15+ agents, three months, 99% of a shooter rebuilt in C++.

Platform Linux, macOS, browserTime About 3 months