# Skills and subagents

> Give sessions skills to load when a task fits, and subagents to delegate work to.

## Skills

A skill is a set of instructions, with any files it needs, that the model
loads when a task fits its description. The host says where skills come
from: `skill.Discover` finds them where the `zelk` command looks
(`.zelk/skills`, `.agents/skills` and `.claude/skills`, at home and in the
project), `skill.FS` reads them from any `fs.FS`, and
`skill.Programmatic` builds them in Go:

```go
// core/guide_example_test.go
release, err := skill.Parse("release", []byte("---\nname: release\ndescription: Cut a release of this project.\n---\n\nTag the version, then push the tag.\n"))
if err != nil {
	panic(err)
}
p, err := replay.New(provider.Caps{})
if err != nil {
	panic(err)
}
ctx := context.Background()
a, err := zelk.New(ctx, p, zelk.WithModel("m"), zelk.WithPermissionMode(permission.ModeDefault),
	zelk.WithSkills(skill.Programmatic("host", skill.TrustHost, release)))
if err != nil {
	panic(err)
}
defer a.Close(ctx)
fmt.Println(release.Name, "-", release.Description)
// Output: release - Cut a release of this project.
```

Each source has a trust level: `TrustHost` skills rank with the host's
own policy, and `TrustProject` skills, which a repository brings, rank with
project instructions as lower-trust guidance. The model loads a skill with the Skill tool, and a
user message `/name args` invokes one directly.

## Subagents

The Task tool lets the model hand a piece of work to a **subagent**: a
child session with its own context, which reports back when done. Two
types are built in, `general` and `explore` (read-only, for searching):

```go
// core/subagents_example_test.go
p, err := replay.New(provider.Caps{})
if err != nil {
	panic(err)
}
ctx := context.Background()
a, err := zelk.New(ctx, p, zelk.WithModel("m"), zelk.WithPermissionMode(permission.ModeDefault), zelk.WithInputDeny())
if err != nil {
	panic(err)
}
defer a.Close(ctx)
for _, d := range a.Subagents() {
	fmt.Println(d.Name)
}
// Output:
// general
// explore
```

`WithSubagents` adds your own types. A definition is Markdown with front
matter, the format Claude Code uses, naming its tools, permission mode,
model and effort:

```go
// core/subagent/example_test.go
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
```

A subagent can't have more authority than its parent: its policy is
narrowed from the parent's, and a definition asking for a wider mode runs
in the parent's, with a warning. `WithSubagentBudget` bounds what children
take from a run's budget, and `WithoutSubagents` removes the Task tool.

## Next

[Compaction](/go/compaction/) keeps long sessions inside the model's window.
