What are the specific Claude Code workflows that actually speed up backend refactoring without breaking the whole build? Im currently trying to clean up a legacy Node.js/TypeScript monolith for a client here in Chicago and the technical debt is honestly just massive, like, spaghetti code everywhere.
I have read a few blog posts about using Claude Code for unit test generation, but people keep arguing about whether you should let it handle the actual dependency injection cleanup or if that just creates more bugs. Im a bit skeptical because I tried it once and it hallucinated a module import that doesnt even exist. I need to get this project stabilized by next month and my budget for external tools is pretty much zero so I really need to master the free/cli stuff.
Are there specific prompting patterns or CLI commands you guys use to keep it from rewriting the entire file when I only want to change one small function signature? Im really struggling with getting it to understand the wider context of our folder structure without it losing the plot. Like, do I just keep feeding it the whole codebase or is there a better way to structure the instructions so it doesnt get confused by the legacy mess...
Man, dealing with legacy Node monoliths in Chicago winters sounds like a special kind of hell. Honestly, the biggest mistake people make with Claude Code is dumping the whole repo into the context window. It gets overwhelmed and starts hallucinating imports, like you saw. Instead of doing that, try using the CLI tool to perform surgical strikes on one module at a time. I usually keep my context tight by manually adding only the relevant interface definitions or shared types to the chat before asking for refactors. For the dependency injection stuff, definitely dont let it take the wheel on the whole architecture. I use it to generate the boilerplate for the new DI pattern and then I manually wire up the services. It saves me hours of typing but keeps the logic where I can see it. If you have an old laptop that is choking on these tasks, check if you can upgrade your RAM to at least 32GB using something like Corsair Vengeance 32GB DDR4 3200MHz to keep your dev environment snappy while running these agents locally. Another tip: be super specific with your prompts. Dont just say refactor this. Use commands that tell it to preserve existing public signatures and only modify internal logic. It stops the tool from gutting your file structure. It is not perfect, but it sure beats doing it all by hand for free.
> do I just keep feeding it the whole codebase Dont do that. Use scoped file inclusions, man. It works well if you point it at specific interfaces and Samsung 990 Pro 2TB NVMe SSD logs.
^ This. Also, totally agree on the scoped file inclusions, that is the only way to keep the context window sane. When I am refactoring, I basically treat it like a surgical tool instead of a hammer. If you feed it too much, it just gets lazy and tries to rewrite everything to be clever. Here is how I keep it from breaking stuff: