The agent loop

Every coach, at the step where it acts

One turn of Claude Code, from session start to session end, with all 11 coaches, the engine's 12 hook bindings, 29 skills, 6 agents and 4 commands placed where they enter it. Drag to move, ctrl + wheel to zoom. Read it as text ↓

Columns are the loop's steps; rows are the plugins. A chip's outline and mark say how it enters, the numbered circles are the special cases, and the panels at the bottom list where it asks and what it writes.
drag or wheel to move · ctrl+wheel to zoom · double-click fits
How a turn runs with AI CoachEvery plugin at the step of the loopwhere it acts.you type ita command you typeClaude calls ita subagenta hook: it just runskept between sessionsStroke and mark show how it enters.Session startstartup · resume · clear ·compactHook context reaches themodel before the firstprompt.Your promptUserPromptSubmit: hooks add context beside it.A /plugin:skill you type loads that skill.A systemMessage reaches only you.Model turnAnswers in text, or calls tools: Skill, Agent, Read,Edit, Bash, WebFetch, Artifact.11 skill descriptions are always in context.Pre-toolPreToolUse runs beforeevery call, permission ornot.deny > defer > ask >allow.PermissionDeny and askrules stillapply.A hook's askshows here.Tool runsSkill: its body loads.Agent: a subagent runs its own loop in its own contextand returns only its report.Its tool calls fire the same hooks.Post-toolThe result returns to themodel.PostToolUse can addcontext; it can't undo thecall.A failure firesPostToolUseFailure.Turn ends ·NotificationNo tool call: the turnends and waits for you.Notification: a permissionprompt (~6 s) or idle (~60s). Can't block.CompactionPreCompact, then thecontext is summarized.The session resumes asSessionStart:compact.Session endSessionEnd: the last hookbefore the process exits.Across sessionsWhat this session leavesfor the next one, and forteammates.next session: the brief is read backcompaction resumes as SessionStart:compactthe result returns: the loopno tool call: the turn ends and waits for youai-coach-coreThe engine. Hooks and memory; runs withoutbeing asked.ai-coach (bundle)Three commands that tie the coachestogether.memory-coachSearch memory, publish conclusions, handthem to a teammate.investigation-coachOnboarding docs, architecture maps, studymaterial.strategy-coachThe business as a vault, and featurespecs.analysis-coachRequirements, critiqued analysis,executive write-ups.atlas-coachEverything outside the repo: research,ingestion, markets.security-coachInjection scans, OWASP audits, pentesttriage.prompt-coachPrompts that land, and briefs for asubagent.harness-coachWhat is installed, and what fills thissession.design-coachPublished pages made checkable, lintedbefore publish.pair-coachTalk to Claude through @claude comments inthe code.ship-coachCommit, branch and PR on Haiku, after onelook.--run chains--with-blueprintchains--tourspawnsspawns--prior-artspawnsspawnsgates claimsspawnsquarantinesexportslearnssession-start.jsinjects the briefbrief ≤ 4,000 charssettable 500–16,000compact: 1,000 + snapshotbranch/seed/partner nudgesprompt.jsrecords · hints to youskips < 25 chars, / and !hints: systemMessage onlynever shown to the modelplan mode: a Haiku reviewguard.jsblocks or asks: secretsoff by defaultblocks real credentialsasks: secret out, key readonly hook that can blockobserve.jsrecords the actionEdit · Write · Bash<private> stripped firstspotlight.jswarns: injectionWebFetch, WebSearch, ReadRead outside the repo onlyin full once per sessionnever blocksobserve.js · FAILrecords the failurefeeds the snapshotand the distillationnotice.jsrecords a correctionon error, failed, wrong…prints nothingprecompact.jssaves where you werebranch, ≤ 8 files touchedlast fail, ≤ 3 correctionshanded back once, deletedsession-end.jsdistils on Haiku≤ 3 learnings, 'distilled'AICOACH_LEARN=off skips itprunes at 30 and 90 daysnever exports a seed~/.ai-coachyour memory databasenext session's briefsurvives uninstalling/startday one, --run chains/wrapone question, publish/sitrepread-only morning readrecallsearches memorydebriefpublishes conclusionshandoffexports the team seedrosterwho is on the teamteam-seed.jsonlcarried by gitteammates import itnothing leaves on its own/investigateall three, in orderonboardonboarding docsmapmaps → artifact-stylestudystudy materialscout · sonnetread-only repo sweepRead · Grep · Glob · Bash≤ 500 words, file:linefeaturespec, then planblueprintthe business vaultelicitrequirementsinsightanalysis, critiquedstoryexecutive write-upcriticunanchored reviewRead · Grep · Glob · Bashnever sees the reasoningresearchverified web researchmarketcompetitor analysisingestdocs in · Haikutranslatedocs to coderesearcher · sonnetcited briefWebFetch · WebSearch≤ 600 words, UNVERIFIEDverifiertries to refuteWebFetch · WebSearchreader · haikuPDF, 20 pages a callRead · Write · Bashscaninjection scan · HaikuauditOWASP audit · Haikutriagepentest report · Haikuexaminerquarantine readerRead · Grep onlyno shell, no networkprompta prompt that landsscopeshape a big askprompt-statshabits that cost youdispatchbrief a subagentcontextwhat fills the sessionpartnerspartner tools · Haikuartifact-stylecheckable pagesartifact-lint.jsasks on lint errorsArtifact .html publishnever deniesartifact-nudge.jsloads artifact-styleafter native design skillsmentions-nudge.jsnames open threadsyour uncommitted lines≤ 5 locationspair1–3 stubs for youmentionsanswers @claude inlinecommitHaiku · low effort123456789Where it stops to askguard.jsasks before a secret-looking payload leaves, or a credential file is read/ai-coach:startsays what --run costs, once, and asks/ai-coach:wrapone question for every identity gap/memory-coach:debriefshows the draft, then publishes/memory-coach:handoffexports only on a yes/memory-coach:rosterasks for your role/investigation-coach:onboardstates the cost before starting/strategy-coach:featureno plan.md until you answer/strategy-coach:blueprintyou correct the domain first/atlas-coach:ingeststops on a spotlight warning/security-coach:audit--triage asks before recording/prompt-coach:scopeany FAIL stops the walk/harness-coach:partnersinstalls only what you pickartifact-lint.jsasks before a page that fails the lint is published/pair-coach:mentionsasks about lines someone else committed/ship-coach:commitone look at the whole planWhere it writessession-start.jsthe session rowprompt.jsfirst prompt (scrubbed), signal idsobserve.jsone observation per actionobserve.js · FAILa FAIL observationnotice.jsa correctionprecompact.jsa working-state snapshotsession-end.jsa summary and up to 3 learnings/memory-coach:debriefa debrief/memory-coach:handoff.ai-coach/team-seed.jsonl/memory-coach:roster.ai-coach/team.md/investigation-coach:onboarddocs/onboarding//investigation-coach:mapdocs/onboarding/components/, an Artifact/investigation-coach:studydocs/study//strategy-coach:featuredocs/features/<slug>//strategy-coach:blueprintdocs/business/, an Artifact/analysis-coach:elicitdocs/requirements//analysis-coach:insightdocs/analysis//atlas-coach:researchresearch/<slug>.md/atlas-coach:marketdocs/market//atlas-coach:ingestdocs/<slug>.md/security-coach:auditfindings/security-coach:triagefindings, .ai-coach/security//design-coach:artifact-stylean Artifact page/pair-coach:paircode, tests, stubs that throw/pair-coach:mentionsreplies and changes in the code/ship-coach:commita commit, a branch, a PRSpecial cases1Every hook fails open: a crash is logged and the session goes on. Only guard.js can stop a call.2The engine's own claude -p runs set AICOACH_INNER, so every hook skips them: no recursion.3Hook context goes to the model. Prompt hints go only to you, as a systemMessage.4Inside a subagent, every tool call still passes guard, observe and spotlight; the parent gets only the report.5Anything between <private> tags is stripped before a single byte is written.6What a model wrote is stamped distilled, and nothing ever promotes it to a person's word.7Nothing leaves your machine on its own: the seed is exported only when you say yes.8Small models where a summary is the job: distillation, plan review, commit, reader, and skills pinned to Haiku.9AI Coach binds no Stop, SubagentStart or SubagentStop hook: a turn always ends when Claude is done.

