DEV Community

Taylor Wang
Taylor Wang

Posted on

Iterating on AI Code-Review Prompts Without Spending a Token

The first time I paid for an AI code review, the machine told me to "consider making this function more maintainable." No line number. No reason. No concrete suggestion. Just a polite, expensive nudge. I tweaked the prompt, paid again, got the same generic advice. Then I started treating prompts the way I treat code.

Prompts need iteration. Iteration needs cheap experiments. And cheap experiments need free models plus a free server. That's exactly what I started using last week when I left my paid review tool behind.

Disclosure: This article was prepared as part of MonkeyCode's product outreach.

The Problem with Paid Review Loops

Every time you rephrase a review prompt, you're betting tokens against a guess. You want the model to catch a null pointer, but you also want it to stop flagging your variable names. So you change one sentence. You rerun on a real diff. The model now returns a wall of style complaints, and the actual bug is still buried. You adjust again. Your bill climbs. Your confidence doesn't.

The core problem is not the model. It's the lack of a free rehearsal space. You need somewhere to experiment without watching a meter spin.

Where MonkeyCode Fits

MonkeyCode is an open-source project that gives you two things: access to free models and a free server to run them on. No credit card, no provisioning, no cold sandbox. You point your own review tool at the server and start testing. If your prompt is bad, you only lose a few seconds. That's the kind of environment where real prompt engineering happens.

I'm not going to claim the free models are as powerful as the latest frontier models. They're not. But for iterating on the shape of a review prompt, they're more than enough. You can learn what instructions matter, what context your model actually uses, and what responses you can trust.

A Minimal CLI to Start Iterating

Here is the script I use as my scratchpad. It reads a diff from stdin, wraps it in a prompt, and calls the MonkeyCode server. You can run it locally, or plug it into a pre-commit hook.

#!/usr/bin/env python3
import os
import sys
import requests

ENDPOINT = os.getenv("MKCD_ENDPOINT", "http://localhost:8080/v1/chat/completions")
API_KEY = os.getenv("MKCD_API_KEY", "unused")
MODEL = os.getenv("MKCD_MODEL", "free-default")

def call_review(diff: str, system: str, prompt_template: str) -> str:
    user = prompt_template.format(diff=diff[:6000])
    payload = {
        "model": MODEL,
        "messages": [
            {"role": "system", "content": system},
            {"role": "user", "content": user},
        ],
        "temperature": 0.2,
    }
    r = requests.post(
        ENDPOINT,
        json=payload,
        headers={"Authorization": f"Bearer {API_KEY}"},
        timeout=60,
    )
    r.raise_for_status()
    return r.json()["choices"][0]["message"]["content"]

if __name__ == "__main__":
    diff = sys.stdin.read()
    if len(diff) > 6000:
        diff = diff[:6000] + "\n...[TRUNCATED]"

    system_prompt = "You are a code reviewer. Be concise, specific, and cite line numbers."
    prompt_template = """
Review this diff. Focus on things that can crash, silently wrong output, and security issues.
Ignore style. For each issue, state the severity and the exact line if possible.

{diff}
"""
    print(call_review(diff, system_prompt, prompt_template))
Enter fullscreen mode Exit fullscreen mode

This script is intentionally boring. The value is not the Python; it's the prompt you put in. And because the model is free, you can run a hundred variations without flinching.

A Test Set You Can Reuse

Iteration needs a fixed set of bad code, otherwise you're just vibing. I prepared three synthetic diffs, each with one specific injected bug. Copy them into files, run the script above on each, and score the output.

Diff 1: Missing null check

- def fetch(id):
-     row = db.execute("SELECT * FROM users WHERE id = ?", id)
-     return row["name"]
+ def fetch(id):
+     row = db.execute("SELECT * FROM users WHERE id = ?", id)
+     if row is None:
+         return "guest"
+     return row["name"]
Enter fullscreen mode Exit fullscreen mode

The injected bug: if id is invalid, the function should return an error, not a guest string. A good review should flag this logic change.

Diff 2: Off-by-one loop

- for i in range(len(items)):
-     process(items[i])
+ for i in range(len(items) - 1):
+     process(items[i])
Enter fullscreen mode Exit fullscreen mode

The injected bug: dropping the last item.

Diff 3: Float equality

- if a / b == 0.1:
-     log("found")
+ if abs(a / b - 0.1) < 1e-9:
+     log("found")
Enter fullscreen mode Exit fullscreen mode

This one is already fixed. A good reviewer should point out that a / b might still raise a division error if b is zero.

How to Score a Prompt

Run all three diffs through a prompt version. Record three things: how many bugs it found, how many false alarms it raised, and whether it quoted a line. After a few rounds, you'll notice patterns.

Prompt version Found bug 1 Found bug 2 Found bug 3 False alarms Line refs
v1: generic ? ? ? ? ?
v2: plus rules ? ? ? ? ?
v3: strict format ? ? ? ? ?

Fill that table for yourself. The goal is not a perfect score; the goal is to learn which instructions change behavior. That's the discipline free models let you practice.

Why Free Models Change the Workflow

When a token balance is visible, you tend to stop after two tries. "Good enough," you think. With MonkeyCode's free models and free server, you can afford a third, a fifth, a tenth try. You can also run the same prompt multiple times to see how stable the output is. That's invaluable. I caught a prompt that only worked when the diff happened to cite a function name with the word "bug" in it. You don't discover quirks like that with a single run.

Limitations and When to Skip This

The free tier has limits. The server is shared, so latency can spike. The model itself is a moving target; a prompt that works today might degrade tomorrow. And obviously, free models will hallucinate more often than a strong paid model. So do not use this as the final gate for critical code. Use it as the lab where you build a prompt that you later run against a stronger, more expensive model.

Teams under compliance requirements should skip public free tiers entirely. Same for anyone processing proprietary code that can't leave a private network. MonkeyCode's free server is not a compliance boundary. Use your own judgment.

The other group that should skip this: people who want a one-click review bot with zero configuration. Free models reward attention, not automation. You need to read outputs, tune prompts, and repeat.

The Iteration Habit

The real product here is not MonkeyCode. It's the habit of treating your prompts as testable software. Clip in a diff. Adjust one variable. Record the result. Move on. The fact that I can do that for free, on a free server, is what makes the habit sustainable. If you've never actively iterated on a review prompt, the next PR diff you have is a perfect starting point. Run it through the script above with a plain prompt. Then add one rule. Compare. Repeat. The token meter won't punish you.

That's the freedom I needed.

Top comments (0)