Steering coding agents with AGENT_TODO markers
I am working with a client in a regulated industry, which means I am accountable for every line of code I commit, including the lines a coding agent wrote on my behalf. Coding agents are fast, but the accountability does not transfer to them. In this post, I will explain how I keep that accountability while iterating with an agent: I review diffs and stage as I go, I leave AGENT_TODO: markers in the code as instructions, I action them with a skill on demand, and I put a deterministic guard at the commit boundary. I am using the Pi agent harness for the agent, and git for the review loop.
The code
All the code can be found in this GitHub repo. It is a side project I am working on, and the workflow described here is how I work in it. The post quotes only three small, self-contained files:
.agents/skills/action-agent-todos/SKILL.md— the skill that finds and actions the markers..pre-commit-config.yaml— the pre-commit configuration with the guard hook.scripts/git-hooks/check-agent-todos— the guard script.
I am writing about the repo as it was at the time of writing, at commit 2affb0b. All file links in this post point at that commit, and you can browse the latest state of the repo at the plain repo link.
My base workflow with a coding agent
My basic loop with the agent is the following:
- I prompt the agent to make changes to my codebase.
- I look at the diff and stage the files I have reviewed.
- I repeat.
- When I am happy with the result and everything is staged, I commit.
The important part is that staging is my review action. The agent is explicitly instructed, in the repo's AGENTS.md, not to stage or commit on its own:
Do not stage, unstage, or commit files, unless explicitly instructed.
The user might stage files as they review your work.
Since every file that enters a commit has been staged by me after a review, a commit contains only reviewed work.
One problem remains with this loop. For small follow-up changes, prompting the agent and pointing it at a specific file and line is more effort than the change itself is worth. For that reason, I added an extra channel of communication: I annotate the code.
AGENT_TODO markers
While I am reading the agent's diff, I sometimes find something that needs changing. A comment, a rename, a question. Instead of describing the location in a prompt, I add a comment to the code itself:
# AGENT_TODO: rename fetchResults to fetch_results and update the call sites
# AGENT_TODO: is the retry here necessary, or can I drop it?
The marker is just a comment with a fixed prefix, AGENT_TODO:, followed by the instruction. (The examples above are a reconstruction of the kinds of markers I leave, not a quote from a single session.) The question form is the interesting one: the agent answers the question in its output, so when I review the output I can steer the agent on how to address the todo, or skip it.
There is a small trick in how I stage. I stage the annotated files before I trigger the agent. This is because the same staged diff then shows both the instruction I left and the agent's removal of it. One diff review covers both directions.
The action-agent-todos skill
The markers do nothing on their own. A skill actions them. This is the skill, from action-agent-todos/SKILL.md:
---
name: action-agent-todos
description: "Find and action AGENT_TODO: markers in the codebase, treating
each marker as an instruction to follow. Use only when the user explicitly
asks to action AGENT_TODO markers."
---
The description is what gates activation. The skill runs only when I invoke it explicitly, for example with /skill:action-agent-todos in Pi. The syntax varies from harness to harness; in a harness without a skill command, a plain prompt like "action the AGENT_TODOs in the codebase" does the same job.
The first step of the skill is to find every marker in the codebase:
rg -n "AGENT(S)?_TODO:" --no-ignore --hidden \
-g '!.venv' -g '!.git' -g '!.mypy_cache' -g '!.pytest_cache' \
-g '!.agents/skills/action-agent-todos'
Some comments on the command above:
- The regex
AGENT(S)?_TODO:also catches the misspelledAGENTS_TODO:. It is a cheap bit of robustness against a common typo. --no-ignorestops ripgrep from honouring ignore files, but it does not search dot-directories on its own. Since--hiddenis added as well, markers inside.agents/or.github/are not missed.- Cache directories are excluded, and the skill excludes its own file. The skill file contains the marker string in its documentation, and it must not match itself.
The rest of the skill's contract is short. It groups the markers by file, reads enough surrounding context to understand each instruction, and actions each instruction exactly as written. It removes only the marker comment once the instruction is done, keeping any other comments on the same line. And it reports, marker by marker, what each marker asked for and what it did. Notice that if a marker is ambiguous or conflicts with the project conventions, the skill asks before acting and does not remove the marker until the question is resolved.
A complete iteration with AGENT_TODOs
Let's walk through a full loop. The example is made up; it is a typical loop, with two markers in a file called src/indexer.py. I am reviewing the agent's latest diff, and I leave the two markers. I stage the file so the markers are part of the staged diff, then I trigger the skill:
git add src/indexer.py
User: /skill:action-agent-todos
Agent: I found two AGENT_TODO markers, both in src/indexer.py.
1. Rename fetchResults to fetch_results and update the call sites. Done.
I renamed the function and updated the two call sites in build_index
and refresh. The marker is removed.
2. "is the retry here necessary, or can I drop it?" — you asked a question,
so I have not changed the code. The retry wraps the SearXNG HTTP call,
and it covers the case where the local SearXNG container is slow to
start after a restart. Dropping it would make the first request after
a restart fail. I have left the marker in place for you to decide.
I review the output before I review the diff. The output matters because the agent did not action the second marker: it asked. My answer steers the loop:
User: Skip the second one — keep the retry and remove the marker.
Agent: Done. I removed the AGENT_TODO from the retry call and left the
retry in place. Both markers are gone.
The diff the agent left behind is then exactly what I need to review: the rename, the updated call sites, and both removed markers.
--- a/src/indexer.py
+++ b/src/indexer.py
@@ -12,8 +12,7 @@
-# AGENT_TODO: rename fetchResults to fetch_results and update the call sites
-def fetchResults(query):
+def fetch_results(query):
...
I review it, stage it, and move on to the commit. If I commit with a marker still in the tree — a real risk, since I sometimes write markers myself and simply forget them — the guard catches it:
$ git commit -m "Index fetched pages"
check agent todos.....................................................Failed
- hook id: check_agent_todos
- exit code: 1
AGENT_TODO:/AGENTS_TODO: markers found. Action them (or remove them explicitly) before committing.
I action the marker with the skill, stage the result, and the next commit passes.
Making sure AGENT_TODOs never get committed
I have put safe-guards in place so that markers never reach a commit. There are various ways to do this; these are the three I use or have considered.
Option 1: ask the agent to remind you
The simplest guard is a short sentence in AGENTS.md telling the agent to check for markers before I commit. I have not implemented it in the example repo, because that repo has real pre-commit hooks, which cover the same ground more reliably. The main disadvantage of this option is that it relies on the model remembering to do it. A reminder is only as reliable as the model that reads it.
Option 2: a pre-commit hook
This is the guard I actually use. From .pre-commit-config.yaml:
- id: check_agent_todos
name: check agent todos
description: "Fail if AGENT_TODO:/AGENTS_TODO: markers remain in the codebase"
entry: scripts/git-hooks/check-agent-todos
language: system
pass_filenames: false
And the script it runs:
#!/bin/sh
# Fail if any AGENT_TODO: or AGENTS_TODO: markers remain in the codebase.
# Markers are instructions for the agent (see the action-agent-todos skill); commit
# only after actioning them.
if ! command -v rg >/dev/null 2>&1; then
echo "check-agent-todos: ripgrep (rg) not found on PATH" >&2
exit 1
fi
rg -n "AGENT(S)?_TODO:" --no-ignore --hidden \
-g '!.venv' -g '!.git' -g '!.mypy_cache' -g '!.pytest_cache' \
-g '!.agents/skills/action-agent-todos' -g '!scripts/git-hooks/check-agent-todos' -g '!.pre-commit-config.yaml'
if [ $? -eq 0 ]; then
echo "AGENT_TODO:/AGENTS_TODO: markers found. Action them (or remove them explicitly) before committing." >&2
exit 1
fi
exit 0
Some comments on the script above:
- It fails if
rgis not on PATH, deliberately. A broken guard must not pass silently. - It excludes its own artefacts: the skill file, the script itself, and
.pre-commit-config.yaml. Without the last exclusion, the hook's own description text would fail the check. - Notice that the hook greps the whole working tree, not just the staged files. A stray marker in an untracked scratch file also blocks the commit. In this workflow that is acceptable, because by the time I commit, everything relevant is staged anyway.
The advantage of this option is that it is deterministic and model-independent. It works no matter which agent, or which model, wrote the code.
Option 3: a step in the commit-message skill
I have a skill that drafts my commit message from the staged changes, and I ask for a commit message only when everything is staged. That makes the skill sit exactly at the commit boundary, so making its first step a grep for AGENT_TODO: markers means the message is only produced once the tree is clean. The main disadvantage is the same as Option 1: it is model-dependent. I treat it as a second line of defence, not as the only one.
Limitations
- Option 1 relies on the model and is less reliable than the hook.
Conclusion
In this post, I described how I keep accountability for agent-written code while working with a client in a regulated industry. I review diffs and stage as I go, I leave AGENT_TODO: markers in the code and action them with a dedicated skill on demand, and I put deterministic guards at the commit boundary so a marker never ships. The point of the whole workflow is that the human stays in the loop at exactly three points: writing the instruction, reviewing the change, and committing the result.
This post was written with the assistance of AI, as described in this post.
Comments
Join the discussionNo comments yet. Be the first to comment.