/build-loop:flag-issue [optional name of the thing that misbehaved]from build-loop
Logs a correction to the bug queue at ~/.claude/build-loop/queue/, against anything the user built — a skill, a hook, a slash command, a plugin, or a loose script. Use when the user says "that was wrong", "it should have", "next time", "don't do that", corrects anything of theirs by name, says the output was not what they wanted, or explicitly invokes /flag-issue. Reads the current session context to pre-fill what it was, what happened, what was expected, and a correct example; then shows a draft to the user and waits for confirmation before writing. Dedupes against queue entries from the last 10 minutes. After writing a primary entry, reads DEPS.json and auto-adds one dep-review queue entry per dependent listed in the map — so anything likely affected by the fix surfaces for review without the user having to remember.
Ships in build-loop. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You are logging a correction to the build loop bug queue at ~/.claude/build-loop/queue/. The schema is at ${CLAUDE_PLUGIN_ROOT}/reference/SCHEMA.md — read it if you haven't already in this session.
Paths in this file are written with
~for readability. The Write tool and Node'sfsboth take it literally, so expand it to the absolute home path before using it. A literal~creates a directory called~next to wherever you happen to be, and every check that follows then reads the wrong place.
Every queue write goes through
scripts/queue.js. This skill used to write entries with the Write tool, on the argument that a brand-new file under a fresh timestamped name has no good file to lose. That reasoning was about half-written files and it was right about those. It missed the other failure: the dedup check and the write were separate tool calls, so two sessions capturing the same correction both looked at the queue, both saw no duplicate, and both wrote. The check was never the problem. The gap after it was.The
createcommand does the check and the write inside one process holding one lock, so nothing can land between them.
Scratch files go in a private directory, made once per run. Make it before the first hand-off and reuse it for the rest of the run:
node "${CLAUDE_PLUGIN_ROOT}/scripts/scratch.js"
Use the path it prints, written as {scratch} below, and never a fixed name
under /tmp, which another live session can overwrite between the Write and
the call. If it exits non-zero it printed why instead of a path, so say
what it said and stop rather than treating that sentence as a directory.
If there is no session history (brand new session, /flag-issue run immediately with no prior exchanges), open with:
"No recent context to pull from. What went wrong, and what was it that misbehaved?"
Then proceed to Step 1 using whatever the user tells you.
Look back at the last 3–5 exchanges in the current session. Extract five pieces of information.
1. target — the name of the thing being corrected. It does not have to be a skill. A hook, a slash command, a plugin, or a loose script are all valid, and the queue records which. Matching rules, in order:
$ARGUMENTS is non-empty, use it as the name.{guess}. Is that right?"2. target_kind — one of skill, hook, command, plugin, script, other. Infer it rather than asking:
hookcommandSKILL.md: skillpluginscriptotherYou show this in the draft at Step 2, so a wrong guess costs nothing. Asking about it as its own question costs a turn.
3. target_path — the absolute path to the file a fix would edit. Resolve it this way:
Two calls before you search anything, answering different questions. First, whether the roots are there, which is the one you relay:
node "${CLAUDE_PLUGIN_ROOT}/scripts/roots.js" check
Then, for the roots themselves:
node "${CLAUDE_PLUGIN_ROOT}/scripts/roots.js" list
Every root comes back with an absolute path, its kind, and whether it
exists. The defaults are already applied when there is no config file, and
a pre-v2 skillRoots config has already been read as roots of kind skill.
list prints JSON on every exit code except 1, so it is not the thing you
relay for a missing root. The sentence naming a missing root and its path
lives in check, on purpose, so six callers cannot word the same condition
six ways. Exit 1 is the exception in both: the config could not be read at
all, and both print that one sentence rather than JSON. The exit codes below
are check's, and list returns the same ones.
Every one of those messages arrives on stdout, including exit 1. That is true
of check. list prints its JSON there too, so relay the one and read the
other.
Search the roots whose kind matches target_kind, in configured order, first hit wins:
skill: ls <root.path>/{target}/SKILL.md, then ls <root.path>/{target}/skill/SKILL.mdhook: ls <root.path>/{target}, then ls <root.path>/{target}.*command: ls <root.path>/{target}.mdOn a hit, use that path and set repo to that root's name.
Also search every root of kind plugin-repo, whatever the target_kind is. These hold things nested one level deeper, and the subdirectory that matches is what tells you the kind:
node "${CLAUDE_PLUGIN_ROOT}/scripts/roots.js" layout --root <root.path> --slug {target}
A hit here overrides the kind you guessed in step 2 of this list, because the directory it was found in is evidence and your guess was not.
A plugin resolves to its .claude-plugin/plugin.json, never to its
directory. The path recorded here is what /apply-fix later opens, and a
directory cannot be opened or edited. DEPS.json stores plugin rows the same
way, so recording a directory also makes the queue entry and the map disagree
about the same plugin.
The listings are generated, and /audit-deps and /built-check read the
same list. They used to be a copy each, in prose, in three skills. bin/ was
added to the repository on 2026-08-14 and to none of the three, so
bin/hook-node resolved nowhere here and appeared in DEPS.json zero times,
while being the file every hook in every plugin starts through. statusline/
and tests/ are in the list for opposite reasons and both used to be
forgotten: statusline/ is another place a plugin keeps executable code, and
tests/ sits at the root of the repository inside no plugin, so a glob
anchored at plugins/*/ cannot reach it. The test row matches the bare name
and the .test.js form together, since a correction is far more likely to
arrive as "session-skills" than as "session-skills.test".
scripts/ is not optional and it is where the logic usually lives. A hook or a skill in a well-built plugin is a thin wrapper over a module in scripts/, so that is the file a fix edits. Leaving it out meant hook-io, config, command, scan and patterns all failed to resolve and fell through to asking the user for a path. Two of the four guardrails bugs fixed on 2026-07-27 were in scripts/, so this was the common case rather than the edge.
If more than one plugin holds a file with the same name, scripts/cli.js exists in three, do not pick one. List the paths and ask which:
"
{target}exists in more than one plugin: {paths}. Which one?"
If target_kind is other and nothing above matched, there is no convention left to search. Ask.
If nothing was found anywhere, the check in point 1 has already said whether the roots themselves are the problem. Where it named one as gone, repeat that before asking for anything: a root that has moved is the likely reason, and naming a file does not fix it.
Then ask: "I can't find {target} in any configured root. What file should a fix edit?"
Record whatever path they confirm. If it sits outside every configured root, set repo: "unknown" and note it. Never guess a path, and never fall back to a plausible-looking file. A wrong path here sends a commit into an unrelated repository.
Never record a path under ~/.claude/plugins/marketplaces/. That is the plugin manager's cache and it is overwritten on the next update, so a fix committed there disappears without warning. If the only match is there, say so and ask where the checkout lives:
"
{target}resolves to the installed copy at{path}, which the plugin manager overwrites on update. Where is the checkout you actually edit?"
4. what_happened — the behavior the user flagged as wrong. Summarize in one or two sentences in plain language. Quote the user's own words if they are short enough.
5. what_expected — what the user said it should have done. If they stated it explicitly, quote them. If not, ask ONE clarifying question:
"Got it. What should it have done instead? A rough description is fine."
6. correct_example — a concrete example of correct output. If the user gave one, use it verbatim. If not, ask ONE question:
"Can you give me a rough example of what the right output would have looked like? One line is fine."
Rule: ask at most ONE clarifying question per turn. If the user's last message already answered a question, do not re-ask it.
Display the draft in this exact format before writing anything:
I'll log this correction to the queue:
Target: {target} ({target_kind}, path: {target_path}, repo: {repo})
What happened: {what_happened}
What expected: {what_expected}
Correct example: {correct_example}
Write it? (y / edit / skip)
On the user's response:
y, yes, sure, go, or any clear affirmative → proceed to Step 3.edit or any change request → update the draft with them edits, re-show, ask again.skip, no, nope, or any negative → respond "Skipped, nothing logged." and stop. Do not write anything.No silent writes. Ever.
Before writing, check for a duplicate:
Compute dedup_key:
what_happened.-, strip leading/trailing dashes.dedup_key = "{target}::{slug}"Look for an existing entry with the same dedup_key created in the last ten
minutes, so you can tell the user before writing:
ls ~/.claude/build-loop/queue/*.json 2>/dev/null
Read each and compare. This is a courtesy check, not the guarantee. The real one happens inside the lock in Step 4, which is where a duplicate is actually refused, and it is worth knowing which is which: this check can be beaten by another session writing in the moment between it and your write, and that one cannot.
If a duplicate is found:
"I already have a similar entry from {when}:
{existing_filename}. Skip (dedupe) or write anyway?" Default if no response: skip.
If no duplicate, continue to Step 4.
Compose the entry object. All fields required per SCHEMA.md v5:
$schema_version: 5
id: {YYYY-MM-DDTHH-MM-SS}-{slug(target)} ← filename stem, must match exactly
created_at: current UTC time in ISO-8601 (e.g. 2026-04-23T14:30:00.000Z)
status: "Open"
type: "primary"
parent_id: null
target: {target}
target_kind: {target_kind}
target_path: {target_path}
repo: {repo}
session_id: the current Claude Code session ID, resolved as below. Fill "" only after that has failed.
session_cwd: current working directory of this session (fill "" if not available)
what_happened: {what_happened}
what_expected: {what_expected}
correct_example: {correct_example}
source: "slash-capture"
urgency_hint: "normal" (set to "high" only if the user explicitly says it is urgent)
dedup_key: {dedup_key}
notes: []
resolution: null
Resolving session_id. Do not reach for "" first. The scratchpad directory
named in your system prompt carries the id in its path, which has the shape
.../{project-slug}/{session-id}/scratchpad, so the segment immediately before
scratchpad is the id. Confirm it rather than trusting the shape:
ls ~/.claude/projects/*/{session_id}.jsonl
A hit means the id is right and the transcript is on disk to be read later.
Record "" only when there is no scratchpad path to read from, or when nothing
matches.
This field is the only route from a queue entry back to the conversation that
produced it. The entry filed on 2026-08-07 against UserPromptSubmit carried
"", and working out what had actually failed took a full session of forensics
four days later, because there was no transcript to open and the surrounding
sessions had none of the failure in them. The id was sitting in the scratchpad
path the whole time. Treat this as required, not as a convenience field.
Then:
Get the current UTC time: date -u +"%Y-%m-%dT%H-%M-%S" for the filename, date -u +"%Y-%m-%dT%H:%M:%S.000Z" for created_at.
Build the filename: {YYYY-MM-DDTHH-MM-SS}-{slug(target)}.json
The id field MUST equal the filename stem (everything before .json).
Ensure the queue directory exists: mkdir -p ~/.claude/build-loop/queue
Write the composed entry to a scratch file with the Write tool, then hand it over. Do not write it into the queue directory yourself:
node "${CLAUDE_PLUGIN_ROOT}/scripts/queue.js" create {scratch}/{filename}
It re-checks the dedup_key inside the lock and writes only if nothing
matched, so the check and the write cannot be separated.
If Step 3 found a duplicate and the user said "write anyway", pass
--dedup-window 0, which skips the check. Without it the write is refused
for the exact duplicate they just approved, and the correction they asked to
keep is discarded. Exit 0 means it was
written. Exit 2 means a duplicate won the race and nothing was written: say so
and name the entry it printed, rather than retrying. Exit 1 is a real error
and the message is written to be read aloud.
Stop here unless it exited 0. Nothing below this line is true if the entry was not written.
In both cases do NOT go on to Step 4b and do NOT print the confirmation.
Dep-review entries carry parent_id pointing at the primary, so writing them
against an entry that does not exist leaves children with no parent, and the
Step 4c line would tell the user their correction was logged when it was
discarded. That is the worst failure this skill has, because the user has no
reason to check.
The old flow could not reach this state: the dedup decision happened before
the single Write, so there was no way to be refused after deciding to write.
create can refuse, so the branch has to exist.
Do NOT count here, and do NOT confirm here. Go straight to Step 4b. The count is taken in Step 4c, after the dep-review entries exist.
It used to be taken at this point, and every dep-review written afterwards made it wrong by one. The confirmation then reported a total and, in the next breath, announced N entries the total did not include.
After the primary entry is written in Step 4, flag anything the map says depends on it. This runs BEFORE the final confirmation message — the confirmation in Step 4 becomes a later step below (see Step 4c).
Read ~/.claude/build-loop/DEPS.json using the Read tool.
If the read fails (file missing, permission denied, or the content is not valid JSON):
Print: "⚠ DEPS.json missing or unreadable, skipping dep-review flagging. Run /audit-deps to fix." Jump to Step 4c with
dep_reviews_written: 0. Never block the primary write.
Build the composite key from the primary entry you just wrote, following the Composite Key Rule in SCHEMA-DEPS.md:
{repo}:{target}.plugin-repo, it is {repo}:{plugin}/{target}. Take the plugin segment from target_path, which is the directory under plugins/, not from the target name. The name alone cannot say which plugin it is in, and three of them ship a cli.Read the map from DEPS.json.targets. If that key is absent and DEPS.json.skills is present, use skills instead, treating each entry's skill field as target and a missing kind as "skill". That is a v1 map, per SCHEMA-DEPS.md. Reading only targets against a v1 map finds nothing, reports every dependency as absent, and silently skips the dep-review flagging that is the whole point of this step.
If the exact key is absent, work down this list before giving up. A lookup that quietly finds nothing is indistinguishable from a target that genuinely has no dependents, so exhaust the fallbacks first and then say which one matched.
a. The bare key, {repo}:{target}. A map written before v3 stored plugin-repo entries under a plain name, plugins:hook-io rather than plugins:guardrails/hook-io. Step b cannot find those, because hook-io does not end with /hook-io. Without this step every pre-v3 map goes silent the moment this version is installed.
On a match here, add this to the confirmation in Step 4c:
Note: DEPS.json predates v3, so this matched on name alone. If more than one plugin has a {target}, the entry may describe a different one. Run /audit-deps to rebuild the keys.
A pre-v3 map is the file where plugins:cli meant three different things, so the entry may belong to another plugin. Using it beats going silent, and calling it exact would be wrong.
b. A suffix match on /{target}. The mirror of a: a bare lookup against a map that is already qualified.
dep_reviews_written: 0. Picking one sends a review to the wrong plugin, which is the exact failure the key format exists to stop.c. Nothing matched. There is no entry, which is the case handled below.
If the key is NOT in the map:
Print: "⚠ {target} not in DEPS.json, skipping dep-review flagging. Run /audit-deps to add it." Jump to Step 4c with
dep_reviews_written: 0.
If the key IS present, look at its dependents. If the array is empty, jump to Step 4c with dep_reviews_written: 0 — there's nothing to flag, which is the common case.
For every { target: X, plugin: P, kind: K, repo: R, reason: Y, confidence?: low } in the dependents array. An edge written before schema v5 carries skill instead of target and has no kind, so read X from target if present and skill otherwise, and default K to skill:
X is bare and stays bare. P is a separate field naming the plugin, and it is only there under a plugin-repo root. Use {R}:{P}/{X} when you need the edge's key in DEPS.json, and use X on its own everywhere the dep-review entry is concerned.
Never write {P}/{X} into the entry's target. A queue entry's target is a name on disk that /apply-fix and /list-bugs later have to resolve to a file, and nothing on disk is called guardrails/hook-io. If an edge does carry a slashed target, which a map written before this rule may, split it: the part before the last / is P and the part after is X.
The id, the filename, and the dedup_key want the opposite. Those exist to be unique, and a bare name is not. One fix to something that guardrails/cli and slop-check/cli both depend on produces two dependents with the same bare name, and then:
dedup_key, so the dedup check in step 3 skips the secondEither way one review survives and the other disappears without a word, which is the failure this whole map exists to prevent, happening inside the thing meant to prevent it.
So fold P in wherever the value is an identifier, and leave it out wherever the value is a name that has to resolve:
| value | with a plugin | without |
|---|---|---|
target | {X} | {X} |
id and filename | {ts}-dep-review-{slug(P)}-{slug(X)} | {ts}-dep-review-{slug(X)} |
dedup_key | dep-review::{P}/{X}::{parent id} | dep-review::{X}::{parent id} |
Compute urgency_hint (Claude's judgment — this is NOT a rule engine):
"high"."low".Compute the dep-review dedup key: dep-review::{P}/{X}::{primary entry's id} when P is present, otherwise dep-review::{X}::{primary entry's id}. The plugin belongs here. Without it, two dependents called cli in different plugins produce one key, and the second is skipped as a duplicate of the first.
Dedup: not a separate step any more. Step 5 passes --dedup-window all,
which makes queue.js refuse any entry whose dedup_key already exists at
any age. Unlike primary dedup, dep-review dedup has no expiry: one parent and
one dependent is one logical review, forever, not one every ten minutes.
Build the dep-review entry (all fields per SCHEMA.md v5):
$schema_version: 5
id: {primary timestamp}-dep-review-{slug(P)}-{slug(X)}, or -dep-review-{slug(X)} where there is no P
created_at: {same as primary entry's created_at}
status: "Open"
type: "dep-review"
parent_id: {primary entry's id}
target: {X} <- bare. Never {P}/{X}.
target_kind: {K}
target_path: {DEPS.json entry's path value}
repo: {R}
session_id: {same as primary entry's session_id}
session_cwd: {same as primary entry's session_cwd}
what_happened: "Review: {X} may be affected by fix to {primary target}. Reason: {Y}"
what_expected: "(not applicable: this is a dependency review)"
correct_example: "(not applicable)"
source: "dep-review-auto"
urgency_hint: {computed above}
dedup_key: dep-review::{P}/{X}::{primary entry's id}, or dep-review::{X}::{...} where there is no P
notes: []
resolution: null
Write the entry. Compose it to a scratch file with the Write tool, then:
node "${CLAUDE_PLUGIN_ROOT}/scripts/queue.js" create {scratch}/{id}.json --dedup-window all
The filename it lands under is the id with .json appended, so
{primary timestamp}-dep-review-{slug(P)}-{slug(X)}.json where there is a
plugin. queue.js derives it from the id field, which is what keeps the two
from drifting apart: an entry whose filename and id disagree cannot be found
by its own identifier.
Exit 2 means this review already exists, which is not an error. Exit 1 is:
report the failure for that dependent and carry on with the remaining ones,
per the failure handling at the end of this step. Neither counts toward
dep_reviews_written, so step 6 runs only after an exit 0.
Increment dep_reviews_written.
The confirmation message from the current Step 4 is REPLACED. Instead of "Logged to {filename}. Queue now has N open items.", use this rule.
Take the count now, after every write above has landed:
node "${CLAUDE_PLUGIN_ROOT}/scripts/queue.js" count
Count statuses, never files. This used to be ls queue/*.json | wc -l,
which counts every entry ever written. A resolved entry stays in the same
directory with its status changed, so that number only ever grows: on
2026-08-09 it reported 85 open items against 19 that were actually open, the
other 66 being resolved or closed. Reporting it as "open" made a queue with
seven live bugs in it look abandoned, which is the opposite of what the number
is for.
And take it here rather than before Step 4b. It used to run right after the primary entry was written, so every dep-review written afterwards left it short by one. The message then gave a total and immediately announced N entries that total did not include, which is a plainer contradiction than the one this replaced, because both halves are on screen at once.
{count} is the line that command printed, repeated as it came. Do not
restate part of it as a total of your own. The fault this replaced was a
number presented as "open items" that was not one, and quoting half of a correct
line reintroduces it in a smaller way.
If dep_reviews_written == 0:
"Logged to
{filename}. Queue: {count}."
If dep_reviews_written > 0:
"Logged to
{filename}. Queue: {count}." "Also flagged {dep_reviews_written} dep-review {entr(y|ies)}: {comma-separated target names}."
Pluralization: use "entry" when dep_reviews_written == 1, "entries" otherwise.
If ANY dep-review write fails (exit 1 from queue.js, or the Write tool erroring on the scratch file), continue with the remaining dependents and note the failure in the confirmation. An exit 2 is a duplicate rather than a failure, so it is not counted here:
"Flagged {K} of {total} dep-reviews. {total - K} failed to write. Check the queue directory manually."
The primary entry write is never rolled back because a dep-review write failed. The primary is the source of truth; dep-reviews are convenience.
If the Write tool fails for any reason, tell the user exactly what failed. Do NOT retry silently. They may want to fix the root cause before retrying.
If the user declines to answer a clarifying question, record the missing field as "(not provided)" and still write the entry. A partial entry is better than a lost correction. Flag this in the confirmation message:
"Logged with missing {field}. You can edit the file later at
{path}."
target_path is the exception, and it is not a partial entry, it is a blocked
one. With no path there is nothing to infer repo from, so the entry lands as
repo: "unknown", and /apply-fix refuses that outright. The correction is
recorded and can never be started by anything. Say that before writing, rather
than after:
"Without a file path this cannot be started.
/apply-fixrefuses an entry whose repo is unknown, and the repo is worked out from the path, so with no path there is nothing to work it out from. Log it anyway, or name the file?"
Answering with a real path is the whole remedy, as long as it sits under a
configured root: the target_path resolution in Step 1 sets repo from the
root it matched. A path outside every root still leaves repo: "unknown", so
say so at that point rather than letting them believe the question is settled.
If they choose to log it anyway, the confirmation names what it is, and names the field that actually unblocks it:
"Logged as blocked.
/apply-fixrefuses it untilrepois set at{path}. Filling intarget_pathalone will not clear it, becauserepois worked out once, when the entry is written, and nothing recomputes it afterwards."
Say repo, not target_path. The guard in /apply-fix reads repo and
nothing else, and the Repo Attribution Rule in SCHEMA.md infers repo from the
path at capture time only. Sending somebody to type a path into an entry that
already exists points them at the one field that will not move the guard, and
they find out when the fix command refuses them a second time, for the same
reason as the first. That is this bullet's own failure happening one level
down, and it is how the wrong wording got written: it was corrected to name the
blockage and never checked for whether it named the remedy.
The old wording, "Logged with missing field, you can edit the file later", is
what let the 2026-08-07 UserPromptSubmit entry read as a minor gap. It sat
unworkable for four days because nothing in the confirmation said it could not
be worked at all.
If repo ends up as "unknown", add a note in the notes array:
{"ts": "{created_at}", "text": "repo unknown: target_path {target_path} is outside both known roots. Resolve before Phase 3 can apply the fix."}
If DEPS.json cannot be read in Step 4b, NEVER block the primary confirmation. The primary entry is the source of truth. Dep-review is best-effort.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub sarahcallmesmadds/infra-plugins --plugin build-loop11 skills in this plugin
/apply-fixApplies a correction from the bug queue to an actual target file. Reads the queue entry, checks DEPS.json for dependents, reasons about the surgical fix, shows a plain-language before/after diff, waits for the user's approval (yes / no / retry), then writes the fix, commits to the correct repo, and updates the queue entry status to "fix applied, watching" with the commit hash stored. Never writes without explicit approval./audit-depsScans every configured root (skills, hooks, commands), compares what is on disk to DEPS.json at ~/.claude/build-loop/, and surfaces missing (on disk but not in the map), orphaned (in the map but not on disk), or changed (the file is newer than its DEPS.json entry's last_updated) entries. Use when you've added or renamed a skill, hook, or command, or when DEPS.json is flagged as stale. Shows a draft of proposed changes and asks y/edit/skip before writing — never silent writes.Other plugins' skills for the same job
/built-check