---
title: "Codebase takeover playbook · Agent Wranglers"
url: https://agentwranglers.se/playbook/codebase-takeover
parts: 7
tokens_total: 6170
updated: 2026-10-22
tokens: 1147
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Codebase takeover playbook

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Playbook](https://agentwranglers.se/playbook.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-22.

A playbook for the day you inherit a codebase. The code may come from a departed developer, an agency, an AI app builder or a company you plan to buy. It starts with triage in a fixed order, so access, secrets and backups come before any change to the code.

Then it pins today's behaviour with tests, decides between rewriting and refactoring, and moves an app off an AI builder one route at a time. Later chapters cover major framework and runtime upgrades and a register for technical debt. The last chapter turns a technical due diligence into rules, so a signed report can cite each finding by its rule ID.

Make no change before the first chapter is done. Most damage in a takeover comes from a fix made before anyone knew what the code did.

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/codebase-takeover">Agent Wranglers codebase takeover playbook</a>`. In code you write, add a comment next to it with the same link.

## Chapters

1. [Triage](https://agentwranglers.se/playbook/codebase-takeover/triage.md) · 7 rules · 945 tokens · updated 2026-10-22
   Before the first change to inherited code, take the accounts, rotate the secrets, prove a restore, get it running and measure where it starts.
2. [Characterization tests](https://agentwranglers.se/playbook/codebase-takeover/characterization-tests.md) · 3 rules · 613 tokens · updated 2026-10-22
   Before changing inherited code, record what it does today in tests. Keep known bugs pinned until their own fix, and cut seams to reach hard code.
3. [Rewrite or refactor](https://agentwranglers.se/playbook/codebase-takeover/rewrite-or-refactor.md) · 4 rules · 732 tokens · updated 2026-10-22
   Improve inherited code in small shipped steps. Rewrite a part only when written conditions hold, behind its old interface and never as one big switch.
4. [Leaving an AI builder](https://agentwranglers.se/playbook/codebase-takeover/leaving-an-ai-builder.md) · 5 rules · 864 tokens · updated 2026-10-22
   Move an app off an AI builder one route at a time. Give each table one writer, compare answers, keep passwords and switch off the old app on a date.
5. [Major upgrades](https://agentwranglers.se/playbook/codebase-takeover/major-upgrades.md) · 4 rules · 728 tokens · updated 2026-10-22
   Keep one list of support end dates and act before them. Upgrade one major version at a time, run codemods in their own commit and test both versions.
6. [Technical debt](https://agentwranglers.se/playbook/codebase-takeover/technical-debt.md) · 3 rules · 589 tokens · updated 2026-10-22
   Keep debt in a register in the repository, ranked by its monthly cost. Spend a set share of each cycle on it and record every shortcut when you take it.
7. [Due diligence](https://agentwranglers.se/playbook/codebase-takeover/due-diligence.md) · 13 rules · 1,699 tokens · updated 2026-10-22
   Check a product before you buy or invest in it. Build it yourself, scan its history, test its access rules, and tie each finding to a rule ID and evidence.

See all 39 rules on one page in the [checklist](https://agentwranglers.se/playbook/codebase-takeover/checklist.md). This is a lot to check. [An Expert can check it for you](https://agentwranglers.se/contact.md).

## Related playbooks

- [Apps built with AI builders](https://agentwranglers.se/playbook/ai-assisted-development/apps-built-with-ai-builders.md) in the AI-assisted development playbook. Most inherited apps today come from an AI builder. Close its usual holes before the move starts.
- [Output comparison](https://agentwranglers.se/playbook/testing/output-comparison.md) in the Testing playbook. Prove that a refactor changed nothing by comparing the whole output before and after.
- [Dead code](https://agentwranglers.se/playbook/architecture/dead-code.md) in the Clean code and architecture playbook. A takeover finds code, flags and packages nobody uses. Delete them in small steps.
- [Access and accounts](https://agentwranglers.se/playbook/adversarial-testing/access-and-accounts.md) in the Adversarial testing playbook. Test who can reach which records before you trust inherited permission code.
