Inherited a vibe coded codebase? A first-week playbook

A practical playbook for taking over a vibe coded codebase: a first-day security audit, characterization tests, CI gates, a safe refactor order and rules for AI agents.

AI Engineering Stop 1 of 2 By UniqBlog Desk 29 November 2026 Updated 1 December 2026 6 min read

Soft 3D illustration: a leaning stack of blocks whose top is being straightened into a neat column, lit by a violet flashlight beside an open toolbox

When you inherit a vibe coded codebase, do not start by rewriting it. On day one, find and rotate leaked secrets, check who can read whose data, and list vulnerable dependencies. On days two to five, pin the current behaviour with characterization tests and put CI gates in front of main. Only then refactor, one small, tested slice at a time. AI agents can help with every step if you treat them like a fast junior with no production access.

This is a common job now. In recent weeks, r/webdev has had a thread from a developer joining a startup whose code is almost entirely AI-generated. r/sysadmin has one about users shipping their own vibe-coded enterprise apps. The commands below were run on 2026-12-01 against osv-scanner 2.7.1, gitleaks 8.30.1, pip-audit 2.10.1, npm 10.9.9 and Node 22.

Key takeaways

  • Assume nothing works the way it is named. Prove it with tests before you change it.
  • Security first: leaked keys, missing authorization and vulnerable packages can hurt users today. Ugly code can wait.
  • Characterization tests record what the code does, not what it should do. They are your safety net for refactoring.
  • CI gates such as secrets, dependencies, tests and lint stop the next AI-written pull request from reintroducing the same problems.

What should I check on the first day?

Work through this checklist before you change any feature. Write down every finding in an issue, even ones you will not fix this week.

  • [ ] Secrets in code and history. Run gitleaks over the whole git history, not just the current files.
  • [ ] Authorization on every data path. Can user A fetch user B's record by changing an ID? Check every API route, server action and database policy.
  • [ ] Database exposure. With a backend-as-a-service, check row-level security. Supabase's docs warn that a table in an exposed schema without RLS "is readable and writable by any role with a grant on it" (Supabase RLS).
  • [ ] Known-vulnerable dependencies. Run npm audit, pip-audit or osv-scanner across all lockfiles.
  • [ ] Data model. Dump the schema. Look for duplicated tables, missing foreign keys and money stored as floats.
  • [ ] What runs in production. Find the deploy path, the env vars, cron jobs and webhooks. Find out who has access.
  • [ ] Tests. Count them, run them, and note what fails. Zero tests is common. Do not panic.
  • [ ] Backups. Confirm that a restore works before you touch any migration.

Broken access control is number one on the OWASP Top 10:2025. Software supply chain failures are number three. Both map straight to the second and fourth items above.

How do I scan for leaked secrets and vulnerable packages?

All four tools are free and run locally. Here they are against a small test repo with a hard-coded AWS example key and an old lodash:

# secrets: scan every commit; exits 1 when leaks are found
gitleaks git .
# or just the working tree, including untracked files
gitleaks dir .

# dependencies, Node: exits non-zero at or above the given level
npm audit --omit=dev --audit-level=high

# dependencies, Python
pip-audit -r requirements.txt

# dependencies, any ecosystem: walks the repo for lockfiles
osv-scanner scan source -r .

On the test repo, osv-scanner reported five advisories for lodash@4.17.15, each with the fixed version. gitleaks reported leaks found: 1 and exited with status 1, which is exactly what a CI gate needs.

If a real secret turns up, rotate it at the provider first. Removing it from git history comes second, because anyone who cloned the repo already has it. Then move every secret into the host's secret store and add .env* to .gitignore.

How do I write characterization tests for code nobody understands?

A characterization test records the current output for a set of inputs, including outputs that look wrong. You are not judging the code yet. You are making sure your refactor does not change it by accident.

Take a typical inherited pricing function:

// pricing.js, as inherited
export function quote(plan, seats, coupon) {
  let price = plan === 'pro' ? 29 : plan === 'team' ? 25 : 0;
  let total = price * seats;
  if (seats > 10) total = total * 0.9;
  if (coupon == 'LAUNCH') total = total - 5;
  return Math.round(total * 100) / 100;
}

