Composable context
- cmd
hev context- skill
hev-context
A repository collects agent instructions over time: an AGENTS.md at the
root, a CLAUDE.md in a subdirectory, a handful of skills. Which of them an
agent reads, and in what order, usually depends on the harness and where it
happens to start. When a run goes well or badly, you can’t say which
instructions it was working from.
Composable context makes that choice explicit. You write a recipe: a short JSON file that lists the instruction and skill files a kind of work should get, in order, whole or narrowed to some of their sections. kit builds the recipe into a bundle, a directory holding every selected file, the assembled text the agent reads, and a digest that identifies exactly that content. An order names a recipe, dispatch builds the bundle when the run starts, gives it to the worker, and records the digest on the run and on the worker’s sessions. While the worker runs, the repository’s instruction files in its worktree match the recipe too. Later you can find every run that was given the same context and compare how they went.
There are no hidden defaults. A bundle contains what the recipe lists and nothing else, and every file in it is shown with where it came from.
Recipes
A recipe is plain JSON, with no templating:
{
"version": 1,
"task": "Update the docs for a CLI change",
"sources": [
{"path": "AGENTS.md", "target": "AGENTS.md"},
{"path": "docs/AGENTS.md", "target": "docs/AGENTS.md"},
{"path": ".claude/skills/docs-style/SKILL.md", "target": ".claude/skills/docs-style/SKILL.md"}
]
}Write a context recipe at .hev/context/docs.json in this repository. It is JSON with "version": 1, "task": "Update the docs for a CLI change", and "sources" listing AGENTS.md, docs/AGENTS.md and .claude/skills/docs-style/SKILL.md, each with "target" equal to its path. Use only files that exist here; drop or replace any that don't. No absolute paths, `..` or backslashes. Check it with `hev context build --root . --recipe .hev/context/docs.json --out <new directory>`. This needs a hev with `hev context`; if `hev context --help` fails, stop and tell me.
Docs: https://hevkit.com/docs/context#recipes (all pages: https://hevkit.com/llms.txt)pathis a file in the project, relative to its root.targetis where the file sits inside the bundle. Keep a skill’s files at their original relative targets so they stay together.- The order of
sourcesis the order the agent reads them in, and it is part of the digest. taskis the assignment. When dispatch builds the bundle, the order’s body replaces it.keepanddropnarrow a Markdown source to some of its sections; see below. Without them the file is taken whole.
Unknown fields are refused. So are absolute paths, .., backslashes,
symlinks, duplicate targets and files over 16 MiB.
Narrow a file by heading
Instruction files grow. A worker sent to fix one thing rarely needs the release process or the billing notes. A source can keep or drop sections by their headings instead of being taken whole:
{"path": "AGENTS.md", "target": "AGENTS.md", "drop": ["## Release process", "## Billing"]}
{"path": "CLAUDE.md", "target": "CLAUDE.md", "keep": ["## Testing", "### Fixtures"]}Narrow two sources in my context recipe .hev/context/docs.json by heading: give the AGENTS.md source "drop": ["## Release process", "## Billing"] and the CLAUDE.md source "keep": ["## Testing", "### Fixtures"]. Use headings from my files, written exactly as they appear with their # marks. Do not edit AGENTS.md or CLAUDE.md. Check it with `hev context build --root . --recipe .hev/context/docs.json --out /tmp/docs-context-narrowed` (the output directory must be new) and report each narrowed file's size before and after. A selector that matches no heading is an error; fix it in the recipe.
Docs: https://hevkit.com/docs/context#narrow-a-file-by-heading (all pages: https://hevkit.com/llms.txt)- A selector is a heading written as it appears in the file,
#marks included:"## Testing"matches every level-2 heading whose text isTesting. Spacing is trimmed and a closing run of#is ignored."(preamble)"names the text before the first heading. Headings inside fenced code blocks and underlined (Setext) headings are plain text. - A section runs to the next heading of the same or a higher level, so it includes its subsections.
keepkeeps the preamble, each matched section, and the heading lines above it, so a kept### Fixturesstill sits under its##. Everything else goes.dropremoves each matched section, afterkeep.- A selector that matches no heading is an error, and so is a file with nothing left. Selectors on a file that isn’t Markdown are refused.
Narrowing only cuts. What remains is the file’s own bytes, in order, with
nothing rewritten or summarized, and the same recipe and file always give the
same bytes. build prints each narrowed file’s size before and after,
context.md labels it (narrowed: N of M bytes), and the review page lists
the sections kept and dropped. A recipe with no keep or drop builds
exactly the bundle and digest it did before narrowing existed.
A worked example
This takes the my-project repository from the
quickstart from no recipe to a run that was given one.
1. Assess the project
cd ~/workspace/my-project
hev context assess --root . --out /tmp/my-project-assessmentAssess the agent instructions in ~/workspace/my-project (use my repository's path if it differs): run `hev context assess --root . --out /tmp/my-project-assessment` from the repository root. The output directory must not exist yet. Confirm it wrote assessment.json, recipe.json and improved.recipe.json, and summarize the findings: duplicates, repeated lines, oversized files, broken links and opposite directives, with file and line. Do not change any source file. This needs a hev with `hev context`; if `hev context --help` fails, stop and tell me.
Docs: https://hevkit.com/docs/context#1-assess-the-project (all pages: https://hevkit.com/llms.txt)assess finds every AGENTS.md and CLAUDE.md at any depth, and the files
under .claude/agents/, .claude/skills/ and .agents/skills/ at the root.
It writes three files into the new directory:
| File | What it holds |
|---|---|
assessment.json | Every source found, and findings with the file and line: exact duplicates, repeated lines, oversized files, a missing Scope: line, broken local links, and opposite directives such as Always run tests. beside Never run tests. |
recipe.json | A baseline recipe that includes every source found. |
improved.recipe.json | The same recipe without exact duplicate files. A starting point to edit. |
The checks are simple word matches. They can miss a conflict that is phrased
differently, and they can flag repetition you meant. They never change a
source file. When nested and root instructions disagree, assess shows both;
it can’t tell you which should win.
hev context extract does the same and also copies every source into
NEW/sources, so you can build bundles from that copy with
--root NEW/sources, apart from the project.
2. Write the recipe
Copy the improved recipe into the repository and cut it down to what this kind of work needs:
mkdir -p .hev/context
cp /tmp/my-project-assessment/improved.recipe.json .hev/context/docs.json
$EDITOR .hev/context/docs.jsonIn the repository root, create .hev/context and copy /tmp/my-project-assessment/improved.recipe.json to .hev/context/docs.json. Then cut its sources down to what docs changes need, and show me the sources you kept and dropped before saving. Keep a skill's files at their original targets.
Docs: https://hevkit.com/docs/context#2-write-the-recipe (all pages: https://hevkit.com/llms.txt)A recipe is meant to be small and specific: one for docs changes, one for reviews, one for a migration. Remove the sources that kind of work doesn’t need, and narrow the ones it needs only part of. A file the recipe doesn’t name is taken out of the worker’s worktree while it runs, so cut only what you mean to. Keep each recipe in the repository so it is reviewed like code.
3. Build it and read it
hev context build --root . --recipe .hev/context/docs.json --out /tmp/docs-context
hev context review --bundle /tmp/docs-contextBuild the context bundle from the recipe: run `hev context build --root . --recipe .hev/context/docs.json --out /tmp/docs-context` (the output directory must be new). Confirm it wrote context.md, materialized/, bundle.json and index.html, and tell me the digest. Then run `hev context review --bundle /tmp/docs-context` and give me the loopback URL it prints; do not open a browser. This needs a hev with `hev context`; if `hev context --help` fails, stop and tell me.
Docs: https://hevkit.com/docs/context#3-build-it-and-read-it (all pages: https://hevkit.com/llms.txt)build writes a new directory:
| Path | What it is |
|---|---|
context.md | The assignment, then every selected Markdown source in recipe order. This is what the agent is given. |
materialized/ | Every selected file at its target, bytes unchanged, including skill files that are not Markdown. |
bundle.json | The manifest: each source’s path, target, hash and size, the assessment, and the digest. |
index.html | A self-contained page for reading the bundle. It works offline. |
review serves that page on a loopback address and prints the URL. It never
opens a browser and refuses a non-loopback address. Source Markdown and HTML
show as text, never rendered. Every output directory must be new: build
never overwrites anything.
Building the same recipe from the same files gives the same bytes and the same digest. To see what a change to a recipe does, build both and compare them:
hev context diff --before /tmp/docs-context --after /tmp/docs-context-2 --out /tmp/docs-diff
hev context review --bundle /tmp/docs-diffCompare two builds of a context recipe: build the changed recipe into the new directory /tmp/docs-context-2, then run `hev context diff --before /tmp/docs-context --after /tmp/docs-context-2 --out /tmp/docs-diff` and `hev context review --bundle /tmp/docs-diff`. Summarize the changes to the assignment, the source order and each added, removed or changed file, and give me the review URL. This needs a hev with `hev context`; if `hev context --help` fails, stop and tell me.
Docs: https://hevkit.com/docs/context#3-build-it-and-read-it (all pages: https://hevkit.com/llms.txt)diff checks both digests, then shows the assignment, the source order and
every added, removed or changed file side by side.
4. Commit the recipe
git add .hev/context/docs.json
git commit -m "Add a context recipe for docs changes"
git push origin mainCommit the context recipe .hev/context/docs.json with the message "Add a context recipe for docs changes" and push it to origin main, since hosts read the recipe at origin/<base>. If main is protected or I use another base branch, stop and ask me instead of pushing. Verify with `git show origin/main:.hev/context/docs.json`.
Docs: https://hevkit.com/docs/context#4-commit-the-recipe (all pages: https://hevkit.com/llms.txt)The host that runs the work reads the recipe from the repository at the run’s
base commit, origin/<base>, so it has to be pushed. A worker can’t change the
recipe its own next attempt gets.
5. Name it in an order
---
name: docs-for-flags
host: laptop
repo: my-project
harness: claude
context: .hev/context/docs.json
---
Document the new --json flag in docs/cli.md.
## Acceptance
- docs/cli.md describes --json with an example.Write an order file docs-for-flags.md with frontmatter name: docs-for-flags, host: laptop, repo: my-project, harness: claude, context: .hev/context/docs.json. Use my host and repository names if they differ. The body says: Document the new --json flag in docs/cli.md. Add an ## Acceptance section: docs/cli.md describes --json with an example. Check that .hev/context/docs.json exists at origin/main. Show me the file; do not dispatch it.
Docs: https://hevkit.com/docs/context#5-name-it-in-an-order (all pages: https://hevkit.com/llms.txt)context is a path inside the order’s repository. An order without it, and
without a carried recipe, runs exactly as it
does without composable context. For an inline order,
hev dispatch run REPO TASK... --context .hev/context/docs.json does the same.
6. Dispatch it
hev dispatch docs-for-flags.mdDispatch the order with `hev dispatch docs-for-flags.md`. Confirm the run started, and if it failed before launch, show me the error, which names the recipe problem. This needs a hev with `hev context`; if `hev context --help` fails, stop and tell me.
Docs: https://hevkit.com/docs/context#6-dispatch-it (all pages: https://hevkit.com/llms.txt)On the host, after the worktree exists and before the agent starts, dispatch
builds the bundle from the worktree using the recipe. The order’s body is the
bundle’s assignment, in place of the recipe’s task. Sources are read from the
worktree, so a rework sees the worker’s own committed changes to instruction
files.
The worker is given the bundle’s context.md on standard input when it
starts, alongside its usual prompt, for both codex and claude, on macOS,
Linux and Windows hosts. A harness_wrapper
must pass standard input through to the harness; exec "$@" does.
If the recipe is missing or invalid, or names a file that doesn’t exist, the run fails before anything launches, with an error that names the problem. dispatch never starts a worker with part of a bundle.
7. Read what it was given
hev dispatch show docs-for-flags
hev context review --run docs-for-flagsShow what the run docs-for-flags was given: run `hev dispatch show docs-for-flags` and report its context digest, recipe and bundle location. Then run `hev context review --run docs-for-flags` and give me the URL it prints; add `--attempt 1` to see the first attempt if there were several. This needs a hev with `hev context`; if `hev context --help` fails, stop and tell me.
Docs: https://hevkit.com/docs/context#7-read-what-it-was-given (all pages: https://hevkit.com/llms.txt)show prints a Context: block: the digest, the recipe with its hash and the
commit it was read at, where the bundle is, how many sources it has, and each
instruction file in the worktree with the form the worker had it in. Each earlier attempt’s
line names the digest it was given. Run review --run on the run’s host: it
opens the current attempt’s bundle, and --attempt 1 opens the first.
Review a dispatch’s context
A committed recipe suits a kind of work you send often. For one dispatch, you can instead plan a recipe from the order itself, narrow it, and send it with the order.
Plan
hev context plan fix-login-redirect.md --root ~/workspace/web --out /tmp/fix-login-planPlan a context recipe for one dispatch of the order fix-login-redirect.md: run `hev context plan fix-login-redirect.md --root ~/workspace/web --out /tmp/fix-login-plan`, with my order file and repository path, and an output directory that does not exist yet. Show me the inventory it prints and the path of index.html. Then copy recipe.json to narrowed.json and propose which sources to remove and which keep or drop headings to add for this task, with a reason for each cut. Keep whole any instruction file the order asks the worker to edit. After I agree, check that it builds with `hev context build --root ~/workspace/web --recipe narrowed.json --out /tmp/fix-login-narrowed`. If plan says there is nothing to narrow, stop and tell me.
Docs: https://hevkit.com/docs/context#plan (all pages: https://hevkit.com/llms.txt)plan reads the order, runs the assessment on its repository (--root, by
default the current directory) and writes a new directory:
| File | What it holds |
|---|---|
recipe.json | Every instruction file, agent and skill found, whole, with the order’s body as the task. It builds as is. |
plan.json | Each file’s kind, size and hash, its sections with their sizes, and the assessment’s findings. |
index.html | A review page with the same, and each file’s full text. |
It also prints that inventory. It cuts nothing and calls no model: choosing what the task needs is up to you. If the repository has no instruction files, it says there is nothing to narrow and writes nothing; dispatch without a recipe.
Copy recipe.json, remove the sources the task doesn’t need and add keep
or drop to the rest, then check it with hev context build. Keep whole any
instruction file the order asks the worker to edit.
A recipe for one dispatch
hev dispatch fix-login-redirect.md --context-file narrowed.json
hev dispatch run web 'Fix the login redirect' --context-file narrowed.json
hev dispatch amend fix-login-redirect fix-login-redirect.md --context-file narrowed.jsonDispatch the order fix-login-redirect.md with my narrowed recipe carried in it: run `hev dispatch fix-login-redirect.md --context-file narrowed.json`, with my order and recipe files. For an order written on the command line, use `hev dispatch run web 'Fix the login redirect' --context-file narrowed.json`; to change the recipe of a run already sent, use `hev dispatch amend fix-login-redirect fix-login-redirect.md --context-file narrowed.json`. The recipe must be under 1 MiB and does not need committing, and the order must not also name `context`. Verify with `hev dispatch show fix-login-redirect` that the recipe was carried in the order, and tell me the context digest.
Docs: https://hevkit.com/docs/context#a-recipe-for-one-dispatch (all pages: https://hevkit.com/llms.txt)--context-file checks the file is a recipe and adds it to the order as
context_recipe:, the recipe’s JSON in base64, up to 1 MiB. It travels with
the order, through the queue, amends and host moves, like any other field.
The recipe file never needs committing; its sources are still read from the
run’s worktree. An order names context or carries context_recipe, not
both.
On the host, the first build pins the carried recipe in the run record as
context-recipe.json and records its hash. Every later attempt reads the
pinned copy, so a worker can’t change the recipe its next attempt gets. An
amend pins the amended order’s recipe, and a host move pins it on the new
host. hev dispatch show says the recipe was carried in the order.
The hev-context skill
An agent that dispatches for you does this review with you. hev skills setup
installs the hev-context skill for owners, and hev-dispatch points to it
when the order’s repository has instruction files. The agent runs plan,
proposes a narrowed recipe with a reason for each cut, checks that it builds,
and shows you one screen: what is kept, what is dropped and why, and the size
before and after. You answer yes or say what to change. It then dispatches
with --context-file and tells you the digest, so you can find the run later.
The skill never edits a repository’s instruction files. If a section looks
stale or contradictory it may say so in one line. Tell it to skip the review
and it dispatches without a recipe, so the worker loads the files whole.
hev dispatch itself never asks anything.
Instruction files in the worktree
Claude Code and Codex read AGENTS.md, CLAUDE.md, agents and skills from
the worktree themselves, so a narrowed copy on standard input wouldn’t be
enough: the harness would still load the full file. For every run with a
recipe, committed or carried, dispatch puts each instruction file in the
worktree in the form the recipe gives it, for exactly as long as the harness
runs. It works the same for claude and codex, on every host.
Each file assess would find gets one form:
| Form | When | What the worker can read |
|---|---|---|
| narrowed | The recipe names it with keep or drop. | The narrowed bytes. |
| whole | The recipe names it without selectors, or it belongs to a skill whose other files the recipe names. | The file, untouched. |
| excluded | The recipe doesn’t name it. | Nothing: the file is removed. |
| full | It would be narrowed or excluded, but it is untracked or has uncommitted changes. | The file, untouched. The record says why. |
This changes only the worker’s own worktree, and only while it runs. The
repository, the base commit, your checkout and anything the worker commits
keep the full files. Before the harness starts, dispatch marks each replaced
file skip-worktree in that worktree’s Git index, so git status, diff,
add -A, commit -a and stash don’t see it and git add PATH refuses it.
When the harness exits, dispatch clears the marks and checks the files out
again. If the supervisor dies mid-run, the next attempt puts them back before
it builds its bundle. A repeating order does this around each round.
The worker is told. When any file is narrowed or excluded, its assignment ends with a short section listing them and how to restore one:
git update-index --no-skip-worktree -- PATH && git checkout -- PATHI am a dispatched worker and need to edit an instruction file that dispatch narrowed or excluded in my worktree, PATH (for example AGENTS.md). Restore it first: run `git update-index --no-skip-worktree -- PATH && git checkout -- PATH`. Check with `git status` and by reading the file that it is tracked normally and has its full content, then edit and commit it as usual.
Docs: https://hevkit.com/docs/context#instruction-files-in-the-worktree (all pages: https://hevkit.com/llms.txt)A worker that has to edit a narrowed or excluded file restores it that way,
then edits and commits it as usual. An edit to a replaced file without
restoring it can’t be committed: dispatch saves the changed copy under
instruction-edits/ in the run record, restores the file, and reports it in
result.json as instruction_warnings.
What is recorded
Every launch builds a fresh bundle. A rework, retry,
say to an ended run, or an amend that restarts the run gets a new bundle and
digest, and earlier attempts keep theirs. The recipe is read at the commit
pinned by the first bundle, unless an amend changes base. An amend that
changes context on a live run restarts it, because a worker is given its
context only at launch. Bundles live in the run record,
never in the worktree, so they are never committed:
| Where | What |
|---|---|
~/.hev/orders/NAME/contexts/N/ | Attempt N’s bundle: context.md, materialized/, bundle.json, index.html |
meta.json | The recipe path, its hash and the commit it was read at, the digest, every source’s path and hash (and the full file’s, for a narrowed one), and each instruction file’s form |
context-recipe.json | A carried recipe, pinned at the first build |
result.json | The digest, so an archived attempt still names the bundle it had |
history.json | Each attempt’s full record, including its bundle |
| Worker session rows | The digest, as context_digest, once the session is indexed |
hev dispatch show NAME --json carries it in meta.json and result.json,
and hev dispatch ls --json rows carry context_digest and context_bundle.
Records written without a context have no context fields and read as before.
Bundles hold the full text of every source, with the same file permissions as the rest of the run record. kit does not send them anywhere new.
Find runs by context
The digest is the handle for “runs given this context”. Take it from
hev dispatch show, then filter traces by it:
hev traces ls --context DIGEST
hev traces search "why did the tests fail" --context DIGESTFind runs that were given one context: take the context digest from `hev dispatch show <run name>`, then run `hev traces ls --context <digest>` and `hev traces search "why did the tests fail" --context <digest>`. Add --since if I only want recent sessions. List the sessions and quote the best match. This needs a hev with `hev context`; if `hev context --help` fails, stop and tell me.
Docs: https://hevkit.com/docs/context#find-runs-by-context (all pages: https://hevkit.com/llms.txt)--context combines with --order, --since and the other scoping flags.
Like --order, traces ls --context looks at every age unless you give
--since. Both work on every tier (Upgrade). Search finds
the sessions given the digest, then searches only their chunks.
A run’s context and its ask-rooted trace
are recorded side by side: the worker gets the bundle on standard input and
the trace in its environment, and the run, each attempt and the worker’s
session row carry both the trace ID and the digest, so hev traces ls --context DIGEST finds every session that was given a bundle.
Orders written by hev intake templates can name a
recipe with context: too.
Limits
- The bundle is not everything the agent saw. Dispatch sets the
repository’s instruction files in the worktree, but Claude Code and Codex
still load your user-level settings (
~/.claude,~/.codex), their own system prompts, and worktree files discovery doesn’t cover, such asCLAUDE.local.mdor.claude/rules/. dispatch doesn’t stop that or measure it, and the run record says the bundle is not the whole picture. - A digest is a reproducibility handle, not proof. It says exactly which bytes dispatch gave the worker. It can’t say what the harness read, kept or ignored.
- Discovery is local and literal.
assessreads the project only. It does not read guidance in your home directory, ignored harness state, remote links or anything a harness injects. Files a source links to are checked but not added; add them to the recipe yourself. - Validators get no bundle. A browser validation run starts with the harness’s usual context.
- Recipes list files. A recipe can’t yet pull in a search over traces or the board. The format is meant to grow a new source kind without breaking existing recipes or their digests.
- Every host must support
context. A target whosehevlacks it refuses an order withcontext:orcontext_recipe:as an unknown key, so it never runs without the context it was asked for.hev dispatch hostsshows each host’s version.