Skip to content

feat(hooks): inject skill-loading context at SubagentStart #2173

Description

@bdfinst

Part of #2172.

Context

We register hooks on SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, SessionEnd, Stop and SubagentStop — but nothing on SubagentStart.

nWave uses it: a 64-line handler reads the hook input, and for nw-* agent types writes an additionalContext JSON reminder naming the skill files to load. Fail-open — any exception exits 0 so the spawned subagent is never blocked by a reminder hook.

Our equivalent is prose inside each agent body ("Cites:" lists, and in several agents an explicit instruction to read named knowledge files). That works, but it is instruction-following, and it costs the same tokens on every dispatch whether or not the agent needed reminding. A hook injects it deterministically at boot and can tailor it to the dispatched agent.

Goal

Register a SubagentStart hook that injects the dispatched agent's required context deterministically, so the agent file does not have to carry the reminder as prose.

Approach

  • Read the dispatched subagent_type; resolve its Cites: list from the agent file (the same closed registry hooks/lib/review_agent_registry already reads for agent_dispatch_ledger.py — reuse it, do not build a second source of truth).
  • Emit additionalContext naming the resolved knowledge paths.
  • Fail-open, unconditionally. An exception, an unknown agent type, or an unreadable agents/ directory exits 0 with no output. A reminder hook must never block a dispatch.
  • Decide whether this replaces the prose in agent bodies or duplicates it. Replacing is the only version that saves tokens; duplicating costs more than today. If the prose stays for agents dispatched outside this plugin's hooks, say so explicitly and scope which agents rely on which mechanism.

Acceptance criteria

  • A dispatch of a registered review agent receives additionalContext listing exactly the knowledge files that agent's Cites: names.
  • An unregistered or misspelled subagent_type produces no output and exit 0.
  • Malformed stdin, absent agents/ directory, and an exception in resolution each exit 0 silently.
  • If agent-body prose is removed in favor of the hook, /agent-audit passes and agent-eval fixtures show no detection regression for at least the agents whose prose was removed — a context injection that arrives differently must not change what the agent finds.
  • knowledge/telemetry-schema.md updated if the hook emits any boundary event.
  • Full pre-push pytest directory list green.

Out of scope

  • Changing what any agent cites. This slice changes the delivery mechanism, not the content.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions