Skip to main content

Command Palette

Search for a command to run...

Guardrails for Coding with Agents

Published
3 min read
Guardrails for Coding with Agents

Working with coding agents can feel like pair programming with an overeager junior partner: enthusiastic, fast, but sometimes reckless. To keep the collaboration safe and productive, I’ve developed a set of safeguards that make coding with agents reliable instead of chaotic.

These guardrails help me keep control of the workflow, protect the codebase, and ensure that the agent and I move in small, verifiable steps.


1. Pre-Commit Hooks in Addition to CI

I used to rely mainly on CI checks after push. That’s not enough when refactoring with an agent.
Now I run fast checks locally on every commit via pre-commit hooks:

  • Format and lint (SwiftLint, Ruff, Black, etc.)

  • Fast unit/integration smoke tests

  • Block commits that break them

This keeps history clean before code ever reaches CI.

👉 Lesson learned: never allow the agent to bypass hooks. I repeat in prompts:
“NEVER use --no-verify.”
I’ve caught agents slipping it in “to fix local issues,” while breaking something else.


2. Prompt Add-Ons to Keep the Agent on Track

Certain phrases have become guardrails I use constantly:

  • “DON’T WRITE CODE YET!” — prevents premature edits while planning.

  • “ONLY implement the next task and then run the integration test.” — forces small, test-driven steps.

  • “NEVER use --no-verify.” — reinforces hook discipline.

I often reassert these after chat compaction, when the agent tends to forget constraints.


3. Small Steps, Many Commits

Agents thrive on big changes. Humans thrive on small, reversible ones. My rules:

  • One commit per change. Lots of tiny commits.

  • Checkpoint before each agent run. Commit/tag, then let it work.

  • Never use the agent to undo. Instead, use Git:

    • git reset --hard HEAD~1

    • git revert HEAD

    • git restore path/to/file.swift

This way I always have a deterministic escape hatch.


4. Handling Compaction Resets

The riskiest moments are when the agent compacts the chat. Suddenly all my constraints are gone and it reverts to overdesign mode.

When I catch this, I stop and say:
“Please don’t just create new work and ideas. Please start with explaining to me what you are currently trying to achieve.”

If I miss it, I often have to restart the simplification process. The lesson: detect compaction early and reassert constraints.


5. Visualizing the Safe Flow

Here’s a diagram of the safe refactor loop:

Wrapping Up

Guardrails aren’t optional when pairing with coding agents. They make the difference between chaos and flow.

  • Pre-commit hooks catch mistakes before CI.

  • Prompt add-ons keep the agent disciplined.

  • Small commits and Git rollbacks let me undo instantly.

  • Reassert constraints after compaction to avoid spirals of overdesign.

These practices have completely changed how I work with coding agents. They create the structure and safety I need to move fast without breaking everything.

In my next post, I’ll explore the why behind this process — how these guardrails enable a surprisingly old rhythm in software development: “Make it work, then make it good.”