archive2026

How I let a coding agent work in my repositories

Coding agents can now edit files and run commands for a long time without asking. The setup I use to keep that safe and reviewable: a branch, a sandbox, tests as the contract, and small diffs.

3 min read#dev#agent#git

I use coding agents for a lot of small work now. They read the repository, edit many files, run the tests and the build, and try again when something fails, often for a long time without asking. The agent can run any command my user can run, and it can produce more code than I can read carefully. After a few months I have settled on some rules. They do not depend on a specific tool.

A branch or a worktree

Never let the agent work on main. Give it a branch. If you want to keep working yourself at the same time, give it its own worktree:

git worktree add ../myproject-agent -b agent/fix-mqtt-reconnect
cd ../myproject-agent

Now the agent has its own folder and branch. When it is done, you review the branch like any pull request. If the result is bad, delete it:

git worktree remove ../myproject-agent
git branch -D agent/fix-mqtt-reconnect

No secrets in the working directory

The agent reads files to understand the project. If .env contains production credentials, the agent reads them too, and they may end up in a log, a prompt, or a commit.

So real secrets stay out of the repository folder, in a secrets manager or a file outside the tree, with a .env.example of fake values in the repository. And the agent does not get a shell where cloud CLIs are logged in to production.

Limit what it can run

Most agents have a permission setting: ask before each command, allow a list of commands, or allow everything. My default:

  • Allow: reading files, running tests, running the linter, running the build, git status, git diff.
  • Ask: installing packages, network access, git push, anything with sudo.
  • Never: deploy commands, database migrations against shared databases, rm -rf outside the project.

For longer unattended runs, use a container or a VM with only the project folder mounted and no access to your home directory. A devcontainer or a plain docker run is enough:

docker run --rm -it \
  -v "$PWD":/work -w /work \
  --network none \
  python:3.14 bash

--network none is strict. If the agent needs to install dependencies, install them first, then cut the network.

Tests are the contract

An agent is good at making tests pass. So the tests must describe what you really want.

  • Before the task, write or check the test that shows the bug or the new behaviour.
  • Tell the agent not to change existing tests unless you ask. Then check in the diff that it did not.
  • Watch for tests that were made weaker: removed asserts, broader except, skipped tests, larger tolerances.
git diff main -- tests/ | grep -E '^\-.*assert|skip|xfail'

This is a rough check, but it finds the common cases.

Small diffs

Review cost grows faster than diff size. A 50-line diff gets a real review. A 2,000-line diff gets a quick scroll. Split the work: one task per branch, one concern per commit. If the agent produces a huge diff, ask it to split the change into steps, or throw it away and give a smaller task.

Read the diff

The agent’s summary of what it did is useful, but it is not proof. I read the diff, and I look especially at:

  • New dependencies in package.json, pyproject.toml, pom.xml or Cargo.toml. Check that each one exists, is the package you expect, and is maintained.
  • Changes to CI config, build scripts and git hooks.
  • Code that catches and ignores errors.
  • Files outside the area of the task.