Refactor with AI
Use Plan and Code modes to rename a pattern and review each proposed change.
This tutorial shows a safe AI-assisted refactor: extract a repeated utility, update call sites, and review every diff before accepting.
Prepare
- Open a project folder in Shape.
- Sign in to your Shape account for AI access.
- Open AI Chat from the titlebar.
Pick a small, well-scoped task, such as "Move duplicated date formatting into lib/format-date.ts and update imports."
Optional: Plan first
For larger refactors, start in Plan mode:
- Select Plan from the mode dropdown.
- Describe the refactor and which files you think are involved.
- Send the message.
The assistant researches the codebase and saves a plan to .shape/plans/. Open that file in the editor, edit if needed, then continue in Code mode.
Run in Code mode
- Switch the dropdown to Code.
- Send a clear instruction, for example:
Create
lib/format-date.tswith aformatDatefunction. Replace inlinetoLocaleDateStringcalls incomponents/with imports from the new module. Do not change unrelated files.
- Wait for the assistant to propose edits.
Review each edit
Each changed file appears in the pending strip above the chat input.
- Click the file to open a diff tab.
- Read added and removed lines.
- Click Keep only when the change looks correct.
- Click Undo on anything that touches files outside scope.
Do not enable auto-apply until you are comfortable with the workflow. See Reviewing Edits.
Verify
After accepting edits:
- Save all files (Ctrl+K S).
- Open Problems (Ctrl+Shift+M) and fix new type errors.
- Run tests or the dev server from the terminal:
npm testIf the assistant proposed a terminal command, approve Run on the card and check output in the panel.
Iterate
If something failed, send a follow-up in the same thread:
The test in
format-date.test.tsfails because of timezone. Fix the test to use UTC.
Review and accept the follow-up edits the same way.
What you learned
- Use Plan for design and Code for implementation
- Preview and Keep or Undo edits one file at a time
- Verify with Problems and terminal commands