Architecture constraints
plugins/core-standards/docs/agent-architecture-patterns.md
context: fork Rules¶
- NEVER use AskUserQuestion in a fork skill. The sub-agent has no channel back to the user. The call fails silently — the parent receives no output at all.
- ALWAYS include a concrete actionable task, not just guidelines. A fork skill with only principles produces empty output.
- ALWAYS define a structured output format with delimiters. The parent only sees the sub-agent's final output — make it parseable.
- Fork sub-agents CANNOT spawn their own sub-agents. No nesting.
- ALWAYS add an "Error Handling (context: fork)" section with three rules: no interactive questions, inline failure reporting, full formatted output.
- ALWAYS add a TL;DR summary step as the final output of the fork skill.
Hook Rules¶
- Hooks are ADDITIVE across all four levels (Global > Plugin > Skill > Agent). A lower-level hook cannot suppress a higher-level hook.
- Hooks at the same level execute in PARALLEL. Do not write hooks that depend on side effects from other hooks at the same level.
- Skill-scoped hooks (in SKILL.md frontmatter
hooks:field) only fire while the skill is active. They are removed when the skill completes. - Agent hooks are Level 4 (narrowest scope). They stack on top of all broader hooks, never replace them.
Stophooks declared in agent frontmatter are automatically converted toSubagentStopevents — they fire when the sub-agent stops, not when the parent conversation stops.
Permission Rules¶
bypassPermissionscascades DOWNWARD. If a parent uses it, ALL sub-agents inherit it. You cannot restrict below the parent's level via permissions.- Enforce restrictions via hooks (e.g.,
block-writes.sh), not permissions. This is why the policy island pattern exists. - Background sub-agents auto-deny any unapproved permission prompts. Either pre-approve tools or run the sub-agent in the foreground.
Orchestrator Rules¶
- Sub-agents cannot spawn their own sub-agents. Design orchestrators as FLAT dispatch points — chain from the orchestrator, not from within sub-agents.
- Gate failures must halt the pipeline. The orchestrator is responsible for this logic — there is no built-in gate mechanism.
- The orchestrator needs the Agent/Task tool. Specialist sub-agents typically should NOT have it.
Agent Isolation Rules¶
- Read-only agents (review, analysis) do NOT need
isolation: worktree. - Agents using
context: forkalready run in isolated context — skip worktree. - Agents needing dirty-tree visibility CANNOT use worktree (it branches from the default remote, not the current working state).
- Apply the 4-question checklist in
references/agent-frontmatter-fields.md.
Quick Anti-Pattern Check¶
When creating or auditing a skill/agent, verify:
- [ ] No AskUserQuestion in any context: fork skill
- [ ] No hook that depends on side effects from another hook at the same level
- [ ] No sub-agent spawning its own sub-agents
- [ ] No guidelines-only fork skill (must have actionable task)
- [ ] bypassPermissions not granted without hook-level enforcement
- [ ] Background sub-agents have all needed tools pre-approved
- [ ] Fork skills have error handling section + TL;DR step