BrowserLeaksUSBrowserLeaksUS

AI Refactor Assistant

Clean up code without changing behavior. AI explains every change

Code

What this tool does

Refactors code for clarity, reduced duplication, and modern idioms - without changing behavior. Produces a diff of every change categorized by type (rename, extract-function, simplify-condition, remove-duplication, modern-syntax, add-type) and flags any bugs it noticed while reading.

Who it's for: Developers cleaning up legacy code, reviewing PRs, or preparing a codebase for a migration.

When to use

  • •Modernize ES5 JavaScript to ES2022 (arrow functions, optional chaining, etc.).
  • •Extract nested logic into smaller named functions.
  • •Reduce repeated code patterns before adding a new feature.
  • •Catch hidden bugs during a cleanup pass.

How it works

  1. 1Paste the code and pick the language (or auto-detect).
  2. 2AI applies refactorings and explains each change.
  3. 3Flags any bugs found - these are behavioral changes, not cosmetic.
  4. 4Review the diff and run your tests before committing.

Tips

  • •Always run tests after refactoring - behavior preservation is 'best effort'.
  • •Prefer small refactoring batches (50-100 lines) for easier review.
  • •The potential_bugs section often catches issues humans miss.

Using this output

How to read a refactor suggestion

01

Behavior should stay, shape can change

A refactor is a change that keeps the observable behavior and moves the structure. The output shows a rewritten snippet and a list of what it claims to have simplified: names, duplication, nesting, or an API that was hard to call. Diff that claim against your paste. If a branch disappeared, the suggestion is a behavior change wearing a refactor's name. Keep the branch, or call the change a fix and test it as one.

Extracted helpers are the usual gift. Check that the helper's parameters are the real inputs and not a global the helper quietly closes over. A function that is shorter because it now depends on a variable you cannot see is harder, not easier. The same goes for a new library the suggestion imports. Reject dependencies you did not ask to add.

02

Prove the move with a test

Run the existing tests before you admire the new shape. If you have none, generate a characterization test with Unit Test Gen on the original, see it pass, then apply the refactor and see it pass again. A characterization test locks today's behavior, including quirks you rely on. Read those quirks before you delete them as 'cleanup'.

Do not mix the refactor with a feature in one commit. The message from Commit Message should say refactor and name the structure, not the new capability. If you cannot describe the result without mentioning a new behavior, you did not refactor. Read the rewritten snippet beside the original and mark any return value, error, or side effect that moved. That comparison is the review.