ANTIGRAVITY LABJP
Articles/Integrations
Integrations/2026-06-18Intermediate

Gating Your Agent's Commits With pre-commit — Keeping Broken Changes Out of the Main Repo

How to wire up a pre-commit gate that lints, type-checks, runs fast tests, and scans for secrets the moment Antigravity's agent commits — with measured timings and the ordering that keeps it fast.

Antigravity243pre-commitGit3quality-gate2agents94

Premium Article

I once asked an agent to fix a bug, and the next morning the green tests in my commit history had turned red. It was a repository for an app I run as an indie developer.

The bug it was asked to fix was genuinely fixed. But somewhere along the way it had deleted a single import in an unrelated file, and an unrelated module now crashed on startup.

The agent was not at fault. The real cause was that I had left myself in a state where I could commit generated changes without reading them.

A human review on every change would be ideal, but when you hand work to an agent many times a day, reading every full diff each time does not last. So I lean on pre-commit. If you concentrate inspection at the single point of the commit, both agent output and your own manual edits pass through the same net, every time.

Why the commit moment is the right checkpoint

An agent's work rewrites files one after another. Intermediate states are broken by definition, and inspecting them there means nothing.

What you want to inspect is the moment the agent decides "this is a stopping point" and tries to finalize the change. That moment is exactly git commit.

You could inspect in CI instead, but CI runs after the push. By then the broken commit already sits in local history and the agent has moved on to its next task. With pre-commit, a broken change never even becomes a commit. The win is that it closes inside the agent's own working loop.

I use the same idea running my blogs. In the pipeline that auto-updates the Dolice Labs sites, every article passes through a Python quality gate right before push, and any violation means the article is thrown away and rewritten. Placing inspection just short of the final destination is the same instinct whether the artifact is code or prose.

Start from the smallest config

If you stack heavy hooks from day one, the agent's wait time stretches and you stop wanting to use it. Begin with only what is fast and high-impact.

Create .pre-commit-config.yaml at the repository root.

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-merge-conflict
      - id: check-added-large-files
        args: ["--maxkb=500"]
  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.12.1
    hooks:
      - id: ruff
        args: ["--fix"]
      - id: ruff-format

Installation is two commands.

pip install pre-commit
pre-commit install

Running pre-commit install once replaces .git/hooks/pre-commit, and from then on every git commit carries the inspection. When the agent calls git commit internally, the same net fires — no special setup is needed on the agent side.

At this point, commits containing syntax errors, leftover merge markers, or an accidental huge file all stop at the commit stage. In my measurements, this minimal hook set finishes in under a second when only a handful of files are staged. It does not register as wait time.

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 working .pre-commit-config.yaml that rejects a broken change in 1 to 3 seconds, before it ever becomes a commit
How to feed the failing hook output back to the agent so it self-corrects without a human in the loop
The order to stack secret scanning, type checks, and fast tests so coverage grows without adding wait time
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

Integrations2026-06-17
When the Antigravity CLI Stalls on a 401 During Unattended Runs
If your scheduled Antigravity CLI job suddenly stops producing output after a single 401 in the logs, here is how to separate an expired token from a silent re-login prompt and rebuild your unattended setup.
Integrations2026-06-14
Trusting Temporal Workflows in Production — Field Notes on Idempotency, Retry Triage, and Saga Compensation
Practical notes from running Temporal as a production backend: how to make activities idempotent for real, where to draw the line between retryable and fatal errors, how to keep Saga compensation from firing twice, and how to make it all observable—built with Antigravity in the loop.
Integrations2026-06-09
Rebuilding Wallpaper Image Delivery Around Resolution Buckets — Letting an Antigravity Agent Own Conversion and Validation
Every new device resolution quietly makes a wallpaper app heavier. I stopped shipping one master image to every device and rebuilt delivery around resolution buckets, WebP/AVIF, and an edge redirect — then handed conversion and validation to an Antigravity agent. Real code and thresholds included.
📚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 →