
How do I use Cascade in Windsurf to do a multi-file refactor and review/apply the diffs safely?
Multi-file refactors are where Cascade really shines. You describe the intent once, Cascade plans and edits across your repo, and you stay in full control of every diff before anything lands in main. Think of it as a collaborative agent that can see your whole codebase and terminal history, but still waits for you to review and approve each change.
In this guide, I’ll walk through how to use Cascade in Windsurf for safe, repeatable multi-file refactors—from the first prompt to reviewing diffs, running tests, and landing a clean PR.
The Quick Overview
- What It Is: Cascade in Windsurf is a “flow-aware” coding collaborator that can plan and execute multi-file refactors, generate code, and run commands while tracking your edits, terminal usage, and context.
- Who It Is For: Individual devs and teams who want AI help with sweeping changes—API renames, module splits, dependency migrations—without losing control of the diff.
- Core Problem Solved: Manual multi-file refactors are slow and error-prone, especially across large repos. Cascade coordinates the change, keeps it lint-clean, and surfaces all diffs for review so you don’t ship surprises.
How It Works
Cascade is built into the Windsurf Editor as an always-in-flow collaborator. It watches your “action timeline” (files edited, commands run, clipboard, and conversation history) and uses that to understand what you’re trying to do.
For multi-file refactors, the high-level workflow is:
-
Scope the change with a precise prompt
You tell Cascade what needs to change—e.g., “rename this method and update all callers” or “split this monolithic service into two modules.” Cascade inspects the codebase, proposes a plan, and starts generating edits. -
Let Cascade apply and iterate on edits
Cascade modifies multiple files in your workspace, leveraging its deep context of your repo. It automatically tries to keep the code lint-clean and offers suggested actions when it sees obvious next steps (like running tests or imports). -
Review diffs, run commands, and commit safely
You review every file change directly in Windsurf, run tests/linters with Cmd+I in the terminal, and only then commit. Cascade can auto-run “safe” commands, but you stay in the loop for anything risky.
Let’s zoom into the concrete steps.
Phase 1: Scoping a Safe Multi-File Refactor
1. Start Cascade from where the refactor begins
You’ll get the best results if you anchor Cascade in the file or workspace that defines the change.
- Open the primary file for the refactor:
For example, the core API you’re renaming, the class you’re splitting, or the config you’re deprecating. - Launch Cascade:
- Using the Cascade panel in Windsurf, or
- With the keyboard shortcut you’ve set (e.g., from the command palette or sidebar).
Then give Cascade a task-level prompt, not a single-line fix:
“We’re migrating away from
LegacyPaymentService. IntroducePaymentGatewayas a replacement, update all call sites to use the new interface, and remove dead code that becomes unused. Keep all changes lint-clean and include a plan before making edits.”
Good prompts for multi-file refactors:
- Describe the goal, not just one file:
- “Rename
UserRole.ADMINtoUserRole.SuperAdmineverywhere and update UI labels accordingly.”
- “Rename
- Mention any constraints:
- “Don’t modify database migrations.”
- “Keep the public REST API backward compatible.”
- Reference tests or commands you expect:
- “After edits, run
pnpm lintandpnpm test user-management.”
- “After edits, run
Cascade’s flow awareness will also use:
- Recent files you edited
- Terminal commands you ran (e.g., last test suite)
- Clipboard snippets you’ve copied
All of that helps it infer the actual refactor scope.
2. Ask for a plan first
Before Cascade starts editing, explicitly ask for a plan:
“First, show me a step-by-step plan for this refactor. Don’t edit files yet.”
Look for:
- A list of target modules/files
- A strategy for sequencing changes (e.g., introduce new API → update call sites → remove old API)
- Which tests/commands Cascade intends to run when it’s done
If the plan is too broad or touches risky areas (like migrations or infra), tighten it:
“Exclude any migrations and Terraform files. Limit this pass to
apps/apiandapps/webonly.”
Once the plan matches your intent, tell Cascade:
“Looks good. Go ahead and apply the plan. Pause after code changes so I can review diffs before you run commands.”
Phase 2: Let Cascade Execute Multi-File Edits
3. Cascade edits across multiple files
With the plan approved, Cascade will start applying changes across your workspace:
- It opens and edits multiple files in the editor.
- It keeps track of cross-file relationships—call sites, imports, shared types.
- It aims to produce lint-clean code and will often fix obvious lint errors it introduces.
You’ll see:
- Files marked as edited in the sidebar
- Inline changes in the editor (additions, deletions, renames)
- Suggested actions, such as:
- “Add required imports for
PaymentGateway” - “Run
pnpm lint user-managementto validate changes”
- “Add required imports for
Because Windsurf is built to keep you in flow, you don’t need to re-explain the context if you pause and come back; Cascade remembers the ongoing refactor.
4. Use suggested actions and Tab-powered imports
As Cascade and you co-edit, look for:
- Suggested Actions in the UI, where Cascade surfaces “next best steps” based on your flow—e.g., “Refactor other implementations in this folder?” or “Update tests in
__tests__.” - Tab to Import when new symbols appear:
- You’ll get an inline suggestion to import the right dependency.
- Hit Tab to accept it, just like autocomplete.
This keeps the refactor moving without manual import hunting.
Phase 3: Reviewing, Testing, and Applying Diffs Safely
This is the part that matters most for safety. The goal: everything is visible, lint-clean, and tested before you merge.
5. Inspect every changed file
Use Windsurf’s diff surfaces to sanity-check the refactor:
-
File-by-file review:
Click through each modified file in the explorer. Confirm:- No unrelated “drive-by” changes
- Naming is consistent (e.g.,
PaymentGatewayis spelled the same everywhere) - Comments and docs match the new behavior
-
Ask Cascade to walk you through the diffs:
In the Cascade panel, prompt:“Summarize all changes you made for this refactor. Group by module and call out any potentially risky changes (behavior changes, not just renames).”
Then drill into specifics:
“Show me all files where
LegacyPaymentServiceis still referenced.”
“List any public API endpoints that changed request/response shape.”
This lets you catch partial or incomplete refactors early.
6. Use Git and worktrees to isolate refactors
For larger changes, isolate the work:
- Create a dedicated branch for the refactor.
- If you need multiple variants, use Git worktrees, which Windsurf supports:
- They let you check out different branches into separate directories while sharing the same history.
- You can spin up multiple Cascade sessions safely in each worktree, avoiding state conflicts.
Recommended pattern:
- Create a branch:
refactor/payment-gateway. - Optionally create a worktree for that branch.
- Open that worktree in Windsurf and run Cascade there.
- Use another worktree/branch for exploratory alternatives if needed.
This keeps your main development line clean while you let Cascade do heavy lifting.
7. Run tests and linters with Cascade in the loop
Once the diffs look sane, validate them:
-
Open the terminal inside Windsurf.
-
Ask Cascade for the right commands:
“What tests and linters should I run to validate this refactor?”
-
Run the suggested command(s) yourself, or allow Cascade to auto-run safe commands:
- Cascade can automatically detect and run certain terminal commands it deems safe (e.g., lint/test), especially if you enable Turbo-like behaviors.
- For anything that could have side effects (migrations, deploys), keep it human-in-the-loop: you approve the command before it executes.
-
If tests fail, ask Cascade:
“Analyze the failing tests and adjust the refactor to fix them. Keep changes minimal and explain each fix.”
Cascade will correlate test output with its earlier edits and propose targeted fixes, again generating diffs you can review.
8. Clean up lint issues automatically
Cascade is designed to not leave lint mess behind:
-
After seeing lint errors, you can say:
“Fix all linter errors introduced by this refactor, but don’t change unrelated code.”
-
Cascade will:
- Parse the lint output
- Apply targeted fixes in the affected files
- Avoid unrelated style churn where possible
Repeat the lint/test cycle until you get a clean run.
Phase 4: Commit, PR, and Post-Refactor Safety
9. Prepare a clean commit and PR
When you’re satisfied:
-
Inspect the final diff one more time.
-
Ask Cascade to help you draft commit and PR metadata:
“Write a concise commit message summarizing this refactor.”
“Draft a PR description with an overview, risks, and how to roll back.” -
Commit the changes on your branch.
If your team uses Windsurf Reviews (GitHub app):
- It can automatically review your refactor PR.
- It will comment on structure, naming, and potential issues.
- It can even adjust PR titles and descriptions to match your conventions.
This adds a second set of AI eyes on top of your own review.
10. Keep Cascade in the loop after merge
Multi-file refactors often reveal follow-up work:
- Deprecated paths still being used in edge cases
- Tests that are too brittle and need refactoring
- Config flags you used during rollout
You can:
“Scan the repo for any lingering references to
LegacyPaymentServicethat we might have missed. Propose a follow-up cleanup plan, but don’t make changes yet.”
Then, just like before, review the plan, let Cascade execute a scoped cleanup, and repeat the safe-diff workflow.
Features & Benefits Breakdown
| Core Feature | What It Does | Primary Benefit |
|---|---|---|
| Cascade Flow Awareness | Tracks edits, commands, clipboard, and history to infer your refactor intent | Less re-explaining; Cascade stays in sync with your ongoing work |
| Multi-File Edit Engine | Applies coordinated changes across many files and modules | Complex refactors done in minutes, not days |
| Terminal + Auto Commands | Suggests and (optionally) auto-runs safe commands like tests and linters | Faster feedback loop with you still approving risky operations |
| Tab to Import | Suggests and inserts missing imports via Tab | Keeps refactors lint-clean without manual import hunting |
| Git Worktree Support | Lets you use multiple branches/worktrees with separate Cascade sessions | Safely explore large changes isolated from main development |
| Suggested Actions | Surfaces context-aware next steps in the IDE | Guides you through the refactor without breaking your flow |
Ideal Use Cases
-
Best for API renames and interface migrations:
Because Cascade can track and update all call sites across the repo, keep imports in sync, and run tests to ensure behavior stays intact. -
Best for module splits and codebase reorganizations:
Because you can have Cascade introduce new modules, move logic, update imports, and then validate everything with a single, orchestrated flow—while reviewing every diff.
Limitations & Considerations
-
Not a fully autonomous refactor bot:
Cascade is intentionally collaborative. It’s powerful, but you should still:- Review the plan before edits
- Inspect diffs
- Approve or run tests/commands yourself for anything with side effects
-
Context and scope matter:
If your prompt is vague (“clean this up”), Cascade may touch more surface area than you’d like. Keep prompts scoped to the domain and directories you care about, and use worktrees/branches to isolate risky changes.
Pricing & Plans (Context for Multi-File Refactors)
Cascade’s multi-file refactor capabilities are available across Windsurf plans, but teams doing heavy refactor work often benefit from team/enterprise controls:
-
Individual / Pro-style plans:
Best for solo devs or small teams needing powerful in-editor refactors, Tab-powered imports, and day-to-day workflow acceleration. -
Teams / Enterprise plans:
Best for organizations needing:- Centralized billing, SSO, and RBAC
- Automated zero data retention (ZDR) defaults
- Hybrid or Self-hosted deployment options for strict compliance
- Org-wide visibility into how refactors and AI-assisted changes are being used
For large-scale refactors across critical systems, Enterprise controls plus Windsurf Reviews can reassure security and platform teams that AI changes are observed, auditable, and governed.
Frequently Asked Questions
How do I stop Cascade from making changes before I’m ready?
Short Answer: Ask for a plan first and explicitly tell Cascade not to edit files until you’ve approved it.
Details:
When you kick off a refactor, start with:
“Only propose a plan. Don’t edit any files yet.”
Review the proposed steps and file list. If something looks off, iterate on the plan:
“Remove any changes to migrations and infra. Limit to
apps/apiandapps/web.”
Once you’re comfortable, say:
“Plan approved. Apply these changes and then pause for my review before running any commands.”
Cascade will respect that boundary and wait for further instructions before touching the terminal or broader workspace.
What if Cascade’s multi-file refactor breaks tests or creates lint errors?
Short Answer: Use Cascade’s test/lint loop—run commands in the terminal, feed failures back to Cascade, and let it fix its own mistakes.
Details:
After the refactor:
-
Run your test and lint commands from the Windsurf terminal (or let Cascade auto-run safe ones).
-
If failures appear, copy or point Cascade to the output:
“Here’s the failing test output from
pnpm test user-management. Fix the refactor so all tests pass.” -
Cascade will:
- Analyze the failures in context of its edits
- Propose targeted code fixes
- Re-run or suggest re-running the tests
For lint errors, you can say:
“Fix all lint errors introduced by this refactor and keep style consistent with the rest of the file.”
Repeat until all checks pass, then do a final diff review before committing.
Summary
Using Cascade in Windsurf for multi-file refactors is about pairing “rocket booster” automation with real-world safety rails. You:
- Scope the change with a clear, plan-first prompt.
- Let Cascade coordinate edits across the repo, using flow awareness and Tab to keep everything in sync.
- Review every diff, run tests/linters, and keep risky commands human-approved.
- Land a clean, well-documented PR—with optional help from Windsurf Reviews.
You get the speed of an agent that understands your whole codebase and terminal history, without giving up the control your team’s standards, audits, and compliance require.