Subagents & hooks

Define specialized sub-agents as markdown files; wire lifecycle hooks to guard or observe every tool call.

Subagents

Subagent definitions live in .deyin/agents/*.md. Front-matter declares name, description, model, readonly, and is_background; the markdown body becomes the sub-agent's system prompt. The main agent delegates through its task tool, and each sub-agent runs with a clean context window.

Built-ins include explorer (fast codebase search), reviewer (diff review without editing), and test-runner.

Hooks

hooks.json lives at .deyin/hooks.json (project) or ~/.deyin/hooks.json (user). Events: sessionStart, preToolUse, postToolUse, beforeShellExecution, afterShellExecution, and stop. The payload arrives as JSON on stdin; exit code 2 blocks the action. Failures fail open unless failClosed is set.

{ "version": 1,
  "hooks": {
    "preToolUse": [{ "command": "./guard.sh", "timeout": 10, "matcher": "write|edit" }]
  } }

Agent definition format

Subagents run in isolated sessions with their own context window. They see the task you hand them — not your whole conversation — which keeps their output focused and cheap.

access maps to the same levels as the composer: full, ask, or read-only. A read-only subagent cannot edit files even if the parent session could.

.deyin/agents/reviewer.md
---
name: reviewer
description: Reviews diffs for correctness and style
model: glm-5.2
access: read-only
tools: [Read, Grep]
---

You are a strict code reviewer...

Lifecycle hooks

Hooks fire at deterministic points so you can enforce policy without prompting the model:

PreToolUse — runs before a tool call; a non-zero exit blocks the call. PostToolUse — runs after success; useful for formatting or audit logs. SubagentStop — fires when a subagent finishes; commonly used to summarize results back into the parent session.

Hooks are shell commands configured in .deyin/settings.json and receive structured JSON on stdin.

Something missing? Tell us or open an issue on GitHub.