Hardware in the loop
You are setting up (or running) a hardware project where agents do the engineering and gates prove it. Read this
whole file before acting. This is a starting point the project grows into its own harness, not a finished
product: adapt every template to the project, and say so to the owner when something here does not fit. The method is described in the repository's docs/ (METHOD, PCB, CAD, FIRMWARE, SIM, SWARM,
TOOLS, LESSONS); this file is the procedure.
0. Say the cost first
Before anything else, tell the user, plainly:
Running this method with a swarm of agents is expensive. On the project it comes from, one swarm day burned 4-5 million tokens, mostly by waking lane agents that each carried 300-800k tokens of context. Three modes:
- chain (recommended): one long lead session (Fable or Opus) hands bounded cards to one or two subagents at a time (Opus or Sonnet), takes the reports, then goes on. The logs and trial and error stay out of the lead's context.
- single: one session, no subagents, cheapest on small projects.
- swarm: a lead plus parallel lanes, fastest wall-clock, by far the most expensive. Which mode do you want? (recommended: chain)
Record the answer as mode (chain, single or swarm). A subagent or two on bounded cards is not a swarm: in chain
mode that is the normal way to work. Do not run a lead with parallel lanes before the user chose swarm mode.
1. Onboarding interview
Run the interview in references/interview.md through the question dialog: batches of at most four questions, the
recommended default first in every question. When a question gets no answer, take the default and write
"default taken" next to it. Cover: project goal and definition of done, goals in order, budget, quantities, default
printed material (carbon-fibre nylon / PETG / PLA / machined aluminium), fastening (heat-set inserts / thread-forming /
through-bolts), enclosure (sealed / vented / open), mechanical clearance, PCB fab and assembly vendor, MCU family, main
supply and worst transient, board class and coating, simulation tiers (native twin / Isaac Sim / Unreal) and the GPU,
machine limits (CPU cap default 90 %, RAM kept free for the system default 4 GB, free-disk floor default 50 GB),
archive location, the web CAD viewer (copy it into the project, default yes), usage tripwire (default 95 %), standing decisions.
Then batch 6 (the build spec: environment, temperature range, IP rating and cooling, standards such as IPC class or MIL-STD-810H / 461G, wire such as SAE AS22759 "Tefzel", EMC, vibration, derating headroom) and batch 7 (how the owner likes to work: long sims detached in the background at below-normal priority or only overnight, engines only when they say, how results reach them, what happens to questions while they are away). Also ask:
- the firmware language, recommending C (say why: the same core compiles for the board and the twin; Python stays for tools, CAD and the Isaac harness);
- the twin tiers, recommending native twin + Unreal 5.8.4+ when there is a GPU (Isaac Sim when the team knows it);
- the storage layout, recommending the repo on an NVMe / SSD and
.archivelinked to the biggest disk; - whether the team already describes boards in a board-as-code tool (SKiDL, atopile, circuit-synth). If it does, keep that tool for the netlist and put this method's gates after it (KiCad ERC / DRC, live part checks, the fab set); if not, use the Python generator pipeline of the skeleton. Do not argue tools: the gates are the point.
Materials, fastening, enclosure sealing, clearance and the build spec are PROJECT DECISIONS: never pick them silently; ask, recommend, record.
Write the answers to answers.json in the target repository's .tmp/ (schema in references/interview.md).
Every answer and every default taken becomes a numbered row of DECISIONS.md (the scaffold writes the first ones).
2. Generate the skeleton
python -I <skill>/scripts/scaffold.py --answers <repo>/.tmp/answers.json --dest <repo> [--with-examples] [--dry-run]
It copies templates/ (README_AGENT.md, PROJECT_STRUCTURE.md, REQUIREMENTS.md, README.md, CODING_RULES.md,
.gitignore, .gitattributes, windows/ci.ps1 + windows/ci/ (groups audit and pcb), windows/cad_viewer.ps1, tools/ (audit +
portability with an empty tracked baseline and waiver file; tools/cad_viewer/, the web CAD viewer, unless the interview said no), pcb/ (DESIGN_STANDARDS.md, tools/kicad_env.py,
tools/board_pipeline.py, tools/distributor_verify.py, tools/route_board.py + pf_route.py + astar.c, the negotiated router), cad/ (cad_plugins.py, render.py, mass_cg_table.py),
firmware/host_tests/hil_check.h, docs/bench/BENCH_REGISTER.md, docs/data/README.md, harness/swarm/ (AGENT_RULES,
slot / detach / watch / merge lock / merge-to-dev / promote / WIP backup / handoff hook / status line scripts) and
.claude/settings.local.json (status line + PostToolUse hook)), fills the template variables, writes
harness/swarm/machine.env and harness/swarm/PLAN.md for the chosen mode. It never overwrites an existing file;
compare kept files by hand and merge what is useful. --with-examples adds the example board (a 2-layer 3.3 V LDO
breakout that runs every pipeline step) and the example enclosure builder with two plug-ins.
It also writes the digital twin (sim/twin/: models, plant, C ABI, runner, scenarios, CUDA sweep, tools), the
firmware core (firmware/core/), sim/unreal/ when the tiers name Unreal, sim/isaac/ when they name Isaac,
DECISIONS.md, QUESTIONS.md, CITATION.md, tools/check_citations.py, tools/archive_tmp.py, tools/hil_update.py
and the version stamp harness/TEMPLATE_VERSION.json (section 8c).
Then fill the decision table in pcb/DESIGN_STANDARDS.md section 0 from the answers, and make the archive link
(mklink /J .archive "<archive path>" on Windows, ln -s <archive path> .archive elsewhere; ask first).
3. Tools
pwsh -File <skill>/scripts/setup_tools.ps1 -ToolsRoot <a folder outside the user profile> [-VerifyOnly] bash <skill>/scripts/setup_tools.sh --tools-root <dir> [--verify-only] # Linux
KiCad 10 (winget), Java 21 (winget), Freerouting 2.1.0 (pinned SHA-256), OSS CAD Suite 2026-10-24 (pinned SHA-256,
only for FPGA projects), a CadQuery venv. It writes <ToolsRoot>/hil_tools.env with HIL_FREEROUTING_JAR,
HIL_JAVA, HIL_KICAD_CLI, HIL_CQ_PYTHON. Ask before installing anything machine-wide; run -VerifyOnly first and
show the user what is missing. Nothing goes into the user profile.
For the twin tiers: pwsh -File <skill>/scripts/check_twin_tools.ps1 finds (never installs) CMake, a compiler,
Ninja, Python, Unreal Engine >= 5.8.4, an Isaac Sim Python, the NVIDIA driver and nvcc, with the install hint for
each missing one. Installing Unreal, Visual Studio, Isaac Sim or CUDA is machine-wide: show the report and ask.
4. Git: main and dev
In the target repository (ask before running git in a repository that already has history):
git init -b main # when it is not a repository yet git add -A && git commit -m "Project skeleton (hardware-in-the-loop method)" git branch dev git push -u origin main dev # when a remote exists
Use the machine's configured git identity. No attribution lines or co-author trailers. Never force-push. Then run the first CI pass and keep its report as the main reference:
pwsh -File windows/ci.ps1 -Only audit pwsh -File windows/ci.ps1 -Only twin # the native twin: build, host suites, scenarios, determinism, ABI
5. Arm the harness
.claude/settings.local.jsonwiresusage_statusline.py(status line, tripwire atHIL_HANDOFF_PCT) andhandoff_hook.sh(PostToolUse). Prove the hook:touch harness/swarm/HANDOFF_SELFTEST, run any tool, expect the "hook is live" context, delete the file.- Start the WIP backup detached:
bash harness/swarm/detach.sh harness/swarm/wip_backup.sh .tmp/wip_backup.log. - Check
bash harness/swarm/locks/slot.sh status. - The lead session runs from the main checkout (that is where
harness/lives); edits happen in worktrees.
6. Working: chain mode (default)
Follow harness/swarm/PLAN.md (from references/chain-plan.md) and docs/SWARM.md section 6:
- The lead owns the plan, the decisions and the owner. It does small jobs itself, a handful of tool calls.
- A job that would fill the lead's context with logs and file dumps goes to a subagent as ONE bounded card: one outcome, what to read, acceptance numbers, what to leave alone, a report file. Opus for subtle cards, Sonnet for mechanical ones.
- Run one or two at a time. Start a second only when the two cards touch different files and will not both need the heavy machine slots. The lead takes each report, spot-checks a number from it, then lands the card.
- A fresh agent per card. Never wake an old agent with a large context to ask it a small thing.
- Long machine jobs, questions and stopping work as in single-session mode below.
6b. Working: single-session mode
Follow harness/swarm/PLAN.md (from references/single-session-plan.md):
- One numbered step at a time, each with the gate that proves it.
- Work in
.claude/worktrees/main-workonswarm/main-work; commit, push,merge_to_dev.shafter every green gate. - Heavy jobs:
eval "$(bash harness/swarm/locks/slot.sh take <kind> <you> "<job>" <GB>)", release after. - Long jobs:
bash harness/swarm/detach.sh <chain.sh> <log>and immediatelybash harness/swarm/watch.sh <log>as a background task; continue with the next step while it runs. - Owner questions: batched, recommended default first; defaults taken are written into the plan.
- Stopping: append "## Where I stopped" (done with SHAs, running jobs with PIDs and logs, exact next step).
When an auto-router or auto-placer gets stuck, in any mode, stop it and look: docs/PCB.md, "When the router gets
stuck". Render the board with pcb/tools/place_view.py, read the picture, place by hand, then route again. A board Freerouting
leaves open because it is dense, not because the placement is wrong, goes to the negotiated router: docs/PCB.md, section 3b.
Lay a board out as named stages, not as whatever fits: a stage table before placement, one region per stage, parts beside the pins they serve, a box and title on silk for each stage. A subagent may get a rough first pass down, but no board routes or lands until a reviewer who is not its author has checked every part against the stages. docs/PCB.md, "Stages". Follow this as far as you can, not rigidly: a part that doesn't fit or a small add-on fix gets noted as an exception, and the board isn't redone for it. For each real stage, search published circuits before fixing the topology and compare them on cost, thermal, voltage and the like: that gets past the knowledge cutoff, and a published circuit is a floor, never a ceiling. A board that passes every check and can't be read isn't finished.
7. Working: swarm mode
Follow docs/SWARM.md of the method repository (not copied by the scaffold) and references/wave-checklist.md:
- Wave 1, recon: read-only agents write verified facts with file:line anchors to
harness/swarm/recon_<area>.md. - Wave 2, plan:
PLAN.md(references/plan-template.md) with lanes, one owner per file (cross-lane changes as patch files inharness/swarm/handoff/), interface additions, acceptance numbers;briefs.mdwith one brief per lane (references/brief-template.md). - Wave 3, lanes in worktrees
swarm/<name>: Sonnet for mechanical work (ports, codecs, renders, tests, docs), Opus for subtle work (control, physics, geometry, signal integrity). Each returns the structured report (references/structured-report.md). - Wave 4, skeptics: fresh agents with the diff and the report only;
audit_placeholders.py --changed-since origin/dev --fail-on-new, the lane's CI groups, three numbers re-checked. - Wave 5, integration: every lane lands on dev with
merge_to_dev.sh(always, red included, under MERGE_LOCK); full CI on dev with-Compare <main report> -FailOn regressions;promote_dev.shonly with zero regressions.
Keep lanes few and briefs exact; every wake-up of a big-context agent costs real money.
7b. The digital twin (both modes)
Follow references/twin-setup.md. In short:
- Run the example twin as shipped;
ci.ps1 -Only twinGREEN proves the toolchain. - Move the product's control code into
firmware/core(C, HAL only;references/firmware-host.mdfor ESP32, ESP32-P4, STM32, RP2040, nRF, Arduino), grow its host suites. - Research each physical effect the scenarios need (
references/research-citations.md): datasheet, standard, textbook, paper; open and verify every source; aCITATION.mdrow and a[REF-nnn]tag per model. - Replace the example plant with the product's, reusing the models; mass properties from the CAD through
sim/twin/tools/cad_to_twin.py, never typed. - Scenarios for the task, every fault the firmware must survive and the build-spec corners, limits from
REQUIREMENTS.md/DECISIONS.md; rows inMATRIX.txt(the first row is the determinism / parity row); seeds in CI, 40 at night (ci.ps1 -Only twin_scenarios -TwinSeeds 40). - Host it: Unreal (recommended; kinematic replay is hash-identical to the native runner, Chaos torque coupling for
contact) or Isaac Sim (behind
sim/isaac/gpu_gate.py). Engines start only when the owner agreed or overnight. - Margins: Monte Carlo over per-unit tolerances (
sim/twin/gpu/, CPU reference, CUDA optional). - Bench: every constant that matters gets a BENCH row and a bench-versus-twin comparison when hardware exists.
7c. Records the agents keep
DECISIONS.md: read first; never re-ask a decision; a change is a new row that supersedes an old one.QUESTIONS.md: every question for the owner, with options, the recommended default first, what it blocks and when the default will be taken; closed questions become decisions.CITATION.md: every model, constant and algorithm with a verified source (ci.ps1 -Only citations)..archive/: results leave.tmp/only throughtools/archive_tmp.py(hash-checked, with a manifest).
7d. Looking at the CAD (the viewer)
The scaffold copies the web CAD viewer to tools/cad_viewer/ and its launcher to windows/cad_viewer.ps1; it is a
template, so the project owns its copy and fixes go back into the skill. Use it whenever someone must look at a build:
after a CAD change lands, before a fit decision, when the owner asks "can I see it".
- Fill
tools/cad_viewer/viewer.config.jsononce: the part-to-.kicad_pcbmap, the parts to skip, material rules, the wire name pattern. Check it withpython tools/cad_viewer/viewer_config.py. Nothing else in the viewer is project-specific. pwsh -File windows/cad_viewer.ps1 pack <build dir> "<label>"then... start. The build dir is what the builder writes (parts.json+stl/); seetools/cad_viewer/README.md.- Board pictures are optional:
render_boards.py(KiCad 10, Pillow) thenpack ... --boards <dir>. A mesh-only build needs neither and still comes up. Section planes step 0.1 mm (Shift 1 mm, Alt 0.01); PCB X-ray and Wire X-ray isolate boards and wires. - Notes the owner pins land in
docs/cad_feedback/notes.jsonl: read them before the next build and answer each.
8. Discipline (both modes)
- PCB: generator-first (
docs/PCB.md). ERC 0/0, DRC 0 violations / 0 unconnected / 0 parity at default severities (with planes refilled, on the first routed board too; high-voltage nets get their own router clearance,docs/LESSONS.md44), every purchased line verified live, fab set + STEP + results JSON with SHA-256s. Hand placement by you is expected when the auto-placer fails. More layers are allowed; report the price delta. Relaxing a rule needs a cited basis. - CAD: builders + plug-ins; a mass / station / CG table (
cad/mass_cg_table.py) with every part change; fit and clash PNGs (cad/render.py) indocs/cad_decisions/<date>/<topic>/; a clearance check for a moving part uses exact solids (lift in steps, intersect, report overlap volume) and has its own results row, never sampled surface points (docs/LESSONS.md43). - Firmware: C (no interpreter in shipped firmware), out-of-tree builds, host suites with
hil_check.h, scenarios through the real interface, seed sweeps, determinism; hardware-pending listed. - Twin: every model cited and tested against a closed form; no Python physics; the same seed gives the same trace.
- No unfinished work shown as finished; bench-only constants get
BENCH B-xx-nnids. - Machine: slots, below-normal priority, timeouts, never kill what you did not start, never
findor recurse from a drive root (search only named project or tool folders), check disk first, one Unreal / GPU job at a time, GPU only through the gate withHIL_GPU=1for that job, no engine launch while the owner is at the machine unless agreed.
8b. Before anything real is ordered
Green gates are necessary, not sufficient. Before a board, a part or a print is ordered: walk the owner through the CAD renders and the board (layout, stack-up, BOM with the ratings), answer "why" for every part and number with the datasheet line or decision behind it, and run an adversarial review pass: fresh agents get the files (schematic, board, BOM, CAD exports, firmware diff, twin results), not your conclusions, and hunt for what the gates do not check. Findings go into the report; the owner decides the order. Keep it friendly and brief; the point is a second pair of eyes, not a ceremony.
8c. Versions and updates
VERSION and CHANGELOG.md in this folder are the method's version. The scaffold stamps every project with it
(harness/TEMPLATE_VERSION.json: version, options chosen, a hash per template file) and copies tools/hil_update.py;
the SessionStart hook in .claude/settings.local.json runs its check, which compares against main of
https://github.com/Kemerd/claude-hardware-in-the-loop and, when upstream is ahead, shows the changelog entries in
between. Many owners never use this skill again after the scaffold and customise every template, so updating works
from the project alone and never overwrites a file the project changed: check -> ask the owner -> plan ->
apply -> merge the diffs by hand -> mark (procedure in the project's README_AGENT.md section 7).
A project from before versions: python -I tools/hil_update.py adopt.
When you change anything under skills/hardware-in-the-loop/ in the method repository itself: bump VERSION
(patch for fixes, minor for new tools or better prompts, major for changes that need a migration) and add a
CHANGELOG.md section above the others, in plain words for the project owner: what improves, not which files moved.
Keep the four path tables at the top of templates/tools/hil_update.py in step with scripts/scaffold.py.
9. Handoff and overnight
- When
HANDOFF_NOWappears (the hook tells you), stop starting work and follow its instruction: commit, push, release, writeharness/swarm/resume_<date>/RESUME_<date_time>_<lane>.md(references/resume-doc.md). - Before the owner leaves for the night: a detached night chain and the morning questions
(
references/overnight-questions.md). The night runs on the defaults; record every default taken.


