Skip to content
Back to skills

Delegated Agent Supervision

ASecurity

Dispatching a coding agent? Fence scope, verify claims.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 21, 2026
ai-agentspythonrustgoshellbashsqlnodeawsgitbackend

Works with

  • terminal
  • cli

Security analysis

A100/100

Pro scans all 7 files and shows the line behind each finding

Scanned December 3, 2026

npx -y skills add Rafaelrr5/agent-cortex --skill delegated-agent-supervision --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Delegated Agent Supervision?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Delegated Agent Supervision
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/rafaelrr5-delegated-agent-supervision/badge)](https://www.skillsdirectory.com/skills/rafaelrr5-delegated-agent-supervision)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: delegated-agent-supervision
description: "Dispatching a coding agent? Fence scope, verify claims."
version: 1.0.0
author: Rafael Rocha Ribeiro (github.com/Rafaelrr5)
license: MIT
platforms: [linux, macos, windows]
metadata:
  agent:
    tags: [delegation, autonomous-agents, supervision, verification, scope-control, git]
    related_skills: [parallel-agent-fanout, measurement-validity]
---

# Supervising Delegated Coding Agents

## When to Use

Use whenever you hand a coding task to an autonomous agent process you cannot
supervise turn-by-turn — `claude -p`, `codex exec`, `opencode run`, or any
one-shot CLI agent launched in the background.

This skill covers the two failure modes that survive a *correct* fix:
**the agent does more than you asked**, and **the agent's summary is not what
actually happened**. It is about the envelope around the delegation, not how to
drive any particular CLI — see the per-tool skills for that.

## The Two Laws

```
1. Capability flags fence what an agent CAN touch. Only the prompt fences
   what it DECIDES to touch. State the file list explicitly.
2. The agent's final summary is a self-report. Git and re-measurement are
   the evidence. Verify before you relay.
```

## Law 1 — Fence the Scope

`--dangerously-skip-permissions` (and equivalents) removes the *approval*
brake, not the *judgment* brake. A capable agent that finishes early looks
around and finds adjacent work worth doing. That instinct is good in a human
colleague and dangerous in an unattended run you cannot steer.

**Observed:** an agent asked to fix one function in one file also rewrote
`pyproject.toml`'s build backend, edited `README.md` and `requirements.txt`,
**deleted `pytest.ini`**, created an unrequested `training/dataset/`
subproject, and committed an unrelated 365-file cleanup. The requested fix was
correct — it just arrived welded to a pile of unrequested change that then had
to be untangled with the user's involvement.

The run that went rogue was the one told *"no other agent is running — the
whole tree is yours."* Phrases meant as reassurance read as licence.

### The fence block

```
## SCOPE
Your scope is ONLY:
  - path/to/file_a.py
  - tests/unit/test_file_a.py
Do NOT modify any other file. Commit only those paths with explicit
`git add <path>` — never `git add -A` or `git commit -a`. Do NOT push.
If the task appears to require touching anything outside that list, STOP and
report what you would need and why. Do not do it.
```

Name the files **even when the agent is working alone**. Never write "the whole
tree is yours."

Put the absolute repository root and interpreter path in every brief, even when
the launch already sets a working directory. A spawned agent's shell can start
somewhere else; with only relative paths, one child ran repeated whole-drive
searches before it found the repository it had been given. Require a `cwd` check
as its first step and forbid drive-wide discovery. For a `hermes` child, also
pass `--in <repo>` on launch and resume. An exit code of 0 does not prove the run
finished: check that the expected report and test artifacts exist.

### Worktrees that share a dependency junction

Isolating an agent in a `git worktree` often means linking `node_modules` (or a
similar dependency folder) from the main checkout with a Windows junction. To
remove that worktree, unlink the junction first (`cmd /c rmdir
<worktree>\node_modules` removes only the link), then run `git worktree remove`.
Observed: `git worktree remove --force` followed the junction, deleted part of
the main checkout's `node_modules` (`.bin` was gone), then failed with
`Filename too long`. Recovery was `npm ci` in the main checkout, then a rebuild
and test run.

### Concurrent agents

Disjoint file lists, and name the other agent's files as off-limits:

```
ANOTHER AGENT IS WORKING CONCURRENTLY on <their files>. Do not touch those.
If you hit a conflict, stop and report rather than resolving across scopes.
```

This works — fenced concurrent agents stayed in their lanes and reported the
boundary rather than crossing it. But concurrency **destroys clean
attribution**: two agents landing commits minutes apart each partly credited
the other's improvement to itself. When you need to know which change caused an
effect, either serialize the runs or demand a controlled measurement that
isolates the one variable.

Before you delegate, look for another agent already working in the same tree
(recent unexplained changes, a running process). Coordinate, split the files, or
wait.

## Law 2 — Verify Before You Relay

Run these before believing any summary:

```bash
git log --oneline -10          # commits you did not ask for?
git status --porcelain         # files touched outside the fence?
git show --stat <new-sha>      # what is actually in that commit?
git diff <in-scope-file>       # is the requested fix actually there?
```

Then independently re-measure the one or two numbers the conclusion rests on.

For timeline-driven or media outputs, compile/typecheck is necessary but not
sufficient: independently recompute coverage and duration (including overlaps),
render boundary/key frames from the current source, and probe the final artifact.
See `references/timeline-media-verification.md` for the failure pattern and a
compact verification recipe.

A child can report done while a process it started in the background (a render,
a test suite) is still running. Check the process or the artifact before you
relay success.

### Self-reports observed to be wrong

| Claim | Reality |
|---|---|
| "before/after: A 50, B 75" | Measured against a **zero-byte** output file the harness had silently failed to write |
| "my change produced the improvement" | A **concurrent** agent's commit, landed minutes earlier, had caused it |
| "fundamental is 0.00 cents off target" | True — but only on the sustain portion; the whole-file average said −282 cents |
| "this test failure is pre-existing" | True here — but only confirmed by checking out the prior commit and re-running |

A claimed pre-existing failure costs one command to verify. Do it.

**A reviewer's reproduction probe can be blind to the fix.** A probe written to
show data loss checked only the storage keys that existed before the fix. The
fix saved the data under a new key, so the probe still printed "lost". Before
relaying "fixed" or "still broken", extend the probe to observe the fix's
mechanism and run it against both the baseline and the fixed tree. The pair of
outputs is the evidence.

### Session-limit exit ≠ failed task: check the diff first

A long `claude -p` run can exit **code 1** with `You've hit your session limit ·
resets 5am` (or an equivalent quota message) *after it has already written most
or all of the work to disk*. The exit code and the empty-looking output
(`bash: no job control in this shell`) read like total failure — but `git status
--porcelain` / `git diff --stat` often shows the change is already there.

**Practice:** on any non-zero exit from a one-shot coding run, do NOT report
"the agent failed" until you have looked at the working tree. Sequence:

```bash
git status --porcelain          # was anything actually touched?
git diff --stat                 # how much landed?
<extract/typecheck the result>  # does it compile? (e.g. node --check for a <script>)
```

Only then decide whether to re-run, hand-finish the remainder, or report done.
In one session the run died on the limit but had completed all four requested
fronts (controls, a pre-game screen, fullscreen HUD, and a visual rebuild);
`node --check` + an ID/class cross-check + a headless-Chrome screenshot confirmed
the whole thing was functional. Treating the exit code alone as failure would
have thrown away finished, correct work.

### On Windows, a rewritten file is a CRLF landmine

An agent that rewrites a file with a Python script on Windows writes CRLF, and
git then sees the whole file as changed. Observed: 11 real lines arrived as a
2,445-line diff, and another commit carried a 541-line phantom deletion. A
commit like that ruins `blame` for that file, and `git show --stat` hides the
real change inside the noise.

```bash
git diff --stat <file>                   # absurd number = suspect
git diff --ignore-cr-at-eol --stat <f>   # drops to ~10 lines => it is CRLF
```

Normalize back to the file's original line endings before committing. Your own
writes can do the same. To count line endings, use `git ls-files --eol <paths>`
or Python `open(p, 'rb').read().count(b'\r')`, not `grep -c $'\r$'` through an
agent's terminal tool, which gave wrong counts in both directions.

### Ask for measurements, not adjectives

```
Measure everything you claim. Never report a number you did not compute.
If the fix does not fully work, say so with the numbers.
An honest 85 beats a hollow 100.
```

Naming the specific trap you fear reliably gets it checked:

```
CRITICAL: <harness> SWALLOWS exceptions and writes a ZERO-BYTE output file.
`ls -la` the output and confirm it is non-empty BEFORE reporting any score.
```

Agents given that warning caught the trap. The one not given it reported a
stale number.

### Define success as the observation, not the score

When the metric can be gamed by absence, say so explicitly:

```
The success criterion is NOT a higher number. It is <specific observable>.
If the total score DROPS because a previously-hollow check now has real
content to judge, that is a GOOD outcome — say so plainly with the numbers.
```

This produced genuinely useful honesty: one agent reported "the sidechain order
ships but is net-negative today" rather than burying a regression under a
green number.

## Two-Stage: Reviewer Then Ranked Implementer

For "review X and improve it" asks, do not hand one agent both jobs. Run a
read-only reviewer (an isolated delegated task, full problem history, file:line
evidence, ranked list with `how_to_verify` per item, an explicit output schema), save its
report as a dated artifact, then launch one unattended `claude -p` session with
that report as its only spec and a strict per-rank loop: confirm claim → smallest
fix → RED/GREEN test → objective verification → log real numbers → one commit
per rank → FINAL STATUS table. Name the objective instrument's blind spot in the
prompt ("do NOT trust 'score unchanged' as proof for rank N — the scorer cannot
see Y"), and tell it to write *why* when a rank is contradicted by the code
rather than force the reviewer's fix. Expect ~1 in 3 open items to flip on
measurement; relay those contradictions first. Full prompt loop, overrides and
verification: `references/review-then-rank-session.md`.

## Queued Fleets: the Status Field Is Also a Self-Report

When agents are dispatched by a queue or board rather than launched by hand,
Law 2 still applies — but the self-report you must distrust is no longer just
the final summary. It is **the recorded status of each task**. A supervisor
process writes those statuses by observing worker processes, and it can
attribute a cause wrongly.

### A stalled worker has three different causes that look identical

| Recorded state | What actually happened | Correct action |
|---|---|---|
| Blocked, with a finished report or artifact already attached | The work is **done**. A human owes a decision | Do not retry or re-route. Extract the question and put it to the user |
| Blocked after repeated worker deaths ("crash x2", "pid N not alive") | Usually **quota**, not a bug — see below | Re-route to an available provider, release, re-dispatch |
| Waiting, predecessors unfinished | A real dependency | Leave it. It releases itself |

Only the middle row is a problem you can fix by changing models. Re-routing a
task that is waiting on a human is pure waste, and it buries the question the
user actually needs to answer.

### Quota exhaustion is recorded as a crash

Observed: a worker died twice; the task record said only
`Agent crash x2 — pid not alive`, with no mention of quota anywhere. The
worker log showed the real story — the primary model returned
`rate_limit_error` with `credits_required` / `org_level_disabled`, failover
moved to the secondary account, which returned HTTP 429 `usage_limit_reached`
with a reset horizon of ~4.5 days, and three retries later the process exited.

**Always read the worker's own log before diagnosing a repeated death.** The
task record carries the symptom; only the log carries the cause. A `429` with
`credits_required` or `usage_limit_reached` is a routing decision, not a defect
— no amount of retrying at the same tier clears it, and the reset horizon in
the payload tells you whether waiting is even viable (hours: wait; days: move).

This is the queue-level twin of the "pre-existing failure" trap: one command
separates a real bug from an environmental stall. Run it.

### Verify a re-dispatch after a delay, never at the instant of dispatch

A status read taken immediately after re-dispatching is **not evidence**.
Newly-spawned workers report as running and can die seconds later on the exact
error you were routing around. Wait a minute or two, then re-read, and check
more than the status field — a record showing *running* while also carrying a
stale failure error has already crashed at least once.

Only report "N tasks running in parallel" after that second read. In this
session the first report was drawn from the instant snapshot and claimed ten
running; minutes later several had finished, several were blocked awaiting
human decisions, and two were dead from quota. The instant snapshot produced a
materially wrong status report to the user.

### Approval holds need a verified dispatch barrier

For a portfolio-wide agent-runtime/repository workflow review, also read
`references/process-audit.md` for measurement, scope and cost discipline.

When provisioning audit cards without execution authorization, inspect the live
CLI and use `--initial-status blocked`, but **do not trust that field alone**.
A live run was promoted and spawned despite being created blocked; the worker
then refused the unapproved scope and reblocked with `needs_input`. A later
blocked snapshot hides this unauthorized attempt. Read `task_events` and
`task_runs` after a dispatcher tick, not just the task status.

Preserve an explicit authorization hold and use real dependency gates for its
unapproved descendants. Do not unblock/reblock to retrofit a block kind: that
opens a dispatch race. On builds where `block` refuses an already-blocked card,
report the limitation and fix through a supported atomic path, never raw SQLite
writes. Record any unintended worker launch honestly, even if it self-stops.

### Surface the human decisions first

When a fleet drains, the valuable output is usually not "what finished" but
**the questions that are now blocking**. Collect every task blocked on human
input, state each decision plainly with the evidence the worker gathered, and
lead the report with them. Those are the only items that cannot progress
without the user.

See `references/queued-fleet-supervision.md` for the recorded evidence and the
recovery sequence.

### Provisioning audit cards without a dispatch race

Do not provision an unapproved parentless root in a live-dispatch board unless
the current build offers a verified atomic human-hold creation path. Creating
with `--initial-status blocked` and immediately calling `block` is **not a safe
substitute**: the latter can refuse an already-blocked card without setting its
kind, leaving it eligible for promotion. A shorter timing window does not fix
the race. Use an existing verified approval dependency or keep the proposed
backlog outside the executable queue until an atomic hold is available.

Inspect `create --help`, `block --help` and `reclaim --help` on the live build.
CLI syntax changes: this build accepts a positional reason and `--kind`; do not
invent `--reason` or assume all commands accept `--json`. If an unauthorized
worker is active, use supported claim recovery, verify the actual process
stopped, and inspect its log and file changes before reporting containment.
Never release a hold just to make the CLI accept a second block.

Use `--idempotency-key` to make provisioning repeatable. Set the executor ceiling
explicitly; then verify both task status and attempt history after a dispatcher
tick. The root needs a real authorization barrier, not just a blocked label.

## Steering and Stopping

One-shot `-p` / `exec` runs are **not steerable mid-flight**. The only levers
are the prompt you started with and killing the process. Everything you care
about must be in the prompt before launch.

Hermes `delegate_task` children are steerable. When the user changes a
parameter while a child is working, send `delegate_task(action='steer',
subagent_id=..., message=...)` with the new rule and where to record it, then
tell the user it was passed on. Waiting for completion and re-dispatching builds
the same work twice.

Pass credentials to any child as a file path with "load it, never print or
commit the values", never as literal values. The brief lands in transcripts and
logs.

If a run starts producing out-of-scope commits, kill it rather than letting it
accumulate more:

```
Use your runtime's process-stop tool with the specific session identifier,
or terminate the verified worker PID with your operating system's process manager.
```

Spot-check `git status --porcelain` during long runs to catch drift early.

## Cleaning Up After a Scope Violation

1. **Back up the in-scope work first** — copy the good files to a temp path
   before touching anything.
2. **Do NOT revert or delete unilaterally.** Reverting another agent's work is
   destructive and irreversible, and the out-of-scope change is sometimes
   independently valuable (an unrequested `.gitignore` cleanup was legitimate,
   just unasked-for). Deletion commands may be blocked pending user consent —
   correctly so; do not rephrase around the block.
3. **Present the choice to the user:** what was in scope, what was not, what
   you would keep, and why. Let them decide.

## Prompt Skeleton

See `references/delegation-prompt-skeleton.md` for the full copy-paste
structure, invocation notes, and the post-run verification recipe.

For a large or multi-part prompt, do NOT inline it as the CLI argv string —
write it to a Markdown brief and pass it through stdin with `< prompt.md` in
one background call. `$(cat ...)` expands into argv and does NOT evade Windows
length limits. See `references/long-prompt-via-file.md` for the pattern and
startup/completion verification.

## Checklist

Before launch:
- [ ] Multi-item "review and fix" ask? Split into reviewer → ranked implementer (see above)
- [ ] Objective instrument's blind spot named, with the direct observable to measure instead
- [ ] Explicit file list in the prompt; `git add <path>` mandated (or, for a rank session: per-rank commits, never .db/media/.env)
- [ ] "STOP and report" instruction for out-of-scope needs
- [ ] Concurrent agents' files named as off-limits (if applicable)
- [ ] Known traps named specifically (swallowed errors, stale artifacts)
- [ ] Success defined as an observation, not a score
- [ ] "Never report a number you did not compute"

After completion:
- [ ] `git log` / `git status --porcelain` reviewed for scope violations
- [ ] The requested fix confirmed present in the diff
- [ ] The child's "gaps / not done" list read against the user's original complaint: a gap on the path the user reported is a blocker, not a footnote
- [ ] Its branch rebased on the current main, then rebuilt and retested, because other sessions move main while the child works
- [ ] Key numbers independently re-measured
- [ ] Timeline/batch coverage independently recomputed when the artifact spans segments
- [ ] Boundary/key frames rendered and final container probed for media outputs
- [ ] "Pre-existing failure" claims verified against the prior commit
- [ ] Migrations or config the agent wrote checked for edits to pre-existing objects (policies, grants, constraints on tables the task did not own). Staying inside the file list is not staying inside the scope, and the agent's own tests only cover its new code
- [ ] Attribution checked if agents ran concurrently

Files in this skill

  • SKILL.md20.2 KB
  • references/delegation-prompt-skeleton.md4.6 KB
  • references/long-prompt-via-file.md1.9 KB
  • references/process-audit.md4.3 KB
  • references/queued-fleet-supervision.md3.3 KB
  • references/review-then-rank-session.md6.1 KB
  • references/timeline-media-verification.md2.9 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.