The Deska blog
Code Archaeology With Agents: Understanding Inherited Systems
Learn how to perform code archaeology with agents to map legacy systems, trace logic, and document inherited codebases efficiently using modern AI tools.
· 10 min read
Inheriting a massive, undocumented legacy codebase feels less like software engineering and more like an excavation. When you perform code archaeology with agents, you transform the process of deciphering ancient logic into a structured exploration of data flows and hidden dependencies. The primary challenge of inherited systems is not just understanding what the code does, but why it was written that way, which side effects exist, and where the fragile joints are located. Modern AI agents have become specialized tools for this specific type of investigation, allowing developers to map out complex architectures without spending weeks manually tracing every function call.
The Reality of Inherited Systems
Legacy code is often defined as code without tests, but in practice, it is code that reflects a different era of architectural decisions. These systems often feature deep nesting, global state management that spans multiple files, and inconsistent naming conventions. When a developer joins a project or takes over a maintenance contract, the first few days are usually lost to environment setup and basic navigation.
Traditional exploration involves using grep to find string occurrences, stepping through debuggers to see state changes, and reading Git logs to understand the evolution of a feature. While effective, these methods are slow. They require the developer to hold a massive mental model of the system in short term memory. Code archaeology with agents changes the dynamic by offloading the initial mapping and pattern recognition to an autonomous or semi autonomous assistant that can read thousands of lines of code in seconds.
Strategies for Agentic Exploration
To effectively use AI agents for system comprehension, you must treat them as specialized investigators. Instead of asking generic questions, provide specific scoped tasks that build a picture of the system.
- Logic Tracing: Ask the agent to follow a specific user action from the API entry point down to the database layer. This helps identify the middleware, validation, and transformation steps.
- Dependency Mapping: Use agents to list all external services and internal modules that a specific component relies on.
- Pattern Identification: Large systems often have repeated patterns or anti patterns. An agent can quickly identify where specific architectural styles are used, which helps in understanding the original author's intent.
- Safety Assessment: Before refactoring, ask an agent to identify potential side effects of changing a specific function, looking for global variables or shared state.
These strategies reduce the cognitive load on the developer. Rather than reading every script, you can focus on the high level architecture while the agent handles the forensic analysis of the implementation details.
Comparing Tools for System Analysis
Different tools offer various approaches to code exploration. The best choice often depends on whether you prefer a deeply integrated IDE experience or a more modular, flexible environment.
| Tool Category | Primary Strength | Limitations |
|---|---|---|
| Integrated IDE Agents | Deep integration with editor features and syntax highlighting. | Can be constrained by the IDE UI metaphors and resource usage. |
| CLI Based Agents | High speed and excellent for batch processing files. | Lacks visual context and spatial organization of information. |
| Spatial Workspaces | Ability to see multiple agents and code views side by side. | Requires a different mental model for workspace management. |
Tools like Claude Code or Codex CLI are powerful because they interact directly with the file system. They can run tests, search for files, and summarize their findings. However, when you are dealing with a complex legacy system, seeing the information is just as important as generating it.
Visualizing Architecture with Deska
Deska provides a unique environment for performing code archaeology by offering an infinite canvas workspace. Instead of switching between tabs and losing context, you can place multiple panels anywhere on a large canvas. This is particularly useful when you need to run several AI coding agents side by side to compare their interpretations of a legacy module.
In Deska, you can open a terminal for Claude Code in one panel, the code editor for a specific file in another, and a browser window for existing documentation in a third. You can zoom out to see the entire logical flow you are investigating. The Ask Deska assistant can help manage this space by opening relevant panels or tracking your progress through the investigation.
Because Deska is local-first, your code and the sessions generated by your agents stay on your machine. This is a critical factor for many enterprise legacy systems where privacy and security are paramount. You can use your own API keys for the coding agents if you prefer the lifetime tier, ensuring that your exploration data remains under your control.
The Process of Documentation via Agents
One of the most valuable outputs of code archaeology is the creation of new documentation. As you explore the system, you can use agents to generate README files for directories that lack them or to create Mermaid.js diagrams representing the flow of data.
- Initialize the agent within the root of the legacy folder.
- Direct the agent to analyze the
package.jsonor equivalent dependency file to understand the stack. - Use the agent to write a summary of each major module.
- Verify the agent's summary by reviewing the code in the Monaco editor.
- Store these findings in notes directly on the workspace for future reference.
This iterative process turns a mystery into a documented map. The goal is not just to fix a bug, but to leave the codebase better understood for the next developer.
Monitoring Long Running Tasks
Deep analysis of a legacy system can take time. When an agent is tasked with scanning a massive directory to find security vulnerabilities or deprecated patterns, you might not want to sit at your desk. The Deska mobile app allows you to monitor these agent threads from your phone.
The mobile connection uses a secure relay to pair your devices directly without exposing ports to the internet. This allows you to check if a long running scan is complete or to read the summary generated by an agent while you are away from your workstation. It keeps the momentum of the archaeology project going even when you are not actively typing.
FAQ
How to use AI to understand legacy code?
You should start by providing the AI with the project structure and primary entry points. Use a tool like Deska to run an agent that can traverse files, asking it to explain the data flow of specific features. Combine the agent's output with manual code reviews to verify accuracy.
Can AI agents document undocumented codebases?
Yes, agents are excellent at summarizing logic and identifying the purpose of functions. By running an agent over an undocumented module, you can generate a technical overview that describes dependencies, inputs, and expected outputs, which serves as a foundation for formal documentation.
Is it safe to use AI for private legacy systems?
Security depends on how the tool handles your data. Local-first tools like Deska keep your files on your machine. When using a lifetime tier with your own API keys, you control where the code is sent, which is often a requirement for sensitive legacy infrastructure.
Getting Started with System Discovery
Understanding an inherited system is a marathon. Using agents to perform the heavy lifting of code archaeology allows you to reach a state of productivity much faster than traditional methods. By organizing these tools within an infinite canvas and maintaining a local-first approach to data, you can build a comprehensive map of any codebase regardless of its age or complexity.
To begin exploring your legacy systems with a more flexible workspace, you can download the Deska app for Mac, Windows, or Linux. The workspace is free to use, and you can start bringing your own agents into the canvas to clarify your most complex inherited projects today.