What are the best Claude Code skills or specific commands I should be using for refactoring a massive pile of legacy Python because I am seriously losing my mind here. I am stuck in this tiny office in Chicago trying to fix a logistics tracking system that was written back when people still thought global variables were a good idea and I have exactly three weeks before our legacy server gets turned off for good and everything goes dark. It is a complete mess of Python 2.7 logic barely holding on with duct tape and some 3.x patches that dont even make sense.
Ive been playing around with the new Claude Code CLI tool and honestly its making me more frustrated than anything right now. I read online that I should just use the /refactor command or maybe set up a custom MCP server to help it see the file structure better but the advice is so conflicting. Some people on Reddit say you should just let it read everything at once while others say thats how you get massive hallucinations where it starts making up library functions that dont exist. When I tried the basic refactor it kept trying to use modern Pydantic models on stuff thats basically just dictionaries and it broke the whole data pipeline.
My main issues right now:
I dont have a massive budget for this, just my standard subscription and maybe fifty bucks in extra credits if I can justify it to my boss who barely knows what an API is. Is there a specific workflow or a set of tool-use patterns that actually works for this kind of archaeology coding? Every time I think I have a prompt that works it fails to see a file three folders up and the whole thing crashes. How do I get it to actually understand the context of 15-year-old spaghetti code without it just guessing...
Regarding what #2 said about "Honestly, I've tried many ways to fix legacy...", i totally agree. I saved a fortune on credits by using Pylint Static Analysis Tool to find circular imports myself before even opening the CLI. It's so much more reliable.
In my experience, feeding Anthropic Claude 3.5 Sonnet API tiny chunks works best. Run the /compact command often so it doesn't get confused by those old circular imports and waste your budget.
Honestly, I've tried many ways to fix legacy garbage and the /refactor command is usually a trap. It over-promises and makes a mess of old SQLAlchemy sessions. In my experience, you gotta treat it like a junior dev who hasn't seen old code before.