Canonical: https://botbento.com/usecases/legacy-code-rewrite-support-with-behavior-mapping/
Format: Markdown representation of the public HTML page.

# Legacy code rewrite support with behavior mapping

[Coding](https://botbento.com/usecases/coding/) · Advanced

Map old behavior first, then draft refactors for engineers to review

A bot helps a modernization effort on an aging codebase by reading legacy modules and writing down what each one actually does. It turns that into characterization tests and notes before any rewrite starts. It drafts refactor patches on a separate branch, flags places where the original intent is unclear, and collects open questions so engineers can confirm behavior instead of guessing. Nothing merges on its own.

## Quick answers

**What does it do?** Map old behavior first, then draft refactors for engineers to review. Result: Characterization tests and refactor.

**What does it need?** Tools: GitHub, Terminal, Docs, Notes. Advanced: more tools and setup. The prompt includes an approval step.

**How do I run it?** When something happens: New legacy module assigned. Copy the prompt below into a bot in BotBento.

## How it works

1. When something happens: New legacy module assigned
2. Then: Read module and record observed behavior
3. Result: Characterization tests and refactor

## Prompt to start with

```text
You support a legacy code modernization effort. When a module is assigned, read it and any nearby tests, then write a plain-language note describing its inputs, outputs, side effects and error paths. Draft characterization tests that capture current behavior, including quirks, before proposing changes. Produce refactor patches on a separate branch and keep each patch small and explained. List every assumption you had to make and every behavior you could not verify, and ask the engineer to confirm it. Never merge, push to a main branch, delete files, open external tickets or message anyone without the user's explicit approval; queue those actions for review.
```

## Tools it uses

GitHub, Terminal, Docs, Notes

## Works with

BotBento

## Tags

legacy-code, refactoring, testing, code-review, documentation

## Source

[Cisco gives engineer unlimited AI tokens to rewrite legacy code](https://news.ycombinator.com/item?id=50304122) — Hacker News · checked 2026-11-13

Summarized in our own words. Any results described there are the authors’ own, not measured by BotBento.

By BotBento Editorial · Added 2026-11-13 · Updated 2026-11-13 · [Suggest a correction](https://botbento.com/contact/)

## Related use cases

- [Modernize a legacy PHP file with an iterative coding bot](https://botbento.com/usecases/modernize-a-legacy-php-file-with-an/) — Reads one legacy file, proposes a modernized version, runs the tests, and opens a draft patch for review
- [Minimalist code implementation and pull request review](https://botbento.com/usecases/minimalist-code-implementation-and-pull-request-review/) — Write less code by reusing existing repo components and catching breaking changes early
- [Review large AI-generated code diffs before merge](https://botbento.com/usecases/review-large-ai-generated-code-diffs-before/) — Refactor and walk through big diffs, then draft a clean commit
