src/lib/cloister/prompts/: the work agent’s
kickoff, the Deft work agent’s kickoff, the planning agent’s discovery prompt
and the model-to-model handoff prompt.
A single loader, renderPrompt at
src/lib/cloister/prompts.ts, is the only way code turns one of those
templates into a finished prompt string.
Role definitions are a separate system. They live in roles/<role>.md, and
Overdeck reads them without this loader. See
Prompts outside this loader.
This page is the authoritative guide to that system: what the templates are,
how the loader works, the frontmatter contract, the full template catalogue,
and how to add, edit, or migrate a prompt without breaking production.
Why templates at all
Before the unified loader, prompts were assembled a dozen different ways: inline template literals in TypeScript,readFileSync of raw Markdown files,
ad-hoc String.replace passes, and a pair of home-grown processIfBlocks /
processEnvBlocks helpers. Each specialist invented its own variable syntax
and its own idea of what an “optional” section looked like.
That sprawl produced three recurring failures:
- Silent typos. A variable like
{{issueId}}referenced in the template but namedissue_idat the call site rendered as the literal string{{issueId}}in the prompt sent to Claude. No error, no warning: the specialist just got a broken prompt and ran on bad context. - Drift between similar templates. The merge-agent prompt used by the full-push path and the wake-time validation path were two separate string builders that were supposed to stay in sync and didn’t.
- No way to see what a prompt expects. Finding the variables a template depended on meant reading the TypeScript call site line by line.
PromptError that names the template path and the
list of offending keys.
Core principles
Keep these five rules in mind when you touch any prompt template.
1. Fail loud, fail early
Missing a required variable is a programming error, not a runtime condition to recover from. The loader fails withPromptError, naming the template path and the
list of missing keys. There is no silent fallback, no empty-string
substitution, no “render partial output and hope nobody notices”. If you see a
PromptError in a log, it means a call site is wrong and needs to be fixed,
not that the loader needs a guard.
2. One template, one API
Code reads a template undersrc/lib/cloister/prompts/ only through
renderPrompt({ name, vars }). If you find another read of one of these
files, migrate it to renderPrompt. Role files under roles/ are read
directly by design; see
Prompts outside this loader.
3. Composition happens in TypeScript
Mustache is deliberately a small, logic-less templating language. The loader disables HTML escaping globally (Mustache.escape = (text) => String(text)) because we’re
generating prompts for an LLM, not HTML. Everything else is vanilla
Mustache with its usual section syntax.
Any non-trivial composition (choosing between two instruction variants,
joining an array of file paths, formatting a table of tasks) happens in
TypeScript. The TypeScript builds a string, then passes that string to the
template as a single variable. This keeps templates readable and keeps
business logic in a place where tsc and your tests can see it.
4. Variables are declared, not discovered
Every variable the template’s body uses should appear in the frontmatter as eitherrequires or optional. The loader rejects any key in vars that
the frontmatter doesn’t declare, and any required key that is missing or
undefined/null. Both errors name the template path and the offending
keys. The loader never scans the body, so a {{VAR}} that the frontmatter
leaves out renders as an empty string when the call site doesn’t pass it.
This means the frontmatter tells you what a template expects, as long as
authors keep it in step with the body.
5. Prompts are not docstrings
A prompt template is production code that steers an LLM’s behavior. Treat it accordingly: prefer explicit instructions over implicit assumptions, prefer concrete examples over abstract rules, and when you change a template, think about what’s going to happen the first time an agent runs it against a real workspace.The renderPrompt API
Signature
name is the filename under src/lib/cloister/prompts/ without the
.md extension. renderPrompt({ name: 'work' }) loads work.md.
renderPrompt returns an Effect. Run it with Effect.runPromise (as
buildWorkAgentPrompt does), with Effect.runSync (as buildHandoffPrompt
does), or yield* it inside Effect.gen.
What happens on every call
- Load. The file is read from disk on every call. There is no template cache; only the resolved prompts directory is cached.
- Parse frontmatter. The leading
---YAML block is extracted viajs-yaml. Missing frontmatter, invalid YAML, or a missingname/descriptionfield all fail withPromptError, and so does arequiresoroptionalvalue that isn’t a list of strings. - Validate
requires. Every key listed inrequiresmust be present invarsand notundefined/null. Missing keys are collected and reported in one error message. - Validate unknown keys. Every key in
varsmust be listed in eitherrequiresoroptional. Undeclared keys are collected and reported in one error message. - Render. The body is passed to
Mustache.render(body, vars)with HTML escaping disabled.
Error handling
Every loading and validation failure is aPromptError, exported from the
module. It’s an Effect tagged error (Data.TaggedError('PromptError')) and
also an Error. renderPrompt fails its Effect with it, so
Effect.runPromise rejects and Effect.runSync throws. Rendering is
different: a body Mustache can’t parse, such as an unclosed {{#VAR}}
section, throws Mustache’s own Error, which the loader does not convert to
a PromptError. Typical PromptError messages:
Prompts directory resolution
resolvePromptsDir() picks the directory once per process and caches the
answer:
join(__dirname, 'prompts'), next to the module that holds the loader. In dev that’ssrc/lib/cloister/prompts. A build copies the templates next to each bundle:dist/dashboard/promptsfor the dashboard server,dist/promptsanddist/cli/promptsfor the CLI.- If that directory doesn’t exist, the resolver finds the package root (it
strips everything from
/src/onward when__dirnamecontains/src/, otherwise it goes up two directories) and triessrc/lib/cloister/promptsunder it. - If neither exists, it keeps the first path, and the first render fails with “Failed to load prompt template”.
*.md from source to dist/dashboard/prompts/.
Frontmatter contract
Every template starts with a YAML frontmatter block delimited by---. The
loader enforces this structure: a missing or malformed block fails with
PromptError before the body is rendered.
Fields
requires vs optional
The rule of thumb:
- If the template’s output would be broken or misleading without the
variable, list it as
requires. - If the variable is genuinely a “fill this in if you have it, leave the
section out otherwise” case, list it as
optional.
requires is stricter than you might think: passing an empty string
("") satisfies the check. Only undefined and null fail. This is
intentional. buildWorkAgentPrompt passes an empty ISSUE_ID when a
recovery path has no issue id, and the prompt still renders. The caller is
the one who decides whether “empty” is a legitimate value.
Unknown keys are an error
Ifvars contains a key that isn’t listed in requires or optional, the
loader refuses to render. This catches two classes of bug:
- You renamed a template variable and forgot to update the call site.
- You added a new variable to the call site and forgot to declare it in the frontmatter.
Mustache syntax reference
We use Mustache.js v4. HTML escaping is disabled globally, so{{VAR}} and {{&VAR}} behave identically and you
never need to worry about < or & showing up in prompts.
Variable substitution
Truthy sections
Render the enclosed block if the variable is truthy (non-empty string,true,
a non-empty array, an object). Empty strings and false hide the block.
{{#VAR}}{{VAR}}{{/VAR}}: that’s Mustache context
fall-through: inside a truthy section, the variable itself is still
accessible in the parent scope and gets substituted normally. This is how
work.md hides its Specialist Feedback heading when PENDING_FEEDBACK is empty.
Inverted sections
Render if the variable is falsy/empty.DO_PUSH boolean.
Boolean flags
{{#VAR}} and {{^VAR}}. They are the
cleanest way to toggle whole sections of a template based on a flow
decision made in TypeScript.
No partials, no lambdas, no custom helpers
Mustache supports partials and lambdas; we don’t use them. Composing from smaller template fragments would push the contract across multiple files; lambdas would put logic back into the template. Both defeat the point of having a declared contract per file. If you find yourself reaching for a helper, the right move is almost always to do the work in TypeScript and pass the result in as a pre-built string variable.Template catalogue
The eleven templates undersrc/lib/cloister/prompts/. Four have a
production caller. The other seven still load and some have smoke tests,
but nothing in src/ renders them today.
Templates with a caller
Templates without a caller
Prompts outside this loader
Not every prompt goes throughrenderPrompt:
- Role definitions live in
roles/<role>.md. When a Claude Code agent launches with a role file, Overdeck strips its frontmatter and passes the body with--append-system-prompt-file(roleSystemPromptInjectioninsrc/lib/agents/runtime-command.ts). - Review convoy sub-reviewers (security, correctness, performance,
requirements) get
roles/review-<subRole>.mdinlined into their spawn message bybuildConvoyPrompt(src/lib/cloister/review-convoy.ts), so the same text drives every harness. - The review and test spawn messages are built in TypeScript by
buildReviewRolePrompt(src/lib/cloister/review-agent.ts) andbuildTestRolePrompt(src/lib/cloister/test-agent-queue.ts).
roles/*.md file needs a commit with a
Prompt-Change: trailer (scripts/check-prompt-change-trailer.sh).
Deleted (replaced by the loader)
These files used to live underprompts/. They no longer exist:
inspect-agent.md→ the inspect verb and its inspect specialist were deleted in PAN-3917merge-agent.md→ replaced bymerge.mdwithDO_PUSH/DO_BUILDflagsreview-agent.md→ replaced byreview.mdtest-agent.md→ replaced bytest.mdwork-agent.md→ renamed towork.md
Orchestration markers
One template wraps its output in HTML comments:planning.mdwraps its whole body in these markers, with an HTML comment that tells session summarizers to skip the block. No code insrc/parses the markers.
Composition pattern
Most non-trivial templates use a pattern we call pre-built blocks: the TypeScript call site composes a multi-line Markdown string based on runtime state, and passes that string in as a single optional variable. The template then conditionally renders the block via a Mustache section.Example: the work.md feedback block
src/lib/cloister/work-agent-prompt.ts, which lists
the workspace’s feedback files and returns an empty string when there are
none:
pendingFeedbackStr is non-empty, the section renders; when it’s
empty, the section disappears entirely. The template stays readable (no
nested conditionals, no formatting logic) and the TypeScript stays honest
about what the block looks like.
When to use in-template conditionals vs pre-built blocks
- In-template sections (
{{#VAR}}...{{/VAR}}) are right when the block is a fixed, static chunk of instructions that’s either present or absent based on a boolean flag. Themerge.mdpush/no-push toggles are a good example: the alternative paths are both long, both fully specified in the template, and both known at template-authoring time. - Pre-built blocks are right when the block’s content is dynamic: it
joins a list, formats a table, runs git commands, reads feedback files, and
the template’s job is just to decide whether to include it. The
work.mdfeedback list is a good example: the TypeScript knows how to format it, the template just needs to show or hide it.
Testing prompts
Prompt tests live insrc/lib/cloister/__tests__/prompts.test.ts. They fall
into three categories:
1. Loader contract tests
These test the loader itself against small fixture templates. Each test writes one as__test-scratch__.md in src/lib/cloister/prompts/ and deletes it afterwards. They cover
missing frontmatter, invalid YAML, missing requires,
unknown vars, empty strings as requires, Mustache section rendering, etc.
They cover the main error paths in renderPrompt and the
frontmatter parser.
2. Live-template smoke tests
These render the real templates against realisticvars fixtures and assert
that key strings appear (or don’t appear) in the output. The merge.md
tests are a good example: four tests covering the push+build flow, the
validation-only flow, the SKIP_DONE_REPORT branch, and the polyrepo
header.
Smoke tests are load-bearing: they catch cases where someone edits a
template in a way that looks fine to Mustache but breaks a downstream
specialist’s expectations.
3. Caller-side tests
Tests that verify TypeScript call sites pass the right variables, live alongside the calling module (e.g.,work-agent-prompt-tests-mode.test.ts for
buildWorkAgentPrompt). These catch the “call site got out of sync
with the frontmatter” class of bug.
Writing a new smoke test
When you add a template, add at least one smoke test that:- Renders the template with a realistic set of
vars. - Asserts the presence of fixed strings that the template always produces.
- Asserts the presence / absence of conditional blocks for each branch the template can take.
vars small and local to the test: no shared state, no
global setup. The loader caches only the prompts directory, so tests can stay simple.
Authoring workflow
Adding a new template
- Create
src/lib/cloister/prompts/<name>.md. - Write the frontmatter first. List every variable you’ll reference in the
body under
requires(if it must be provided) oroptional(if it’s fine to omit). Write a one-linedescription. - Write the body using
{{VAR}}for substitution and{{#VAR}}...{{/VAR}}for optional sections. - Add a caller in TypeScript:
- Add at least one smoke test in
prompts.test.ts. - Run
npx vitest run src/lib/cloister/__tests__/prompts.test.ts,npm run typecheckandnpm run lint. - Run
npm run build. The build pipeline copies*.mdfromsrc/lib/cloister/prompts/todist/dashboard/prompts/,dist/prompts/anddist/cli/prompts/. If you skip this step, the built dashboard and CLI fail with aPromptErrorat runtime.
Editing an existing template
- Decide whether the change is contract-breaking: does it add a new required variable, remove one, or change the meaning of an existing one? If yes, update every call site in the same commit.
- Update the frontmatter. Adding a new variable means adding it to
requiresoroptional. The loader refuses to render until you do. - Update the body.
- Update or add smoke tests.
- Run
npm run typecheck, the prompts tests andnpm run lint:prompts(it checks required and forbidden strings inwork.md,planning.mdand someroles/*.mdfiles).
Migrating a legacy ad-hoc prompt
If you find a call site that builds a prompt via template literals,readFileSync + ad-hoc replace, or any other pre-loader pattern, the
migration path is:
- Create the new
prompts/<name>.mdtemplate with frontmatter that matches the variables the ad-hoc code was substituting. - Replace the ad-hoc builder with a single
renderPrompt({ name, vars })call. - If the old code had conditional logic (e.g., “if foo, include bar”), decide per case: simple toggles become Mustache sections, dynamic content becomes a pre-built block variable.
- Delete the ad-hoc builder, the old template file if there was one, and any helper functions that existed only to support it.
- Add smoke tests.
- Run typecheck + prompts tests.
Troubleshooting
”requires variables that are missing”
optional, unless the template genuinely works with it absent.
”was passed unknown variables”
“missing YAML frontmatter”
--- frontmatter block. This
happens when someone deletes the frontmatter by accident, or pastes a
body-only template from an old pattern. Add the frontmatter.
”Failed to load prompt template”
- Typo in
name.renderPrompt({ name: 'work-agent' })when the file iswork.md. - Missing build copy. You edited or added a template but didn’t run
npm run build, sodist/dashboard/prompts/is stale. Rebuild. - No
prompts/next to the bundle. The loader resolvesprompts/relative to its own module directory (__dirname), not the working directory. If a script bundles the loader somewhere else, check that aprompts/directory sits next to that bundle.
A variable renders as an empty string
Mustache renders a variable that isn’t invars as an empty string, with no
error. The loader only rejects keys that are passed but undeclared, and
required keys that are missing. It never scans the body, so a {{VAR}} that
the frontmatter doesn’t list renders empty when the call site doesn’t pass
it.
Declare the variable in the frontmatter (requires if the content must be
there, optional if it may be left out) and pass it from the call site.
Passing it without declaring it fails with “was passed unknown variables”.
A Mustache section renders when it shouldn’t
Check whether the value you’re passing is actually falsy by Mustache’s rules. Empty string: falsy.0: falsy. false: falsy. null /
undefined: falsy. An empty array: falsy. An empty object: truthy, so
the section will render. This trips people up when they pass
{ some: 'object' } expecting the section to hide.
If you want a section to hide on “nothing to say”, pass an empty string,
not an empty object.
Still stuck? Ask on the Overdeck Discord or file a GitHub Issue.
Further reading
- Implementation:
src/lib/cloister/prompts.ts: the full loader (~180 lines). - Templates:
src/lib/cloister/prompts/: the current catalogue. - Tests:
src/lib/cloister/__tests__/prompts.test.ts: loader contract tests + live smoke tests. - Build pipeline:
docs/BUILD.md: how templates are copied into the bundled dashboard. - Mustache.js: github.com/janl/mustache.js: canonical reference for section syntax, context fall-through, and the set of things we deliberately don’t use.