Call it, record what comes back, and freeze that in a test. This one uses Node's built-in runner, so no install is needed:

// pricing.characterization.test.js; run with: node --test
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { quote } from './pricing.js';

const cases = [
  [['pro', 1, undefined], 29],
  [['team', 11, undefined], 247.5],
  [['pro', 3, 'LAUNCH'], 82],
  [['free', 2, 'LAUNCH'], -5],  // negative total today. Bug? Ask the owner first.
  [['PRO', 1, undefined], 0],   // plan names are case-sensitive today
];

for (const [args, expected] of cases) {
  test(`quote(${args.map(String).join(', ')}) === ${expected}`, () => {
    assert.equal(quote(...args), expected);
  });
}

All five pass on Node 22. The last two cases are the valuable ones. They document behaviour that customers may already depend on. Fix those bugs in a separate, labelled change, and update the test in the same commit.

Start with the code that handles money, auth and data writes. For HTTP apps, a few end-to-end tests that log in and hit the main flows often give more cover per hour than unit tests.

Which CI gates should I add first?

Add gates in this order. Each one is cheap and stops a whole class of regression.

GateCommandBlocks
Secretsgitleaks git .New keys committed by people or agents
Dependenciesosv-scanner scan source -r . or npm audit --audit-level=highKnown-vulnerable packages
Testsnpm test / pytestBehaviour changes, via your characterization tests
Types and linttsc --noEmit, eslint .Hallucinated APIs, unused code, any creep
Buildnpm run build"Works on my machine" merges

A minimal GitHub Actions job:

# .github/workflows/ci.yml
name: ci
on: [pull_request]
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0          # gitleaks needs full history
      - uses: actions/setup-node@v7
        with:
          node-version: 22
      - run: npm ci
      - run: npm audit --omit=dev --audit-level=high
      - run: |
          curl -sL https://github.com/gitleaks/gitleaks/releases/download/v8.30.1/gitleaks_8.30.1_linux_x64.tar.gz | tar xz gitleaks
          ./gitleaks git .
      - run: npm test

Then make the job a required status check on main with branch protection, so nobody can merge around it. Google also publishes a reusable osv-scanner workflow that only fails on vulnerabilities a pull request adds.

In what order should I refactor?

Go from highest risk to lowest, and keep each step shippable:

  1. Security fixes. Rotate secrets, add authorization checks and database policies, upgrade vulnerable packages.
  2. Data integrity. Add constraints and fix the types of money and date columns, with migrations you have tested on a copy.
  3. Delete dead code. AI-generated repos often hold three versions of the same helper. Your tests tell you which one is live.
  4. Consolidate duplicates behind one module, one at a time.
  5. Restructure folders and naming last, because it is the least valuable and the most conflict-prone.

Keep every pull request small enough to review in ten minutes. A 4,000-line "cleanup" pull request is how vibe-coded repos got this way.

How do I use AI agents safely while fixing it?

Agents are good at reading unfamiliar code, writing the first draft of characterization tests and doing mechanical refactors. Set rules first:

  • Tests before edits. Ask the agent to write tests for the current behaviour. Review them, merge them, and only then ask for changes.
  • One task, one branch, small diff. Reject any diff you cannot review line by line.
  • No production access. The agent gets a local database and test keys, never live credentials or a prod shell.
  • CI decides, not the agent. "All tests pass" means nothing until CI shows it.
  • Write down the rules. Put conventions, forbidden patterns and the run-tests command in a repo instructions file the agent reads.
  • Check every new dependency the agent adds. It must exist, be maintained and pass the audit gate.

Sources

UniqBlog Desk · Editors

The editors of UniqBlog. Tested tutorials and tech news for working developers.

Further along the line

  1. Types of LLM: a developer's map for December 2026

    The types of LLM that matter to developers: base vs instruct, reasoning, dense vs MoE, multimodal, small on-device and embedding models, with current examples.

    AI Engineering 29 Nov 6 min read