The same map, as text

The loop, step by step

  1. Session start. startup · resume · clear · compact Hook context reaches the model before the first prompt. Claude Code docs
  2. Your prompt. UserPromptSubmit: hooks add context beside it. A /plugin:skill you type loads that skill. A systemMessage reaches only you. Claude Code docs
  3. Model turn. Answers in text, or calls tools: Skill, Agent, Read, Edit, Bash, WebFetch, Artifact. 11 skill descriptions are always in context. Claude Code docs
  4. Pre-tool. PreToolUse runs before every call, permission or not. deny > defer > ask > allow. Claude Code docs
    • guard.js (ai-coach-core): blocks or asks: secrets. off by default; blocks real credentials; asks: secret out, key read; only hook that can block. Asks: asks before a secret-looking payload leaves, or a credential file is read. plugins/ai-coach-core/hooks/guard.js:44
    • artifact-lint.js (design-coach): asks on lint errors. Artifact .html publish; never denies. Asks: asks before a page that fails the lint is published. plugins/design-coach/hooks/artifact-lint.js:29
  5. Permission. Deny and ask rules still apply. A hook's ask shows here. Claude Code docs
  6. Tool runs. Skill: its body loads. Agent: a subagent runs its own loop in its own context and returns only its report. Its tool calls fire the same hooks. Claude Code docs
  7. Post-tool. The result returns to the model. PostToolUse can add context; it can't undo the call. A failure fires PostToolUseFailure. Claude Code docs
  8. Turn ends · Notification. No tool call: the turn ends and waits for you. Notification: a permission prompt (~6 s) or idle (~60 s). Can't block. Claude Code docs
  9. Compaction. PreCompact, then the context is summarized. The session resumes as SessionStart:compact. Claude Code docs
    • precompact.js (ai-coach-core): saves where you were. branch, ≤ 8 files touched; last fail, ≤ 3 corrections; handed back once, deleted. Writes: a working-state snapshot. plugins/ai-coach-core/hooks/engine.js:1546
  10. Session end. SessionEnd: the last hook before the process exits. Claude Code docs
    • session-end.js (ai-coach-core): distils on Haiku. ≤ 3 learnings, 'distilled'; AICOACH_LEARN=off skips it; prunes at 30 and 90 days; never exports a seed. Writes: a summary and up to 3 learnings. plugins/ai-coach-core/hooks/session-end.js:37
  11. Across sessions. What this session leaves for the next one, and for teammates. README.md

