ANTIGRAVITY LABJP
Articles/Editor View
Editor View/2026-07-11Intermediate

I Only Want to See the Lines the Agent Added: A Changed-Lines Convention Linter

I asked an agent for a small fix, it touched an old file, and the linter threw 13 warnings with no way to tell which were the agent's. Scoping the linter to only the added lines dropped 13 to 3 — about 77% less noise. Here is how to pull added lines out of a diff and check only those, with working code.

Antigravity321AGENTS.md10code review4linterdiff3

Premium Article

I asked an agent to "add a delete endpoint." The diff that came back was clean: one new function, nothing else. Out of habit I ran the pre-save lint, and my hand stopped.

Thirteen warnings.

Scanning down the screen, almost all of them were console.log and var I had written myself, years ago. Which of these lines had the agent actually added just now? By the time I had matched them one by one and confirmed that only three of the violations were newly introduced, half of my appetite for reviewing the change was gone.

The problem is not the agent. It is that linting the whole file makes the warning count scale with how much debt the file carries, not with how large the change is. In what follows we build a small thing that breaks that proportion: a changed-lines linter that inspects only the lines the agent touched. As an indie developer leaning on agents for more edits, I have found this one move pays off quickly.

Why "changed lines" instead of "the whole file"

Code review in the agent era has a different texture than before. When humans wrote one line at a time, the change and the file mostly lined up. New files had the current conventions baked in from the start; old files stayed old; the boundary was clear.

Agents cross that boundary without a thought. "Add one function next to this one" is enough for them to reach confidently into a ten-year-old legacy file. The result is that a five-line addition drags in hundreds of lines of accumulated old violations, all onto the same screen.

Run a whole-file lint here and the reviewer loses twice. First, the agent's genuinely new lines — the ones worth reviewing — drown in the noise of existing violations. Second, you give in to the "while we're here, let's fix the old ones too" temptation, let the agent rewrite beyond what you asked for, and watch the diff balloon.

Changed-lines scope untangles both. Limit the judgment to "lines added in this diff." The legacy debt stays exactly where it is, but not a single newly added violation slips past. It is a deliberate narrowing: commit to not making the debt worse.

Pulling the added lines out of a diff

The heart of this is reading added lines, with their line numbers, out of git diff. The key is --unified=0, which suppresses the surrounding context lines. If context creeps in, unchanged lines end up in scope and the whole point of narrowing dissolves.

In the hunk header @@ -a,b +c,d @@, the +c is the starting line number in the new file. Count forward from there over the + lines and you have the real line number of each addition.

import re, subprocess
 
def added_lines(path):
    """Return (new_lineno, text) for each line the diff ADDED."""
    out = subprocess.run(
        ["git", "--no-pager", "diff", "--unified=0", path],
        capture_output=True, text=True).stdout
    added, newno = [], None
    for ln in out.splitlines():
        m = re.match(r'@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@', ln)
        if m:
            newno = int(m.group(1))
            continue
        if newno is None:
            continue
        if ln.startswith('+') and not ln.startswith('+++'):
            added.append((newno, ln[1:]))
            newno += 1
        elif not ln.startswith('-'):
            newno += 1
    return added

Deleted lines, which start with -, do not exist in the new file, so we do not advance the counter for them. Count a deletion by mistake and every line number after it shifts. That is the quietly easy gotcha here.

Multiple hunks — say you edited two separate spots in the file — are handled too, because we reset newno every time we see a hunk header. Running it against a diff that edited one place near the top and another near the bottom, it picked up the added lines in both, each with the correct line number.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
A diff parser that extracts only the ADDED lines, with their real line numbers
A changed-lines linter, and a measured drop from 13 warnings to 3 (about 77%) on a legacy file
Pairing an AGENTS.md advisory layer with a deterministic gate as a two-stage check
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

Editor View2026-06-26
Splitting a Giant Antigravity Diff Into Meaningful Commits
Are you committing the agent's 400-line diffs as a single blob? Here is a practical workflow, with scripts, for re-splitting an unreviewable bulk commit into one concern per commit.
Editor View2026-06-22
Precedence for Nested AGENTS.md: A Merge Design for Many Projects in One Workspace
Put several projects in one workspace, each with its own AGENTS.md, and which instruction the agent follows turns ambiguous. Root and per-project rules quietly collide; one wins, or both blend. Taking 'closer is stronger' as the base rule, this designs a merge that distinguishes overriding from appending, with working Python and field notes.
Editor View2026-04-13
Gemma 4 × Antigravity: Build a Local AI Code Review Setup That Never Sends Your Code to the Cloud
Run Gemma 4 locally and integrate it with Antigravity's editor for AI-powered code reviews that keep your proprietary code entirely on your machine.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →