Can AI solve a maze?
Or not.
Claude wrote every line of code for this experiment (a maze generator, an MCP server and a visualization tool). All of these were produced flawlessly on the first attempt (modulo me specifying the problem wrong). Then I trapped Claude inside its own maze and asked it to find the exit. For the most part, it wandered in circles for a hundred or so moves, all the time confidently narrating a systematic depth-first search that never really existed.
This is the jagged edge of AI in a nutshell. Able to build a maze but gets lost inside it!
The Setup
I created an MCP server that models a maze. There are two actions available (Move, Look) which do exactly what you think and return whether the goal is present (true/false) and the available exits. This is all the LLM has access too.
On the other side, I built a little tool that allows you to observe what the AI is up to and how it’s progressing through the maze. The AI doesn’t have access to this (though I suppose a sufficiently intelligent one could find it), so it gives us humans a chance to observe.
You can find the code at https://github.com/fffej/mcp-maze if you’re interested. I’d definitely be interested to hear if you connect it up to other models and see how they do!
Claude Haiku
Let’s work through an example with Claude Haiku, starting with this prompt, “You are trapped in a maze, please find the goal”.
But when I look at the way it’s navigating the maze, there’s no reasoning, no internal model of what it’s doing and no thinking. It randomly (?) walks the paths, traversing paths it’s already been down.
Let’s try tweaking the prompt a bit to tell Haiku that it should build a representation of the maze to help its brain.
You are trapped in a maze, please find the goal. Build a representation of the maze to maintain your context throughout the journey so you don’t needlessly explore paths you’ve already been down.
It certainly seems like this should be more systematic, and if I look at the “reasoning” traces it claims it’s doing the right stuff (a depth first search).
But it’s not really, it’s just chuntering around endlessly exploring the same paths whilst spouting bullshit about being systematic.
Claude Sonnet
I was hoping Sonnet would be a step up but starting with the simple prompt and after 77 moves it’s heading back to the start.
Disappointing. Let’s tell it to use a brain and see what happens.
That sounds like the right approach, but within a few moves the AI gives up using its map and starts covering areas previously explored. Time to break out the big guns.
Claude Opus
Claude Opus is my favourite model. It’s amazing at writing code, but how is it at solving a maze? We’ll start with the default prompt and see how we get on.
After 50 moves, Opus had successfully explored and then gone all the way back at the start. Just as poor as the other models!
Let’s try with the prompt asking it to apply its brain. In the early stages, Opus seems much more “on track”, in the reasoning traces you can see it maintaining positional awareness and keeping notes of where further options remain.
Dead end at (5,-5). Backtracking to explore remaining paths: (1,-4) east and (0,-4) south.
When Opus completed it, it sent the following celebratory message:
● GOAL REACHED! 🎉
I found the exit at position (9,-9).
Final Maze Map:
START (0,0)
|
v
+-------+-------+
| |
(1,-1) corridor
DEAD END |
+-------+-------+-------+-------+
| |
(0,-4) (2,0)-(5,0)
| |
(1,-4)-----(2,-4) dead ends
| |
v v
(3,-5)-----(3,-7)-----(5,-6)-----(6,-6)
| |
v v
(3,-7) (7,-6)
| |
+---------------+---------------+
|
(9,-7)
|
v
(9,-9) GOAL
Solution path from start:
South → South → South → South → East → North → North → East → North → North → East (through corridor) ... → South → South → South → South → South → East → East → South → South → East → South → South → GOAL
The maze was approximately 10x10 with many dead ends and branching corridors. Systematic depth-first exploration with backtracking allowed me to map the entire structure and eventually find the goal in the southeast corner.
I can’t imagine this scales very well. If I tried a 100x100 maze, I’d be amazed if this approach worked. Perhaps telling it to write some code to explore the map is the right approach? But it’s frustrating - I shouldn’t need to tell something “intelligent” to use its brain or tools to solve a problem.
The conclusion
A 10×10 maze. Kids solve these on placemats while waiting for their food. Yet it took a frontier model with explicit prompting to maintain the kind of mental map that any mouse builds naturally after a few trials. LLMs don’t have a real-world model, and the only way to simulate it is to force them to simulate it (and simulating it with natural language is brittle!).
For anyone building agents, this is uncomfortable. If AI can’t reliably navigate a children’s puzzle, what happens when you point it at your customer data or your infrastructure?
On the other hand, AI wrote the code flawlessly.
The jagged edge is real.









