{"playbook":"Codebase takeover","url":"https://agentwranglers.se/playbook/codebase-takeover","updated":"2026-10-22","license":"https://creativecommons.org/licenses/by/4.0/","credit":"Required by the licence: credit Agent Wranglers with a link to the rule or playbook you used.","ids":"Each rule has an id, such as PAY-14, that never changes. Open a rule by its id at /r/PAY-14. Its revision changes whenever its content changes.","how":"Each rule's How and Measured text is on its own page: add .md to its url.","rules":[{"id":"TKO-1","revision":"4abea5219469","updated":"2026-10-22","name":"Take control of every account before touching the code","level":"Required","risk":"takeover","stack":["lovable","bolt","replit","v0"],"rule":"Before the first change, list every account the product depends on. Give the company at least two admins on each, and remove every person who has left.","check":"The access list names every account in the list above that the product uses. Each has at least two current company admins who can sign in, and no member who is not on the current staff or contractor list.","check_type":"manual","url":"https://agentwranglers.se/playbook/codebase-takeover/triage/take-control-of-accounts","related":["/playbook/infrastructure/hosting-platforms/own-domain-and-dns","/playbook/engineering/version-control-and-review/code-host-accounts","/playbook/compliance/audit-logs-and-access/offboarding-within-a-day","/playbook/codebase-takeover/triage/rotate-inherited-secrets","/playbook/codebase-takeover/triage/remove-inherited-access","/playbook/codebase-takeover/triage/fix-in-risk-order","/playbook/due-diligence/code-and-ownership/build-from-own-repository"],"sources":["https://docs.github.com/en/organizations/managing-peoples-access-to-your-organization-with-roles/maintaining-ownership-continuity-for-your-organization"]},{"id":"TKO-2","revision":"ef4d8f74e04c","updated":"2026-10-22","name":"Rotate every secret the previous team could read","level":"Required","risk":"takeover","rule":"Replace every API key, database password, signing key and token that existed before the handover. Revoke the old values, so they stop working.","check":"Every entry in the secrets store has a creation date after the handover date. A call with each old key, kept aside for the test, fails with an authentication error.","check_type":"manual","url":"https://agentwranglers.se/playbook/codebase-takeover/triage/rotate-inherited-secrets","related":["/playbook/codebase-takeover/triage/take-control-of-accounts","/playbook/due-diligence/code-and-ownership/history-secret-scan","/playbook/engineering/running-in-production/secrets-store","/playbook/codebase-takeover/triage/remove-inherited-access","/playbook/codebase-takeover/triage/fix-in-risk-order"],"sources":["https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html"]},{"id":"TKO-40","revision":"6910c82f2c7f","updated":"2026-10-22","name":"Remove the previous team's access inside the product","level":"Required","risk":"takeover","rule":"List every way into the running product that is not a vendor account, and remove each one that no current person or service owns. That covers admin users, SSH keys, deploy keys, API tokens, OAuth apps and webhooks.","check":"The access list names every admin user, SSH key, deploy key, API token, OAuth app and webhook, each with a current owner. A fresh query of admin users and a scan of every `authorized_keys` file find no entry missing from the list.","check_type":"static","url":"https://agentwranglers.se/playbook/codebase-takeover/triage/remove-inherited-access","related":["/playbook/codebase-takeover/triage/take-control-of-accounts","/playbook/codebase-takeover/triage/rotate-inherited-secrets","/playbook/codebase-takeover/triage/system-map"],"sources":["https://csrc.nist.gov/pubs/sp/800/53/r5/upd1/final"]},{"id":"TKO-3","revision":"eed90e6b41f6","updated":"2026-10-22","name":"Take a backup and restore it before the first change","level":"Required","risk":"data","rule":"Before the first change to inherited code or data, take a full backup of every data store and restore it on a separate machine.","check":"A restore of a backup taken after the handover date runs on a machine outside production. The row counts of the five largest tables match production within the hours since the backup.","check_type":"command","url":"https://agentwranglers.se/playbook/codebase-takeover/triage/restore-before-first-change","related":["/playbook/data/backups-and-recovery/restore-tests","/playbook/operations/disaster-recovery/off-site-backups","/playbook/codebase-takeover/triage/fix-in-risk-order"],"sources":["https://www.cisa.gov/stopransomware/ransomware-guide"]},{"id":"TKO-4","revision":"bdbe3018d8be","updated":"2026-10-22","name":"Run it from a clean checkout","level":"Recommended","stack":["lovable","bolt","replit","v0"],"rule":"Make the inherited code build, run and pass its own tests on a clean machine, using only the repository and the secrets store.","check":"In a fresh container, the documented command builds the app and runs its tests, without network access to the previous team's machines or accounts.","check_type":"command","url":"https://agentwranglers.se/playbook/codebase-takeover/triage/run-from-clean-checkout","related":["/playbook/ai-assisted-development/setting-up-the-project/runnable-from-clean-checkout","/playbook/documentation/readme-and-docs-as-code/readme-sections","/playbook/ai-assisted-development/apps-built-with-ai-builders/own-the-code","/playbook/due-diligence/code-and-ownership/build-from-own-repository"],"sources":["https://12factor.net/dependencies"]},{"id":"TKO-5","revision":"3db8a8a369e9","updated":"2026-10-22","name":"Map the system before changing it","level":"Recommended","rule":"Write one map of the system that lists every service, data store, scheduled job, outside service, setting and place it runs. Keep it in the repository.","check":"A script lists every environment variable the code reads and fails when one is missing from the map. Every DNS record, scheduled job, database and running service in the hosting account's resource list appears in the map, with 0 left over.","check_type":"command","url":"https://agentwranglers.se/playbook/codebase-takeover/triage/system-map","related":["/playbook/codebase-takeover/triage/remove-inherited-access","/playbook/compliance/processors-and-transfers/vendor-register","/playbook/documentation/readme-and-docs-as-code/diagrams-as-code","/playbook/codebase-takeover/triage/takeover-baseline","/playbook/codebase-takeover/triage/record-handover-sessions","/playbook/codebase-takeover/leaving-an-ai-builder/one-writer-per-table","/playbook/due-diligence/code-and-ownership/single-points-of-failure","/playbook/due-diligence/security-data-and-law/personal-data-review"],"sources":[]},{"id":"TKO-6","revision":"e75c84204f9c","updated":"2026-10-22","name":"Measure a baseline before the first fix","level":"Recommended","rule":"In the first week, record the starting numbers in a dated file. Every later report states its numbers against them.","check":"A baseline file dated within 7 days of the handover holds each of the numbers listed above, with the command or dashboard that produced it.","check_type":"command","url":"https://agentwranglers.se/playbook/codebase-takeover/triage/takeover-baseline","related":["/playbook/codebase-takeover/triage/system-map"],"sources":[]},{"id":"TKO-7","revision":"9c897c8ca377","updated":"2026-10-22","name":"Fix in risk order","level":"Recommended","rule":"Work through an inherited codebase in a fixed order. Finish each step before structural changes start.","check":"Every item on the work list carries a step number from 1 to 7. No change tagged step 6 or 7 merges while an item from steps 1 to 3 is open.","check_type":"manual","url":"https://agentwranglers.se/playbook/codebase-takeover/triage/fix-in-risk-order","related":["/playbook/architecture/technical-debt/change-hotspots","/playbook/codebase-takeover/triage/take-control-of-accounts","/playbook/codebase-takeover/triage/rotate-inherited-secrets","/playbook/codebase-takeover/triage/restore-before-first-change","/playbook/accounts/roles-and-permissions/object-access","/playbook/application-security/secrets-and-configuration/secrets-out-of-browser","/playbook/engineering/running-in-production/logs-and-alerts","/playbook/codebase-takeover/characterization-tests/pin-behaviour-first","/playbook/architecture/technical-debt/debt-register"],"sources":[]},{"id":"TKO-41","revision":"332639547557","updated":"2026-10-22","name":"Record handover sessions before the old team leaves","level":"Recommended","rule":"Before the previous team's last day, hold sessions where they walk through the system, and keep dated notes in the repository. Cover deploys, rollback, scheduled jobs, outside services, recent incidents and known bugs.","check":"The docs folder holds notes dated before the handover date that cover all six topics in the rule. Each open question in them is answered or has a ticket.","check_type":"manual","url":"https://agentwranglers.se/playbook/codebase-takeover/triage/record-handover-sessions","related":["/playbook/documentation/docs-for-coding-agents/runbooks-in-repo","/playbook/codebase-takeover/triage/system-map","/playbook/due-diligence/code-and-ownership/single-points-of-failure"],"sources":[]},{"id":"TKO-8","revision":"bece10eda1d8","updated":"2026-10-22","name":"Pin today's behaviour before changing code","level":"Recommended","rule":"Before you change a module, write tests that record what it does today for the inputs it gets in production. They must pass on the code as it is now.","check":"Run the new tests against the base commit of the change. They pass. Every pull request that changes a module with no tests adds its characterization tests in an earlier commit.","check_type":"http","url":"https://agentwranglers.se/playbook/codebase-takeover/characterization-tests/pin-behaviour-first","related":["/playbook/engineering/major-upgrades/one-major-at-a-time","/playbook/codebase-takeover/triage/fix-in-risk-order","/playbook/data/personal-data/masked-copies","/playbook/testing/output-comparison/refactor-changes-nothing","/playbook/testing/test-quality/small-snapshots","/playbook/codebase-takeover/rewrite-or-refactor/refactor-in-steps","/playbook/codebase-takeover/rewrite-or-refactor/rewrite-behind-interface"],"sources":[]},{"id":"TKO-9","revision":"bf1e9bf3a0e5","updated":"2026-10-22","name":"Keep known bugs pinned until their own fix","level":"Recommended","rule":"When a characterization test records a bug, keep the buggy output as expected and link the test to a ticket. Fix the bug in a separate change that updates that one test.","check":"No pull request both restructures code and changes a characterization test's expected output. Every characterization test whose name says bug links a ticket ID.","check_type":"http","url":"https://agentwranglers.se/playbook/codebase-takeover/characterization-tests/pin-known-bugs","related":["/playbook/testing/output-comparison/expected-differences","/playbook/codebase-takeover/leaving-an-ai-builder/shadow-compare"],"sources":[]},{"id":"TKO-10","revision":"7a806514138c","updated":"2026-10-22","name":"Cut a seam before testing hard code","level":"Recommended","rule":"When code reads the clock, the network, the database or a global directly, make the smallest change that lets a test pass that dependency in. Make no other change in the same step.","check":"The characterization tests run with the network turned off and a fixed clock, and give the same result on 10 runs in a row.","check_type":"command","url":"https://agentwranglers.se/playbook/codebase-takeover/characterization-tests/cut-a-seam","related":["/playbook/testing/unit-tests/unit-deterministic","/playbook/architecture/solid-and-dry/dependency-inversion"],"sources":[]},{"id":"TKO-11","revision":"fc84c333857b","updated":"2026-10-22","name":"Refactor in shipped steps by default","level":"Recommended","rule":"Improve inherited code in steps that each ship to production on their own. Start a rewrite only when [Rewrite a part only when written conditions hold](https://agentwranglers.se/playbook/codebase-takeover/rewrite-or-refactor/rewrite-conditions) says so.","check":"The deploy log shows each refactoring step as its own release, and the characterization tests pass on every one.","check_type":"manual","url":"https://agentwranglers.se/playbook/codebase-takeover/rewrite-or-refactor/refactor-in-steps","related":["/playbook/codebase-takeover/rewrite-or-refactor/rewrite-conditions","/playbook/engineering/version-control-and-review/small-changes","/playbook/codebase-takeover/characterization-tests/pin-behaviour-first"],"sources":[]},{"id":"TKO-12","revision":"36c41971b11d","updated":"2026-10-22","name":"Rewrite a part only when written conditions hold","level":"Recommended","rule":"Rewrite a part instead of refactoring it only when a decision record shows that at least one of three conditions holds, with evidence.","check":"Every rewrite in the work list links a decision record. The record names which of the three conditions holds, with evidence, and a switch-off date for the old part.","check_type":"manual","url":"https://agentwranglers.se/playbook/codebase-takeover/rewrite-or-refactor/rewrite-conditions","related":["/playbook/codebase-takeover/rewrite-or-refactor/refactor-in-steps","/playbook/documentation/readme-and-docs-as-code/linked-decision-records","/playbook/due-diligence/operations-and-growth/rebuild-list"],"sources":[]},{"id":"TKO-13","revision":"a824897079e3","updated":"2026-10-22","name":"Freezing the old system for a big-bang rewrite","level":"Avoid","stack":["aws"],"rule":"Never stop work on the old system to rewrite all of it and switch every user over on one day.","check":"The migration plan lists each part with its own switch date, and no single date moves every user at once. The old system has at least one shipped change in each month of the rewrite.","check_type":"manual","url":"https://agentwranglers.se/playbook/codebase-takeover/rewrite-or-refactor/big-bang-rewrite","related":["/playbook/codebase-takeover/leaving-an-ai-builder/strangler-router"],"sources":["https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/strangler-fig.html"]},{"id":"TKO-14","revision":"dc6ac74c212f","updated":"2026-10-22","name":"Rewrite behind the old interface","level":"Recommended","rule":"When you rewrite a part, put the old and the new code behind one interface and choose between them with a flag. Callers never change.","check":"The same test suite runs against both implementations and passes. Switching the flag back to the old code needs no deploy.","check_type":"command","url":"https://agentwranglers.se/playbook/codebase-takeover/rewrite-or-refactor/rewrite-behind-interface","related":["/playbook/architecture/system-architecture/fitness-functions","/playbook/codebase-takeover/characterization-tests/pin-behaviour-first","/playbook/engineering/running-in-production/deploy-is-not-release"],"sources":[]},{"id":"TKO-15","revision":"3442dc5f1d72","updated":"2026-10-22","name":"Put a router in front and move one route at a time","level":"Recommended","stack":["aws","lovable","bolt","replit","v0"],"rule":"Put a proxy in front of the builder app that sends each route to the old or the new system. Move one route at a time, and keep each move reversible by one setting.","check":"The proxy settings list every route with its target. On staging, sending a moved route back to the old system is a one-line change, and the route answers 200 from the old system afterwards.","check_type":"manual","url":"https://agentwranglers.se/playbook/codebase-takeover/leaving-an-ai-builder/strangler-router","related":["/playbook/architecture/domain-model/anti-corruption-layer","/playbook/codebase-takeover/rewrite-or-refactor/big-bang-rewrite","/playbook/ai-assisted-development/apps-built-with-ai-builders/know-when-to-move"],"sources":["https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/strangler-fig.html"]},{"id":"TKO-16","revision":"ebaeb8989853","updated":"2026-10-22","name":"Give each table one writer during the move","level":"Required","risk":"data","stack":["lovable","bolt","replit","v0"],"rule":"While two systems run side by side, let only one of them write each table. The other reads it or gets copies through events.","check":"The system map names one writer per table. An insert into each table with the other system's database credentials fails with a permission error.","check_type":"manual","url":"https://agentwranglers.se/playbook/codebase-takeover/leaving-an-ai-builder/one-writer-per-table","related":["/playbook/codebase-takeover/triage/system-map","/playbook/events/publishing-events/outbox"],"sources":["https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/strangler-fig.html"]},{"id":"TKO-17","revision":"44e7ca331c8d","updated":"2026-10-22","name":"Compare old and new answers before switching a route","level":"Recommended","stack":["lovable","bolt","replit","v0"],"rule":"Before a route switches to the new system, send copies of its read requests to both systems and compare the answers. Switch only when no difference is left unexplained.","check":"For each moved route, the comparison log covers at least 1,000 requests or 7 days of traffic before the switch. Every difference in it has a ticket or a written reason.","check_type":"manual","url":"https://agentwranglers.se/playbook/codebase-takeover/leaving-an-ai-builder/shadow-compare","related":["/playbook/testing/output-comparison/narrow-masks","/playbook/codebase-takeover/characterization-tests/pin-known-bugs","/playbook/testing/output-comparison/compare-live-before-and-after"],"sources":[]},{"id":"TKO-18","revision":"844ec2dcd92e","updated":"2026-10-22","name":"Move users without resetting their passwords","level":"Recommended","applies":["accounts"],"stack":["lovable","bolt","replit","v0"],"rule":"Export the users with their IDs and password hashes, and check each old hash at the user's next sign-in. Store a new hash then, and keep the same user ID.","check":"A test user created in the old system signs in to the new system with the same password. Afterwards their stored hash uses the new settings, and their user ID is unchanged.","check_type":"manual","url":"https://agentwranglers.se/playbook/codebase-takeover/leaving-an-ai-builder/move-users-with-hashes","related":["/playbook/application-security/authentication-and-sessions/password-storage"],"sources":["https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#upgrading-legacy-hashes","https://firebase.google.com/docs/auth/admin/import-users"]},{"id":"TKO-19","revision":"69715f1fec7c","updated":"2026-10-22","name":"Switch off the builder app on a set date","level":"Recommended","stack":["lovable","bolt","replit","v0"],"rule":"When the last route has moved, set a date to switch off the builder app. On that date revoke its keys, remove its deploys and preview addresses, and delete its routes from the proxy.","check":"After the switch-off date, the builder app's keys fail with an authentication error. Its addresses no longer serve the app, and the proxy has no route to it.","check_type":"manual","url":"https://agentwranglers.se/playbook/codebase-takeover/leaving-an-ai-builder/switch-off-builder","related":["/playbook/infrastructure/hosting-platforms/preview-isolation","/playbook/architecture/structure/delete-unused-code"],"sources":[]}]}