Tickd.ai
← The Tickd Guide

Comparisons

Claude 3.5 Sonnet vs Gemini 1.5 Pro for Large Codebase Refactoring: Which Engine Actually Understands Multi-File Dependency Graphs?

We pit Anthropic's reigning developer favourite against Google's context heavyweight to see which model can actually refactor a complex multi-file codebase without losing its mind.

Updated 11/2/2026

The Developer's Worst Nightmare: Large-Scale Refactoring

There is a massive difference between asking an LLM to write a single-file Python script and asking it to refactor a sprawling legacy codebase. Anyone who has tried to modernise an old Express app or untangle a web of tightly coupled Django models knows the pain. You aren't just changing syntax; you are tracing import statements, maintaining database schemas, and praying you don't break downstream services.

Two clear frontrunners dominate this space: Anthropic's Claude 3.5 Sonnet and Google's Gemini 1.5 Pro. On paper, both look like beasts. Claude has earned a reputation for writing some of the cleanest, most idiomatic code on the market, while Gemini boasts a mind-boggling 2-million-token context window that can swallow entire git repositories for breakfast.

But when the rubber meets the road, which of these models actually understands how your codebase ticks? Let’s put the marketing fluff aside and analyse how they handle multi-file dependency graphs in the real world.

Which AI should I use for this?

Tickd is independent and not affiliated with any AI company.

The Contenders and the Test Suite

To see how they stack up, we threw a moderately complex, legacy Node.js monolithic application at both models. The codebase consisted of roughly 45,000 tokens of code spread across 18 files, featuring: * Tightly coupled database operations mixed with business logic. * A web of circular dependencies in the service layer. * Outdated Express middleware and manual error-handling blocks.

Our goal was to refactor this monolith into a clean, modular architecture using TypeScript, separating concerns into controllers, services, and repository layers, while resolving all circular dependencies.

If you run into issues setting up your own testing environment for these models, head over to our AI troubleshooting guide to get things running smoothly.

Context Ingestion: Reading the Map

Before a model can refactor code, it has to read it. This is where Google’s /platforms/gemini should theoretically wipe the floor with the competition. Feeding 18 files into Gemini's massive context window is child's play. We uploaded the entire codebase in one go, including package files and configuration scripts.

Gemini swallowed it instantly. It didn't flinch. When asked to map out the dependency graph, it produced a remarkably accurate textual representation of how the files interacted. It understood that changing UserService.js would require updates to AuthMiddleware.js and PaymentRouter.js.

Anthropic's /platforms/claude, with its smaller 200,000-token context window, still easily fit our 45,000-token test case. However, we had to be more intentional about how we structured our prompt to avoid hitting system rate limits. Claude also mapped the dependencies correctly, though its initial summary was slightly less granular than Gemini’s.

Winner on ingestion: Gemini 1.5 Pro. The sheer peace of mind of not worrying about context limits makes ingestion effortless.

Tracing Dependencies: Who Actually Gets the Logic?

This is where things get interesting. Mapping a dependency graph is one thing; actually refactoring code while respecting that graph is another.

We asked both models to pull the raw SQL queries out of our service files and abstract them into clean TypeScript repositories, updating all import paths across the entire project.

Gemini's Approach Gemini 1.5 Pro started strong but grew lazy. While it successfully identified which files needed updating, the actual code output was plagued by placeholders. It wrote the first two repository files beautifully, but by the third, it started emitting comments like `// ... rest of the repository code remains the same`.

When we pushed it to write the full implementation, it began to hallucinate import paths, occasionally referencing files that didn't exist in our original structure or changing function signatures without updating the caller files. It could see the big picture, but it struggled to maintain precision across multiple files simultaneously.

Claude's Approach Claude 3.5 Sonnet, on the other hand, was surgical. It refactored the codebase file by file with obsessive attention to detail. It didn't just suggest changes; it explained *why* it was breaking certain circular imports and how it was handling the dependency injection to prevent them from returning.

Claude rarely used lazy placeholders. It wrote complete, synthesised TypeScript modules, correctly typing complex database payloads and ensuring that every single import statement across the 18 files resolved cleanly. It felt like pairing with a senior engineer who actually cared about the build passing.

Winner on dependency tracing: Claude 3.5 Sonnet. It actually does the work instead of hand-waving with placeholders.

Output Completeness and Code Quality

When refactoring, code quality isn't just a preference—it’s a safety requirement. Hallucinated APIs or missing error handling can take hours to debug.

| Refactoring Metric | Claude 3.5 Sonnet | Gemini 1.5 Pro | | :--- | :--- | :--- | | Syntactic Accuracy | Near-perfect TypeScript; zero type errors. | Mostly correct; occasional missing imports. | | Placeholder Avoidance | High. Insists on writing full, runnable code blocks. | Low. Prone to using comments to skip repetitive code. | | Handling Circular Imports | Excellent. Suggested elegant dependency injection. | Moderate. Tried to fix them but missed downstream callers. | | Error Handling | Robust. Wrapped database calls in clean try/catch blocks. | Basic. Often kept the old, clunky Express error blocks. |

If you find yourself hitting roadblock errors when deploying Claude-generated scripts, check out our dedicated Claude troubleshooting resources for quick fixes.

The Verdict: Which Should You Use?

If you have a massive legacy project with hundreds of files and you need to perform high-level analysis, search for patterns, or generate a system-wide migration plan, Gemini 1.5 Pro is your tool. Its context window is a genuine superpower for codebase research.

However, if you actually need to execute the refactor—if you need clean, working, type-safe code that compiles without throwing a fit—Claude 3.5 Sonnet remains the undisputed king. It behaves less like an information retrieval engine and more like a meticulous software craftsman.

For best results, use a hybrid workflow: use Gemini to analyse the architecture and plan the dependency changes, then feed those modular instructions to Claude to write the actual code.

codingcomparisonsclaudegeminirefactoring

Keep going

Build something with the prompt generator, decode the jargon in the glossary, or compare the tools on our platform deep-dives.