Every coach, beside its skills

ai-coach-core

The engine. Hooks and memory; runs without being asked. a hook: it just runs, kept between sessions.

  • session-start.js (fires at session start): injects the brief. brief ≤ 4,000 chars; settable 500–16,000; compact: 1,000 + snapshot; branch/seed/partner nudges. Writes: the session row. plugins/ai-coach-core/hooks/session-start.js:44
  • prompt.js (fires at your prompt): records · hints to you. skips < 25 chars, / and !; hints: systemMessage only; never shown to the model; plan mode: a Haiku review. Writes: first prompt (scrubbed), signal ids. plugins/ai-coach-core/hooks/prompt.js:34
  • guard.js (fires at pre-tool): blocks or asks: secrets. off by default; blocks real credentials; asks: secret out, key read; only hook that can block. Asks: asks before a secret-looking payload leaves, or a credential file is read. plugins/ai-coach-core/hooks/guard.js:44
  • observe.js (fires at post-tool): records the action. Edit · Write · Bash; <private> stripped first. Writes: one observation per action. plugins/ai-coach-core/hooks/observe.js:15
  • spotlight.js (fires at post-tool): warns: injection. WebFetch, WebSearch, Read; Read outside the repo only; in full once per session; never blocks. plugins/ai-coach-core/hooks/spotlight.js:8
  • observe.js · FAIL (fires at post-tool): records the failure. feeds the snapshot; and the distillation. Writes: a FAIL observation. plugins/ai-coach-core/hooks/observe.js:21
  • notice.js (fires at turn ends · notification): records a correction. on error, failed, wrong…; prints nothing. Writes: a correction. plugins/ai-coach-core/hooks/notice.js:30
  • precompact.js (fires at compaction): saves where you were. branch, ≤ 8 files touched; last fail, ≤ 3 corrections; handed back once, deleted. Writes: a working-state snapshot. plugins/ai-coach-core/hooks/engine.js:1546
  • session-end.js (fires at session end): distils on Haiku. ≤ 3 learnings, 'distilled'; AICOACH_LEARN=off skips it; prunes at 30 and 90 days; never exports a seed. Writes: a summary and up to 3 learnings. plugins/ai-coach-core/hooks/session-end.js:37
  • ~/.ai-coach (kept between sessions): your memory database. next session's brief; survives uninstalling. README.md

