Looped Weight-Space Programming: LLM-Written Transformers A single 19,936-weight transformer block written entirely by Claude Opus 5.5 and run in a loop solves 100% of the 30×30 Maze-Hard test mazes, beating Energy-Based Reasoners (EBR), which trains 1.8 million weights on 1,160 PFLOPs of compute and reaches 94.1%. The authors call the method "looped weight-space programming": each forward pass advances a shortest-path search one step, so the weight count does not grow with problem size. The result matters because Claude Opus 5.5 solves only 26% of the same mazes when asked for the shortest path directly, showing an LLM can write a single search step into weights and let the loop repeat it. Deep learning models normally get their weights from training. Once a transformer is trained, though, it is nothing more than a program written in matrices. If you know the program you want, you can skip training and write the matrices yourself. People have done this by hand for small problems related work related . Compilers such as Tracr https://arxiv.org/abs/2301.05062 go further, turning short programs into transformer weights automatically. Recently, Weight-Space Programming https://rikiyat.github.io/blog/weight-space-programming/ Takehi, Teoh, Zhang and Khattab, MIT CSAIL showed that a frontier LLM can edit a model's weights directly, without any training. Other groups have gone further and had LLMs set every weight of a tiny transformer, but only for toy tasks Singh https://csinva.io/weight-space-programming-autoresearch/analyze/toy examples/report.html , AdderBoard https://github.com/anadim/AdderBoard . In those transformers, every step of a computation takes a separate block. Scaling one up to a hard problem would mean a far bigger transformer and a far bigger Claude bill, since Claude would have to write every one of those extra weights. We wanted to know whether LLM-written weights hold up on problems that need long chains of reasoning. Our main test is Maze-Hard https://huggingface.co/datasets/sapientinc/maze-30x30-hard-1k , a benchmark of 30×30 mazes whose shortest paths run longer than 110 steps. Frontier LLMs struggle with it. For example, when Claude Opus 5.5 is asked for the shortest path, it solves only 26% of the test mazes it is given 1 https://arxiv.org/abs/2605.08605 . So instead of asking Claude to solve the mazes, we asked it to write a looped transformer that solves them, setting every weight by hand. The transformer has a single block with 19,936 weights. This block runs in a loop. Each forward pass moves a shortest-path search one step further, so the transformer keeps feeding the maze back through the same block until the path is complete. With enough passes, it solves 100% of the test mazes. That is more than the newest looped models trained for this benchmark reach. Energy-Based Reasoners EBR 2 https://arxiv.org/abs/2611.08977 , one of the strongest of them, trains 1.8 million weights on 1,160 PFLOPs of compute and solves 94.1%. That loop is what this post adds to earlier work on writing weights. With it, one block can run thousands to millions of steps, so the number of weights does not grow with problem size. We call this approach looped weight-space programming . Claude itself struggles to carry out a search of more than a hundred steps in text, even when we spell the algorithm out section 3 maze-claude . Yet it can write a single step of that search into weights, leaving the loop to repeat the step for as long as the maze requires. Programmers rely on the same trick whenever they write code for arithmetic they could not do in their heads. Language models gain from it too. On math word problems, they get more answers right when they write a short program that does the arithmetic than when they do the arithmetic in text 3 https://arxiv.org/abs/2211.10435 , 4 https://arxiv.org/abs/2211.12588 . Writing the weights by hand also makes the transformer easy to read. A trained model spreads its algorithm across millions of numbers, so recovering that algorithm takes substantial analysis. A whole study was needed, for example, to show that a small transformer trained on modular addition computes it with sines, cosines and trigonometric identities 5 https://arxiv.org/abs/2301.05217 . The constructed transformer has explicitly assigned state variables and operations. Claude decided what every number inside it stands for before it set a single weight, so we can read those numbers after any loop and watch the search spread across the maze section 6 interp . The goal is not just to replace conventional algorithms with transformers. It is to understand whether algorithmic reasoning can be explicitly programmed into neural networks rather than acquired through gradient-based training. This gives us interpretable solutions to difficult reasoning tasks, helps separate optimization failures from architectural limitations, and opens the possibility of combining learned representations with reliable algorithmic computation. We hope these hand-written transformers help advance research on looped models, by showing how much a single small block can compute when it runs in a loop and by giving training methods concrete solutions to aim for. Since every number inside them is known, they can also serve as test cases for interpretability tools. The weights and two in-browser demos are public https://github.com/mbzuai-oryx/LoopedWSP . 1. How the maze transformer works In a Claude Code session, Claude designed every weight itself, filling in the weight matrices with code, and we ran it on the test mazes only once, at the end appendix A prompts gives its task description . Claude made each cell of the maze one token, so a 30×30 maze becomes 900 tokens. It gave each cell a memory of 35 numbers, which the transformer carries from one loop to the next. Claude decided what each of these numbers stands for. A few of them record what the cell is a wall, the start cell or the goal and where it sits in the grid. Other numbers track the search. They hold the cell's distance from the goal, which neighbor is its next step and whether it lies on the path. The remaining 20 numbers serve as scratch space for whatever the cell reads from its neighbors. The transformer's single block has four attention heads, each with a single job. One lets every cell read the cell below it, while the other three read the cell to its left, to its right and above it. Claude then set every weight so that each loop updates these numbers the way it intended. The math Cell $c$, at row $r c$ and column $c c$, starts as the sum of three table rows. They put $1$, $r c$, $c c$ and $r c^2 + c c^2$ into its first four numbers and its type into the next three. The head that looks in direction $\delta = \delta r, \delta c $, one of $ 1,0 $, $ 0,-1 $, $ 0,1 $ and $ -1,0 $, scores every cell $n$ by $$ \frac{q c \cdot k n}{\sqrt{8}} \;=\; -100\,\big r n - r c - \delta r ^2 + c n - c c - \delta c ^2\big \;+\; \mathrm{const} c . $$ The neighbor at $c + \delta$ scores 100 more than any other cell, so the softmax puts a weight of $1 - O e^{-100} $ on it. The head copies five of that neighbor's numbers into five scratch numbers of $c$. These are its three count numbers $m 0, m 1, m 2$, its path flag and a binary number that is 1 when it points back at $c$. With this layout, each pass through the block performs one step of a standard shortest-path search. A wave from the goal. The goal starts at distance 0. On every loop, each open cell that has not been visited yet but borders a visited cell takes that neighbor's distance plus one. The visited area therefore spreads outward from the goal one step per loop. The math Write $m k c \in \{0, 1\}$ for the binary number that is 1 when the count of cell $c$ is $k$, and $\mathcal{N} c $ for its four neighbors. Two wave neurons for each $k$ compute $$ m {k+1} c \;\mathrel{+}=\; \tau\Big 2\ \ \sum {n \in \mathcal{N} c }\ \ m k n \;-\; 8\,\big \mathrm{wall} c + m 0 c + m 1 c + m 2 c \big \;-\; \tfrac12\Big , \qquad \tau z = \mathrm{ReLU} z - \mathrm{ReLU} z - 1 , $$ with the index $k+1$ taken mod 3. The argument of $\tau$ is at least $1.5$ when the cell is not a wall, has no count yet and has a neighbor with count $k$. Otherwise it is at most $-0.5$, so $\tau$ gives 1 or 0. After loop $t$, the cells with a count are the ones at most $t$ steps from the goal. Distance modulo 3. Apart from the position, every number in a cell's memory is binary, either 0 or 1. A cell therefore cannot store its distance to the goal as an ordinary number. Instead, it stores the remainder of that distance divided by 3, using three binary numbers, one for each remainder 0, 1 and 2. For example, a distance of 7 leaves a remainder of 1, so it is stored as 0, 1, 0. This is sufficient for the search. Two visited cells next to each other differ in distance from the goal by one, so the remainder is enough to tell which neighbor is one step closer to the goal. As a result, the transformer's size does not depend on maze size. The math Let $d c $ be the length of the shortest path from cell $c$ to the goal. Every step in the grid changes $r + c$ by one, so $d$ has opposite parity on neighboring cells. Two open neighbors $c$ and $n$ therefore satisfy $|d n - d c | = 1$, and $$ d n = d c - 1 \quad\Longleftrightarrow\quad d n \equiv d c - 1 \pmod 3, $$ since the two cases $d c \pm 1$ differ by 2, which is not a multiple of 3. Counting mod 2 would fail, because $d c + 1 \equiv d c - 1 \pmod 2$. Three binary numbers per cell are enough however large the maze is. Pointers. Each cell also has four binary numbers, one for each direction, down, left, right and up. Once a cell is visited, it sets the number for the direction of a neighbor one step closer to the goal to 1 and keeps the other three at 0. We say the cell points to that neighbor. A neighbor is one step closer when its remainder is one less than the cell's, with 2 counting as one less than 0. When several neighbors qualify, it picks the first in the fixed order down, left, right, up. The math Each cell has four binary pointer numbers $p \delta c $, one per direction, taken in the order $\delta 1, \dots, \delta 4$ = down, left, right, up. They are rewritten in every loop. Eight reset neurons, two per direction, cancel the old value, since $p - \mathrm{ReLU} p + \mathrm{ReLU} -p = 0$. At the same time, 24 pointer neurons compute $$ p {\delta j} c \;=\; \sum {k=0}^{2} \tau\Big 2\,m k c + 2\,m {k-1} n {\delta j} - 2\sum {i