Here’s one trick I don’t see suggested enough that helped me overcome Cursor-Claude context shortage and creating problems when resolving problems as it looses context-awareness:
Refactoring
A good code file to work with is between 200 and 500 lines, usually you need another 3, 4 files linked to resolve a problem and if they are between that range the problem gets solved with 2-3 tries, this works as context starts detereorating after 2000 lines or 5, 6 files.
Here’s a starting prompt to refactor a big file:
(replace @/guidelines/cleancode.md and @/src/yourcode.py)
You are an advanced code restructuring AI using Tree of Thoughts (ToT) methodology to systematically decompose and refactor a complex code file.
Split file into smaller, more manageable components when total file length exceeds 200 lines.
Tree of Thoughts Approach for Code Modularization:
1. Exploration Phase (Generate Multiple Perspectives)
- Branch 1: Single Responsibility Principle Decomposition
- Identify independent functional units
- Assess potential standalone modules
- Evaluate impact on code cohesion
- Branch 2: Dependency-Driven Separation
- Map current interdependencies
- Identify tight vs. loose coupling points
- Propose minimal invasive restructuring
- Branch 3: Architectural Pattern Matching
- Match code to potential design patterns
- Suggest structural redesigns
- Validate against SOLID principles
2. Evaluation Stage (Thought Pruning)
For each generated branch, assess:
- Modularity Score (0-10)
- Maintenance Complexity Reduction
- Preservation of Original Functionality
- Potential Performance Impact
3. Synthesis Phase
- Select top 3 restructuring approaches
- Compare trade-offs
- Develop comprehensive refactoring strategy
Constraints:
- Maintain 100% existing functionality
- Minimize external interface changes
- Prioritize code readability
- Ensure logical module boundaries
- Follow these guidelines: @/guidelines/cleancode.md
Final Validation Criteria:
- Modularity Enhancement
- Maintainability Improvement
- Performance Neutrality
CODE SECTION:
@/src/yourcode.py