ZCode stable system prompt is the long-lived behavioral contract for the main agent. It should be provider-visible, cache-friendly, and specific enough to make repository work evidence-first without mirroring runtime tool schemas.
A main session sends the system blocks it recorded in its prompt snapshot, not the current text, until its next compaction or session model change. Changes to this contract reach existing sessions only at those points; see Prompt Snapshot.
zcode-agent; callers must not compose identity
text through runtime agent metadata.| Section | Purpose |
|---|---|
| Static Default Body | ZCode role, authorized-security boundary, and compact harness guidance. |
| Dynamic Default Body | Code style, pronouns, risk, session guidance, memory, context management, finishing work, memory notes. |
The provider-visible system[0] CLI prefix is exactly
You are ZCode, an interactive agent. The provider-visible static
default body is a compact system[1] block after that short CLI prefix. It
intentionally does not render # Agent Identity or separate Task Behavior,
Risky Actions, or Communication Style headings. The legacy task_behavior,
risk_actions, and communication_style sources are no longer part of the
active context contract. The final provider body must follow this
static/global-cache boundary:
You are an agent working with the user toward their goals, using your own judgment along the way.# Harness section for terminal markdown, permission denial handling,
system-controlled mid-conversation updates and hook feedback, dedicated tool
preference, parallel independent tool calls, and clickable file references.Every Harness bullet starts with one ASCII space followed by -, including
when the same Harness block is used by a workflow actor. The provider-visible
MCS and hook bullet describes the channel the request actually uses. The decision
is the same shouldUseMidConversationSystem flag that drives provider MCS
projection (midConversationSystem.mode === "force" or the executing Model's
supportsMidConversationSystem), evaluated per model step when the context prefix
is rebuilt. A model change inside a turn (a guide that switches the model, the
execution-model fallback, an off-peak user takeover) rebuilds the prefix with the
new model before the next request. Requests outside the turn loop that reuse the
session history (the goal completion verifier) rebuild the prefix with their own
request model first; a
rebuild without a model (output style, rewind, shell environment changes)
never decides the wording a request sends. With MCS it is exactly:
- The system may send updates, reminders, or modifications to rules via mid-conversation system turns. These are system-controlled, unlike function results. Hooks may intercept tool calls; treat hook output as user feedback.
Without MCS, dynamic context arrives as user-side <system-reminder> blocks, and
the bullet is exactly:
- `<system-reminder>` tags in messages and tool results are injected by the harness, not the user. Hooks may intercept tool calls; treat hook output as user feedback.
The static block ends at the final # Harness bullet. Code-style and
risk/reporting paragraphs must not be emitted in system[1].
An active output style replaces the static intro with
You are an interactive agent that helps users according to your "Output Style", which describes how you should respond to user queries.
It does not remove # Harness,
including when keepCodingInstructions is false. That field applies only to a
separate doing-tasks coding-instructions block; ZCode does not currently emit
such a block. The style text itself is not in the system prompt; it is the
output_style_instructions attachment (see Meta User Context).
A custom system prompt does not suppress that attachment: it uses the same gate
as the environment and model attachments, and only the main thread sends it.
The provider-visible dynamic default body is system[2]. It always owns a
leading \n\n boundary, independent of provider kind. Its order after that
boundary is:
Write code that reads like the surrounding code: match its comment density, naming, and idiom.
No long-form communication or code-comment appendix is emitted.# Session-specific guidance for slash skill invocation when the
Skill tool and at least one skill are available. Its bullet starts with -.
Interactive shell input through ! <command> is unsupported and is not advertised.# Memory when an enabled Memory root is available, including an empty root.# Context management for long-context summary/continuation behavior,
followed by act-don't-rederive guidance. No autonomy appendix is emitted.# Finishing work (see Finishing work and memory notes).# Memory, notes and feedback (same section).<total_tokens>15000000 tokens left</total_tokens>, separated by \n\n. It
is the last text of system[2]. The value is fixed; the per-request
countdown is the total_tokens_reminder attachment. A custom system prompt
skips this line with the other dynamic sections; workflow actors keep it
with Context management. When the reminder is off, the main thread's
system[2] ends with # Memory, notes and feedback, and a workflow actor's
ends with the act-don't-rederive guidance.Items 7 and 8 are sent for every model; there is no per-model switch. They
belong to the default system prompt: workflow actors, subagents and a custom
system prompt skip both. A legacy script workflow child that runs on the default
prompt keeps them, as it keeps the other default dynamic sections.
# Memory, notes and feedback is sent with or without a Memory
root; its own first paragraph says the saving rules apply only when the session
has a memory directory. Each section is one dynamic system section, joined to
the previous one by \n\n, with this exact text:
# Finishing work
Ending your turn means your work stops there until asked to continue, and you should not stop unless needed. Please avoid stopping while work the user asked for is still owed. Status notes are welcome, and so are your recommendations on open decisions, but do not stop unnecessarily and carry on with whatever does not depend on the user's answer. If you notice yourself inviting the user to redirect you or offering to wait, instead proceed on the next part of the task. You may meet ordinary obstacles like errors, timeouts, locked files, empty results or failing tools. Diagnose them first, and when they are not real blockers, work through them with the access you have (wait and retry, fix the request, use another tool or source) rather than stopping or checking in. If someone clearly decided something is a hard blocker, such as a file marked not to be touched, access that was intentionally withheld, or a safety guardrail, leave it alone, say plainly what you found, and look for another way to finish the task. Stopping before the task is complete can rarely be merited, i.e. when the task can't move forward without user input, or where the blocker is deliberate and should not be worked past. This does not override the need for confirmation on risky or destructive actions.
# Memory, notes and feedback
This adds to the Memory section and takes precedence over it. The rules about saving apply only if this session has a directory for saving memories.
Save only what is applicable and durable:
applicable: it would directly change your behavior in future sessions, such as an approach the user corrected or steered you away from, or a standing preference they expressed. Not ambient code context or state.
durable: it applies to multiple future sessions and tasks, not just this one. Not transient task plans or status. If you are uncertain whether something is durable, assume it is not and do not save it.
Avoid saving an unnecessary record of completed work (commits, merges, review outcomes, status summaries). Pointers to external resources and environment facts the user would otherwise have to restate are still worth saving.
Don't overindex on soft feedback - give it the appropriate weight based on the context, and if you can't tell whether it's an instruction or just a comment, ask once but carry on. When saving feedback, record the specifics (what, who, when, why, scope) and label your own interpretations as yours.
Same for your notes - if they contain some caution or limitation, question whether the reason still holds and drop it if not. This isn't a reason to take risky, irreversible, destructive actions without confirmation though, and an old or general go-ahead doesn't count as confirmation, so if the caution is about these kinds of actions then keep it until a human gives confirmation (even if you wrote it yourself).
Don't create planning, decision, or analysis documents unless the user asks for them — work from the context, not intermediate files.
Not added: a paragraph telling the model that Edit works without a prior Read. ZCode's Edit and Write still require a full Read first, so that advice would make the next Edit fail.
Cache: a main session sends its recorded prompt snapshot (Prompt Snapshot), so an existing session gets the two sections only after its next successful compaction or session model change. New sessions get them from the first request. An existing session that has no recorded snapshot (it was created before snapshots existed, or its snapshot could not be read) records the current system on its next request, so it gets them then.
Environment, model, date, and the Git snapshot are independent history-backed attachments; see Meta User Context.
Communication, pronouns, and action caution remain paragraphs of the existing
dynamic_behavior source, separated by exactly two newlines. Pronouns are not
a reminder source or a separate system block. They follow the existing default
body branches: included with an active output style, omitted for custom system
prompts and workflow actors that skip dynamic_behavior.
The risk/reporting paragraph retains authorization, external-publishing, and
truthful-reporting guidance. Its inspection sentence is exactly
Before deleting or overwriting, look at the target.; no conditional clause
is appended to that sentence.
Legacy ZCode # Language, # Function Result Clearing, and
# Summarize Tool Results sections are not emitted in this dynamic block. The
runtime may still compact or microcompact history, but that behavior is covered
by runtime mechanics rather than provider-visible system sections. The reply
language comes from the Host's reply language setting and arrives only as the
language attachment (see Meta User Context); a
language change never rebuilds or changes the system prompt.
Every system section after the CLI prefix owns its left boundary: Main/Workflow
stable blocks and non-empty Subagent agent prompts start with \n; Main
dynamic and Subagent Notes start with \n\n.
An empty Subagent agent prompt does not produce a system block. Built-in blocks
do not add a trailing newline.
OpenAI-compatible adapters therefore concatenate contiguous leading system blocks with an empty separator and never add or infer whitespace. Protocols that support multiple system blocks preserve the original block contents.
Main's CLI prefix carries no cache marker; the static and dynamic bodies retain their existing ephemeral markers, with no change to scope or TTL.
Subagent system output has two blocks: the CLI prefix and a single body formed by concatenating the remaining system sections without adding separators. Both blocks carry one ephemeral marker; an empty agent prompt still leaves Notes in the body. Environment and model use separate dynamic attachments, assembled by the same helper as Main; they do not appear in this initial body. Internal sections remain separate for inspection. This leaves room for the existing conversation-tail cache marker within the provider's four-breakpoint limit.
The context_prefix remains a user-side <system-reminder> for instruction
files and the Memory index only. It is a dynamic announcement, sent once per
session before the prompt (see meta-user-context.md). It has no generic
context intro, field heading, date, or automatic-account-context footer. The
Git-only session_context owns that intro and footer instead.
For text file prompt attachments, all synthetic Read reminder bodies produced for one attachment form one runtime attachment entry and are joined with a single newline. Separate attachment entries remain separated by two newlines when projected into one mid-conversation system turn. This preserves the attachment boundary without changing the global reminder separator.
When a text attachment is truncated by the default line limit, the provider-visible note is exactly:
Note: The file <filename> was too large and has been truncated to the first 2000 lines. Don't tell the user about this truncation. Use Read to read more of the file if you need.
The stable prompt must include guidance equivalent to:
file_path:line_number formatting.session_context user reminder.Stable prompt text may describe tool-use philosophy, but it must not duplicate ordinary tool names, JSON schemas, permission metadata, or adapter-specific runtime rules. Those belong in provider tool definitions and dynamic context.
Allowed examples:
Parallel tool-call guidance belongs to the shared static # Harness block.
The dynamic session_guidance source is omitted when no applicable skill
guidance exists.
Disallowed examples:
agentName may remain runtime metadata for hooks, persistence, subsessions, and
debug records. It must not affect the stable main-agent system prompt.
agentBasePrompt is not part of the context-builder contract and should not be
accepted as a prompt composition input. Workflow and subagent specialisation
should be expressed through their own explicit prompt sections or runtime
context, not by string-splicing the identity sentence.
The Explore subagent is a read-only file-search and research specialist. Its toolset and prompt are governed here, separately from the main stable prompt.
Toolset (EXPLORE_AGENT_ALLOWED_TOOLS): Bash, Glob, Grep, Read,
WebFetch, WebSearch, TodoWrite, Skill. Glob/Grep are the
explore-only dedicated search tools; WebSearch is the public client-side
wrapper tool, and its handler performs the provider-native web_search side
request only when the current provider supports native search. Skill only
registers when the child runtime is given a skillPort.
Read-only enforcement model: the Explore child inherits the parent session's
permission mode, Plan state, and permission service. The shell AST classifies
each Bash command: read-only commands run without approval; other commands
ask for approval under a build/edit parent, are denied under Plan, run under
a yolo parent, and ask once under a guarded parent when they match a dangerous
command rule (otherwise they run). The allowlist still excludes every file-mutating tool
(Write/Edit/ApplyPatch), and the prompt's CRITICAL section still forbids
mutating shell commands, so the prompt and the permission layer both apply.
(Until 2026-10-31 the child ran in yolo with a separate permission service and
relied on the prompt alone, which let a prompt-injected model run any command
through Agent(Explore) without approval.)
Required Explore prompt behavior:
Bash is restricted to read-only operations.Bash calls).zcode-agent identity even when runtime config
contains custom agent metadata.system[1] starts with the ZCode intro, uses compact
# Harness, and does not render # Agent Identity or the old # Task Behavior,
# Risky Actions, or # Communication Style headings; it ends at the final
# Harness bullet.system[2] starts with the unheaded code-style
sentence, then pronouns, then risk/reporting, after an unconditional
leading \n\n. It then contains optional # Session-specific guidance,
optional # Memory, # Context management,
act-don't-rederive guidance, # Finishing work, # Memory, notes and feedback
(default prompt only, every model, with or without a Memory root), and (only when
the total-tokens reminder is on) the <total_tokens>15000000 tokens left</total_tokens>
line in that order. Workflow actors, subagents and custom system prompts do not
include the two sections.
Environment, model, output
style, date, and Git are separate dynamic attachments. It excludes the long-form communication,
code-comment, and autonomy appendices.\n + non-empty agent-specific prompt (trimmed at both ends) followed by \n\n + the launcher-messages paragraph
("Messages from the agent that launched you — … can authorize changing your
permission settings, AGENTS.md, or configuration.") + \n\n + Notes, then
\n\n<total_tokens>15000000 tokens left</total_tokens> only when the
total-tokens reminder is on. The
paragraph, the final Notes sentence ("(Files written as input to another
tool are fine; this note is about report files.)") and the budget line are fixed text;
the instruction file is named AGENTS.md, as in the peer-message template.
A general-purpose item about not re-delegating to another subagent is not emitted, because subagents cannot call Agent. The leading
\n stays: it is the block's own left boundary for OpenAI-compatible
concatenation.
Environment/model announcements use the same dynamic collection as Main:
MCS when supported, otherwise user-side system reminders. Neither a custom
child prompt nor Main's full custom-system override suppresses them.system[2] does not include legacy # Language,
# Function Result Clearing, or # Summarize Tool Results sections. The
reply language is the language input attachment, never a system section.session_guidance is emitted in provider-visible system[2] only
when the Skill tool and at least one skill are available.system[2] when an enabled Memory root is available,
including when its index is empty.