Basemind debugging with Claude Code

Learn debugging techniques with Claude Code that led to a 7x faster optimization in a 20M line monorepo.

miércoles, 8 de julio de 2026 • 6 min read • Q2BSTUDIO Team

Performance improvement: 7x faster

In today's software development ecosystem, debugging complex systems requires more than opening an editor and following traces. The combination of artificial intelligence tools and rigorous methodologies is redefining how engineers approach seemingly inscrutable problems. A recent case of optimizing a code intelligence tool —a multilingual scanner supporting over 300 languages— illustrates this new paradigm. The process started from a trivial symptom (an incorrectly installed version) and ended with a seven-fold speedup, two patches sent to upstream repositories, and the disabling of a costly feature. What is relevant is not just the numerical result, but the methodology employed: observing the live system before reading the source code, measuring derivatives instead of snapshots, isolating confusing variables, and delegating mechanical work to AI agents while the engineer retains critical verification.

The first lesson is that the symptom rarely matches the actual failure. Instead of opening the scanning module, the team examined running processes with classic tools like ps and lsof. They discovered that an obsolete process —a server launched from a previous editor session— was consuming CPU non-stop. The fix already existed in the repository, but the deployed version predated the patch. This type of confusion is common in environments where multiple versions coexist across package managers, PATH, and plugins. Verifying the artifact that actually runs, rather than an abstraction, becomes the first filter in any investigation. If a company needs to ensure its deployments are free from these risks, having custom applications that integrate version verification and system health mechanisms can save hours of unproductive debugging.

Dynamic measurement made it possible to distinguish between a resource leak and a converging process. By monitoring CPU, cache size, and blob count over time, it was observed that disk writes stopped and CPU usage dropped to one core. That pattern describes a scan that finishes, not an infinite loop. The derivative (rate of change) is more informative than the absolute value. To automate this monitoring, shell monitors were programmed that only reported when a state transition occurred: from active scanning to idle, or from activity to stagnation. This philosophy of 'encoding the hypothesis in a monitor' allows the machine to watch while the human focuses on analysis. In a business context, integrating this type of custom alerts into AI for businesses can transform the operation of critical systems, reducing anomaly detection time.

Another key moment was the blocking of a multiple worktree. A process remained at 0% CPU and lsof itself hung when querying the socket. The last log pointed to an optical recognition backend that made a network call without a timeout and encountered a firewall. Instead of debugging the hang in its full context, the engineers chose to change one variable: they rebuilt the tool without that optional functionality (behind a feature flag) and studied the scanner in isolation. This strategy of removing the extraneous variable is fundamental in any serious debugging. When two failures become entangled, separating them allows understanding each one individually. In the field of cybersecurity, for example, unexpected interactions between components are common; a similar approach helps identify attack vectors or insecure configurations.

After obtaining a clean binary, baseline measurements were taken: scanning a repository of 67,700 files took 181 seconds, re-analyzing all files even if their blobs already existed in the shared store, and rebuilding the git history index for each worktree in about 160 additional seconds. By reading the code to confirm the mechanism —not to guess a patch— it was discovered that the fast paths for unchanged files depended on an index per worktree which, being empty in a new worktree, caused all files to fall into the full re-analysis path. The solution was small and followed patterns already existing in the codebase, accompanied by a regression test that failed before the fix. After applying the change, the same scan went from 181 to 25 seconds: a 7x improvement, with all files reused and peak memory reduced by half. This type of optimization is only possible when deep reading is combined with rigorous quantitative verification. For organizations seeking custom software with high performance, this measure-analyze-fix-remeasure cycle is the foundation of any quality project.

Debugging also crossed the boundary of external dependencies. The network hang sank the tool because the hf_hub library, in versions 0.4 and 0.5, built a ureq agent without a timeout. The bug was in a third party, so the repository was forked, all download points were mapped, and a watchdog was added: run the blocking request in a separate thread, fail after a configurable timeout, and degrade the service by skipping the model instead of hanging. The mechanical work of editing multiple files was delegated to a sub-agent with a tight specification, but the engineer reviewed every diff, recompiled, and ran the tests personally. The sub-agent even corrected a wrong assumption about a type that was not Clone. In the end, a pull request was sent to the original project along with an honest bug report. This collaboration between human and AI agent —where the machine executes repetitive tasks and the human retains decision-making and verification— is a replicable model for any development team. At Q2BSTUDIO we apply it systematically in cloud services aws and azure projects, where operational efficiency and traceability are critical.

Sometimes the best solution is to remove the problematic functionality. Monitoring showed that the embedding pass got stuck on a general language model, with an empty directory and an obsolete lock. But the deeper question was not how to speed it up, but whether code embeddings should exist. By analyzing what was being embedded (symbol, signature, documentation, body) versus what was embedding it (a model trained on natural language), it was found that the tool already built a BM25 index on the same text. The embedding model added little value for code, while adding 100 MB of download and gigabytes of vectors. The decision was to disable code embeddings by default, keep them only for documentation and images, and add a per-file exclusion mechanism. A disabled feature cannot hang, have memory leaks, or hog CPU. This reflection on the real cost of features —not only technical, but also operational— is key to designing business intelligence services and process automation solutions that do not overload systems with superfluous functionalities.

The methodologies extracted from this case are universal: verify the running artifact, measure dynamics instead of snapshots, encode the hypothesis in a passive monitor, isolate confounding variables, read the code to understand the mechanism before intervening, delegate mechanical edits to AI agents but review every change manually, and, above all, ask whether the costly functionality should exist. These lessons fit perfectly with Q2BSTUDIO's philosophy, where we combine the development of custom applications with a pragmatic, data-driven approach. Our team integrates AI agents into workflows to accelerate repetitive tasks, while applying rigorous review and testing processes. Additionally, we offer AI for businesses that allows our clients to incorporate intelligent assistants without sacrificing control or security. Whether optimizing an internal search engine or deploying a real-time analysis system, the combination of solid methodology and cutting-edge tools is what makes the difference between a product that works and one that truly scales.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.