Code Archaeology with AI
I recently revived some of my own old MATLAB code with an AI assistant, and it was code that nobody had touched in years. Every company has a closet full of old code like that. Maybe it’s a Perl script that generates invoices and nobody knows how it works. Maybe it’s a Java monolith that was “temporary” in 2014. Maybe it’s a MATLAB folder from grad school that you swear you’ll get back to someday.
Code archaeology is the practice of digging through old codebases to understand what they do, why they were written that way, and whether any of it is still useful. It’s a skill every developer needs but nobody teaches. And it turns out AI is good at parts of it and hilariously bad at others.
What AI is good at
Reading unfamiliar languages
This is probably the single best use case. I had MATLAB code I hadn’t looked at in over a decade. I don’t have a MATLAB license anymore. I barely remember the syntax. But when I fed the files to Claude, it could read them fluently and explain what each function was doing in plain English.
This generalizes well. Got a codebase in a language you don’t know? An AI assistant can act as a translator, walking you through the logic without requiring you to learn the full language first. I’ve used this trick with old Fortran code, R scripts, and even some truly cursed Bash. The AI doesn’t care that the code is ugly or that the variable names are single letters. It just reads it.
Identifying patterns and architecture
In a folder full of files you’ve never seen before, finding the entry point, what calls what, and where data flows is one of the hardest jobs. AI assistants are good at it: give them a handful of files and they can usually sketch out the architecture, identify the main abstractions, and explain the relationships between components. They’re especially good at recognizing common patterns: “this looks like a factory pattern” or “this is implementing a pub/sub system.” That pattern recognition saves hours of manual tracing.
Generating documentation
Old code is almost never documented. When it is, the documentation is wrong. AI can generate reasonable documentation from code that has none, and it does a better job than you’d expect. It picks up on implicit contracts, explains side effects, and can even flag things that look intentionally weird vs. accidentally weird.
I’ve started using this as a first pass whenever I inherit a codebase. Have the AI generate docs, then read the docs with the code open and correct whatever it got wrong. It’s faster than writing docs from scratch and it forces you to actually verify your understanding.
What AI is bad at
Understanding why
AI can tell you what code does, but it struggles to tell you why. That gap is the core limitation of code archaeology with AI.
When I was porting my MATLAB code, the AI could see that I was using a specific mutation rate schedule that decayed over generations. It could describe the schedule perfectly. What it couldn’t tell me was why I chose those particular values. Were they theoretically motivated? Did I tune them empirically? Was I just copying a paper? I honestly couldn’t remember either, but at least I knew that I didn’t know. The AI would cheerfully make up a plausible-sounding justification if I asked.
This is where hallucinations in code archaeology get dangerous. The AI will confidently explain the “reasoning” behind arbitrary implementation choices. If the original developer isn’t around to correct it, that fabricated context becomes the accepted truth. Always treat the AI’s explanations of intent as hypotheses, not facts.
Historical context
Code doesn’t exist in a vacuum. That weird workaround in line 47 might exist because of a bug in Python 2.6 that was fixed in 2.7. That strange data format might match what a vendor’s API used to return before they updated it in 2019. The AI doesn’t know any of this. It sees the code as it is today and reasons about it in isolation.
I’ve seen AI assistants suggest “cleaning up” workarounds that were there for good reasons. Without git history, issue trackers, or institutional knowledge, the AI is making assumptions about constraints that may or may not still apply.
Knowing what’s dead
One of the biggest challenges in old codebases is figuring out what’s actually used. Is this function called from somewhere? Is this configuration file still relevant? AI assistants will analyze code in isolation but they can’t reliably tell you whether a particular module is still reachable from any entry point. They’ll dutifully explain dead code as if it matters.
Static analysis tools are better at this. Use those first, then bring in the AI to understand the code that’s actually alive.
A practical workflow
Get the lay of the land manually. Look at the directory structure, check git history if it exists, read any README files. Don’t start with AI.
Use static analysis first. Run whatever linters, type checkers, or dependency analyzers apply. This gives you ground truth about what’s connected to what.
Feed the AI individual files with specific questions. “What does this function do?” works better than “explain this codebase.” Focused questions get better answers.
Cross-reference AI explanations with the code. When the AI says “this function handles authentication,” verify it. When it says “this was probably done for performance reasons,” be skeptical.
Use the AI for translation and porting. This is where it really shines. Once you understand what the code does and why, the AI can help you rewrite it in a modern language or framework much faster than you could do it manually.
Write your own documentation as you go, and don’t just accept the AI-generated docs. Correct them, because that’s how you learn the code.
The bigger picture
Code archaeology is going to matter more, not less: we’re generating code faster than ever, and the shelf life of that code isn’t getting any longer. The volume of legacy code in the world is growing, and the people who wrote it are retiring, changing jobs, or just forgetting what they did.
AI assistants are a genuine force multiplier for this work. They lower the barrier to understanding unfamiliar code, especially in unfamiliar languages. But they’re a tool, not a replacement for the hard work of actually understanding why code exists and whether it should continue to exist.
The real archaeology is reconstructing the decisions, constraints, and context that produced the code.
Stay in the loop
Get notified when I publish new posts. No spam, unsubscribe anytime.