ai-coach (bundle)

Three commands that tie the coaches together. a command you type.

memory-coach

Search memory, publish conclusions, hand them to a teammate. Claude calls it, kept between sessions.

investigation-coach

Onboarding docs, architecture maps, study material. a command you type, Claude calls it, a subagent.

strategy-coach

The business as a vault, and feature specs. you type it, Claude calls it.

analysis-coach

Requirements, critiqued analysis, executive write-ups. you type it, a subagent.

atlas-coach

Everything outside the repo: research, ingestion, markets. you type it, a subagent.

security-coach

Injection scans, OWASP audits, pentest triage. you type it, a subagent.

prompt-coach

Prompts that land, and briefs for a subagent. you type it, Claude calls it.

harness-coach

What is installed, and what fills this session. you type it.

design-coach

Published pages made checkable, linted before publish. Claude calls it, a hook: it just runs.

pair-coach

Talk to Claude through @claude comments in the code. a hook: it just runs, you type it, Claude calls it.

ship-coach

Commit, branch and PR on Haiku, after one look. you type it.

Special cases

  1. Every hook fails open: a crash is logged and the session goes on. Only guard.js can stop a call. plugins/ai-coach-core/hooks/guard.js:4
  2. The engine's own claude -p runs set AICOACH_INNER, so every hook skips them: no recursion. plugins/ai-coach-core/hooks/engine.js:448
  3. Hook context goes to the model. Prompt hints go only to you, as a systemMessage. plugins/ai-coach-core/hooks/prompt.js:10
  4. Inside a subagent, every tool call still passes guard, observe and spotlight; the parent gets only the report. Claude Code docs
  5. Anything between <private> tags is stripped before a single byte is written. plugins/ai-coach-core/hooks/observe.js:15
  6. What a model wrote is stamped distilled, and nothing ever promotes it to a person's word. plugins/ai-coach-core/hooks/session-end.js:43
  7. Nothing leaves your machine on its own: the seed is exported only when you say yes. plugins/ai-coach-core/hooks/session-end.js:58
  8. Small models where a summary is the job: distillation, plan review, commit, reader, and skills pinned to Haiku. plugins/ship-coach/skills/commit/SKILL.md:5
  9. AI Coach binds no Stop, SubagentStart or SubagentStop hook: a turn always ends when Claude is done. plugins/ai-coach-core/hooks/hooks.json:1