Skip to content
Source on GitHub (opens in a new tab)
import "github.com/barevoidco/zelk/core/subagent"

Package subagent defines the kinds of child session a model can spawn with the Task tool: built-in general and explore types and the host’s own definitions. A definition can only narrow what its parent may do. Parse reads Claude Code agent files; Discover supplies conventional file sources for CLI hosts, never implicitly for New.

type Definition struct {
// Name is what the model passes as the Task tool's agent type.
Name string
// Description tells the model when to use it.
Description string
// Prompt is appended to the child's system prompt.
Prompt string
// Tools, if not nil, are the only tools the child may use, among
// its parent's; DisallowedTools are removed from them.
Tools, DisallowedTools []string
// Mode is the child's permission mode, within its parent's; empty
// inherits it.
Mode permission.Mode
// MaxTurns bounds the child's run; zero is no bound.
MaxTurns int
// Model, if set, is the model the child runs on, in the family of the
// agent's provider, resolved as Agent.SetModel resolves a switch.
// Empty inherits the model its parent is on when it spawns the child.
Model string
// Effort, if set, is the child's reasoning effort, replacing its
// parent's; empty inherits it.
Effort event.Effort
// OutputSchema, if set, is the child's structured output contract:
// a JSON Schema in the canonical subset. The child
// delivers its result through StructuredOutput, and the parent gets
// the accepted value with the child's report. Without it, a child
// has no output contract, whatever its parent's.
OutputSchema json.RawMessage
// Isolation, if IsolationWorktree, runs every child of this type in a
// workspace of its own, which the host makes (zelk.WithIsolation);
// empty runs it in its parent's.
Isolation Isolation
}

Definition is a kind of child session.

func Discover(ctx context.Context, home, cwd string) ([]Definition, []error)

Discover loads conventional agent files for CLI hosts. Project directories precede user directories; closest to cwd wins, then .zelk, .agents, .claude. The walk stops at the first .git; outside a repository only cwd is searched. User directories are home/.zelk/agents, home/.agents/agents and home/.claude/agents, in that order, the same three as each project’s. Files in each directory are read in lexical order; the first valid definition of a name wins. Missing directories are ignored; other failures are returned as diagnostics alongside valid definitions. No file can grant child authority.

Example

dir, err := os.MkdirTemp("", "agents-example-")
if err != nil {
panic(err)
}
defer os.RemoveAll(dir)
if err := os.WriteFile(filepath.Join(dir, ".git"), nil, 0600); err != nil {
panic(err)
}
agents := filepath.Join(dir, ".zelk", "agents")
if err := os.MkdirAll(agents, 0700); err != nil {
panic(err)
}
data := []byte("---\nname: reviewer\ndescription: Reviews code.\n---\nReview the change.")
if err := os.WriteFile(filepath.Join(agents, "reviewer.md"), data, 0600); err != nil {
panic(err)
}
defs, diagnostics := subagent.Discover(context.Background(), "", dir)
fmt.Println(defs[0].Name, len(diagnostics))
// Output: reviewer 0

Output:

reviewer 0
func Explore() Definition

Explore is the built-in read-only type, for searching and reading the workspace without changing it.

func General() Definition

General is the built-in type for work that needs the parent’s full tool set: research, multi-step changes, anything delegated whole.

func Parse(data []byte) (Definition, error)

Parse reads a Claude Code agent file: YAML frontmatter and a Markdown prompt. Unknown fields are ignored. Tools and permissionMode only narrow the parent when the definition is used through zelk.WithSubagents.

Example

d, err := subagent.Parse([]byte("---\nname: reviewer\ndescription: Reviews code.\ntools: Read, Grep\npermissionMode: plan\nmodel: claude-haiku-5-5\neffort: max\n---\nReview the change."))
if err != nil {
panic(err)
}
fmt.Println(d.Name, d.Mode, d.Tools, d.Model, d.Effort)
// Output: reviewer plan [Read Grep] claude-haiku-5-5 high

Output:

reviewer plan [Read Grep] claude-haiku-5-5 high
func (d Definition) Validate() error

Validate reports whether d can be used.

type Isolation string

Isolation is where a child works.

const IsolationWorktree Isolation = "worktree"

IsolationWorktree is a git worktree of the parent’s repository, made for the child from the parent’s HEAD.