Refactor across files: how to do it with AI
Last checked 2026-10-15
AdvancedBot with human review 💻 Coding
Rename or restructure code across a repository with review.
1. Bot automation level
Bot with human review Agents act on real systems; review plans, approvals and results before trusting them.
2. Before you hand it to the bot
- Gather inputs: files, data samples, links and any templates.
- Set up access: connect only the apps/repos the agent needs, with least-privilege accounts.
- Context: tell the bot audience, purpose, constraints and examples of good output.
- Privacy check: remove personal, confidential or regulated data unless your plan/workspace is approved for it.
- Success criteria: write down what 'done' looks like (length, format, tests passing, fields filled).
3. Copy-paste prompts
Main prompt
Refactor the auth module into a service class; update all callers.
Beginner-friendly
Refactor the auth module into a service class; update all callers. I'm new to this: explain each step in plain words and ask me for anything you need before starting.
Check-your-work
Refactor the auth module into a service class; update all callers. When you finish, list any assumptions you made, anything you're unsure about, and what I should double-check before using the result.
Free tiers that can handle this (verified): GitHub Copilot, ChatGPT (incl. Work & Codex). Others: check plan.
4. Step-by-step
- Write the target design in 3–5 sentences and list files/modules in scope.
- Ask the agent for a step-by-step plan and the list of call sites before any edits.
- Run it on a branch; ask for small commits per step.
- Run the full test suite and type checker after each step.
- Review the final diff for behaviour changes, not just renames.
5. Which bots and plans can do it
| Tool | What's different here | Plan limits | Source |
|---|---|---|---|
| Cursor | Agent edits across files; Cloud Agents can work on larger tasks remotely. | Pricing page unverified; cloud agents require a connected source-control repo. | cursor.com/docs/agent/overview |
| GitHub Copilot | Cloud agent opens the change as a PR for review. | Free: 2,000 completions + 50 chats; cloud agent listed on paid plans. | docs.github.com/en/copilot/concepts/agents/cloud-agent/about-cloud-agent |
| Claude (incl. Claude Code) | Claude Code Desktop supports parallel sessions with Git isolation and diff review. | Claude Code and Research need Pro or higher; computer use is Pro/Max only (research preview). | code.claude.com/docs/en/desktop |
| ChatGPT (incl. Work & Codex) | Codex shows diffs and supports multi-repository work in the desktop app. | Free tier has limited deep research, Codex and Work; scheduled tasks need Go or higher (per chatgpt.com/pricing). | help.openai.com/en/articles/20001275-chatgpt-work-and-codex |
Free or paid?
- Cursor: Free: not verified, so check the official site. Paid: price not verified, so check the official site. For this task, check the plan.
- GitHub Copilot: Free plan: yes. 2,000 completions and 50 chat requests a month; agent mode and CLI. Paid: the lowest price we could verify on the official pricing page is $10/month (other plans may exist). Its free tier can handle this task.
- Claude (incl. Claude Code): Free plan: yes. chat, web search, files & code execution, Artifacts, connectors. Claude Code and Research need Pro. Paid: the lowest price we could verify on the official pricing page is $20/month (other plans may exist). For this task, check the plan.
- ChatGPT (incl. Work & Codex): Free plan: yes. unlimited text chats; limited uploads, images, voice, deep research and Codex. Paid: price not verified, so check the official site. Its free tier can handle this task.
6. Risks and what to double-check
- Large refactors can silently change behaviour; rely on tests, not the agent's summary.
- Keep the scope tight — agents may 'improve' unrelated code.
- Run tests and review diffs; never merge unreviewed agent code.
- AI can hallucinate facts — verify anything that matters.
- Watch for prompt injection from web pages, emails or files the agent reads.