Vibecoding in Production


Jul 23, 2025 See all posts

The Agentic Coding Workflow: How to Do 300k-LOC Refactors Using Free AI Models

Most people think “AI-assisted coding” means asking a chatbot for tiny snippets: “Write this function… fix this bug… why is TypeScript crying again?” That’s toy usage.

But the people doing 300k-line refactors, solo, in weeks? They treat the AI like a full junior developer team — with structure, files, plans, rules, and strict control.

The catch? Most tutorials rely on expensive tools like Claude Code and paid automation.

This guide gives you the same power using free or standalone models like Gemini, Qwen, DeepSeek, Codestral, etc.

This is a complete workflow — not a prompt.


1. The Two-Model Setup: The Brain vs. The Hands

Using one model for everything is the reason most people get garbage results. Large projects need a split:

A. The Architect — the “Brain”

Use: Gemini 2.5 Pro or whatever SOTA you use Role:

This model is your Senior Engineer.


B. The Builder — the “Hands”

Use: Qwen 2.5 Coder, DeepSeek Coder V2, or coder model of your choice Role:

This model is your Junior Developer.


2. The Rulebook System (Manual Replacement for Auto-Skills)

Paid tools keep the AI “on track” automatically. You can replicate this manually using a single file:

Create a file called AI_RULES.md.

Paste this at the start of every coding session.

What goes inside?

A. Your Tech Stack (very specific)

Examples:

B. Your Coding Rules

Examples:

  1. Output full files — no placeholders.
  2. Wrap database calls in try/catch.
  3. Components must be pure functions.
  4. All API routes must validate input.

C. Your Project Commands

Examples:

This becomes the AI’s “company handbook.”


3. The State Management System (Your Manual Memory)

AI forgets. Long tasks drift. Refactors get derailed.

You fix this by creating three files for every major task:


1. TASK-PLAN.md — Your Master Plan

Generated by the Architect model. Contains:


2. TASK-CONTEXT.md — Your Scratchpad

You paste into it:

This prevents hallucinated variable names.


3. TASK-CHECKLIST.md — Reality Tracker

A simple list you tick off manually.


The workflow:

Step 1 — Ask the Architect:

“Read auth.ts. Create PLAN.md, TASKS.md, and list risks. Don’t write code yet.”

Step 2 — For each phase:

You give Qwen/DeepSeek:

When hallucinations start → paste the plan again. This resets the AI’s “mental state.”


4. The Error-Free Loop (Manual Equivalent of Hooks)

You are now the “QA team.”

A. Before you run any code:

Ask the model:

“Review your own output. Check for missing imports, TypeScript errors, broken types, or insecure patterns. Give me the fixed version.”

This eliminates 70% of runtime errors.


B. When something breaks:

Don’t say “it doesn’t work.”

Instead paste the full stack trace.

Example prompt:

“Here is the stack trace. Fix only the errors mentioned. Do not refactor unrelated code.”

This keeps the model focused.


C. Formatting?

Never waste tokens. Use your IDE.


5. Backend Stability With PM2

If you run backend services (Node/Go/Python), logs get messy. Crashes are missed. Terminals get flooded.

Solution: Use PM2

npm install pm2 -g
pm2 start app.js --name backend --log-date-format 'YYYY-MM-DD HH:mm:ss'

When something breaks:

pm2 logs backend --lines 100

Paste that into your Architect model:

“Here are the last 100 lines. Diagnose the crash.”


6. The Agent Personas (Without Needing a Full Agent System)

Paid systems run specialized agents. You can simulate them with targeted system prompts.

A. Planning Phase

“You are strategic-plan-architect. Produce a detailed plan. Minimize technical debt.”

B. Coding Phase

“You are senior-react-dev. Write clean code following AI_RULES.md.”

C. Debugging Phase

“You are build-error-resolver. Fix only the errors in the logs below.”

This “persona shifting” keeps the model sharp.


7. Documentation That Improves the AI Over Time

AI performs better when it has your project’s cumulative memory.

Maintain two files:

A. AI_RULES.md

Generic rules about how code should be written.

B. ARCHITECTURE.md

Project-specific documentation:

At the end of every session:

Ask:

“Summarize everything we changed today so I can save it to ARCHITECTURE.md.”

This becomes your “save game.”


The Final Checklist

This is the workflow in 10 seconds:

Follow this, and even free models become real engineering partners — not autocomplete toys.



Enjoyed the article? I write about 1-2 a month. Subscribe via email or RSS feed.