ZCode should support user-defined slash commands as reusable prompt templates.
The first version follows Claude Code's legacy .claude/commands/*.md format
closely enough for common commands to migrate, while keeping ZCode's stronger
runtime boundaries: discovery and file I/O live in adapters, execution is owned
by command center, permissions stay scoped to a single invocation, and TUI/ZCode app-server
only render command surfaces.
This feature is for NL -> Code workflows such as /review, /fix-issue 123,
/commit, or /test auth. A custom command is not a new local CLI command and
does not run arbitrary UI code.
The compatible Claude Code command format stores prompt commands as markdown files:
.claude/commands/**/*.md~/.claude/commands/**/*.mddescription, argument-hint,
allowed-tools, and model.$ARGUMENTS, $1, $2, @file, and
shell injection blocks such as !`git status`.ZCode should be compatible with the stable file shape and common frontmatter, but dynamic file/shell expansion must go through ZCode adapters and permission contracts instead of being performed by ad hoc string replacement.
.zcode/commands/review.md and invoke it as /review..claude/commands/review.md and invoke it as /review
when Claude compatibility is enabled..agents/commands/review.md and invoke it as /review
when .agents compatibility is enabled./help and TUI slash suggestions list custom commands with their
description, source, and argument hint.zcode commands list lists discoverable custom commands without starting a
model turn.zcode --prompt "/review" and ZCode app-server prompt commands can invoke custom
commands that do not require terminal-only interaction./help, /model, /skill, etc. is ignored and reported as a
diagnostic rather than shadowing local control commands.P0 supports markdown prompt commands:
---
description: Review current changes
argument-hint: [scope]
allowed-tools: Read, Grep, Bash(git diff *)
model: main
---
Review the current diff for correctness, tests, and maintainability.
Scope: $ARGUMENTS
Frontmatter fields:
description: optional string. If missing, use the first non-empty markdown
line as a fallback, capped for display. Empty commands are invalid.argument-hint: optional string shown by TUI after completing /command.allowed-tools: optional comma or array list using ZCode permission rule
syntax. It can grant only invocation-scoped allowances and never overrides
global deny rules.model: optional main, lite, or configured provider/model one-turn
override. Unknown model refs fail before starting a model turn.disable-noninteractive: optional boolean. When true, omit the command from
ZCode app-server and headless command lists.Reserved P1/P2 fields:
arguments: named argument metadata.when_to_use: model-facing command discovery text.context: inline | fork: future subagent execution mode.effort: one-turn reasoning effort override.shell: shell profile for dynamic shell expansion.Plugin compatibility adds one P0-compatible field:
skills: optional comma or array list of skill names that should be loaded
before running this prompt command. The command expander renders an explicit
instruction to call the Skill tool for those names; it does not load the
skill body directly.Unknown frontmatter keys produce warnings and do not fail the command.
Allowed command names use ^[a-z0-9][a-z0-9:-]{0,63}$ after normalization.
Spaces, path separators, leading dots, and uppercase-only distinctions are not
valid. Names are case-insensitive at invocation time.
For subdirectories, ZCode uses a stable colon namespace:
.zcode/commands/review.md -> /review
.zcode/commands/frontend/review.md -> /frontend:review
This avoids collisions and matches the command-center model better than showing
two different files as the same /review.
Discovery is adapter-owned and receives workingDirectory, config, trace, and
abort signal. Core and TUI must not scan the filesystem directly.
Default roots, in priority order:
commands.roots[] from config, nearest entry first..zcode/commands/**/*.md..agents compatibility roots:
.agents/commands/**/*.md..claude/commands/**/*.md.~/.zcode/commands/**/*.md..agents compatibility root: ~/.agents/commands/**/*.md.~/.claude/commands/**/*.md.Config shape:
commands: {
enabled: boolean;
roots: string[];
metadataBudget: number;
maxCommandBytes: number;
compatibility: {
agents: boolean;
claude: boolean;
};
}
Plugin command roots are specified by plugin-compat.md.
They are projected as source: "plugin" roots and otherwise use this same
markdown command format.
No ZCODE_* environment variable is introduced for this feature. If a future
environment override is needed, it must be specified separately with precedence,
error behavior, and tests.
Add a command contract package beside skill contracts:
type CustomCommandScope = "project" | "user" | "system" | "admin";
type CustomCommandSource = "zcode" | "agents" | "claude" | "plugin";
interface CustomCommandMetadata {
name: string;
description: string;
argumentHint?: string;
path: string;
rootPath: string;
scope: CustomCommandScope;
source: CustomCommandSource;
allowedTools: string[];
model?: string;
disableNonInteractive: boolean;
frontmatterKeys: string[];
}
interface CustomCommandPort {
discoverCommands(request, options): Promise<CustomCommandLoadOutcome>;
loadCommand(request, options): Promise<CustomCommandContent>;
}
The adapter returns structured diagnostics for scan failures, invalid names,
duplicate names, invalid frontmatter, and oversized files. Diagnostics are
surfaced by zcode commands list --verbose, doctor verbose output, and debug
logs.
/name args.name.CustomCommandPort.allowed-tools and
model override.The visible transcript should show the user invocation (/review auth) and a
small command-loaded marker. The full markdown body is stored as hidden
model-visible command context, not re-rendered as user chat text.
P0 expansion:
$ARGUMENTS with the raw argument tail.$1, $2, ... with parsed positional arguments.If the template does not reference $ARGUMENTS or positional placeholders
and the user supplied args, append:
User arguments:
<args>
Dynamic expansion:
@file references are P1. They should resolve through the file-system
adapter, respect workspace/path permissions, and produce attachment-style
model context rather than raw string concatenation.!`command` and fenced ! shell blocks never run while a command is
resolved, whatever its source (project, user, or plugin). Resolution stays a
pure text step: each block is rewritten into a hand-off note followed by a
fenced bash block. The note says the step comes from the /name command
file and its scope/source, not from ZCode, and asks the model to run that
exact command with the Bash tool and use its output, unless it looks unsafe
or unrelated to the user's request. The command then runs only as an ordinary
Bash tool call, so plan mode, guarded checks, permission rules, hooks, and
approval prompts all apply, and the user sees it as a tool call.`Warning!` followed by another code span
stays plain text. A fenced block starts with ```!.$ARGUMENTS / $N
substitution, so argument text is never treated as a shell block.Bash call
sets them as environment variables (see tool/04-bash.md),
so the shell expands them, including forms such as ${NAME:-default}, and
scripts started by the block can read them too:
CLAUDE_PROJECT_DIR, ZCODE_PROJECT_DIR: the session workspace root.CLAUDE_SESSION_ID, CLAUDE_CODE_SESSION_ID, ZCODE_SESSION_ID: the
session ID.${NAME} and $NAME forms, because the Bash call does not know which
plugin the step came from. This applies to plugin commands only:
CLAUDE_PLUGIN_ROOT, ZCODE_PLUGIN_ROOT, CLAUDE_PLUGIN_DATA,
ZCODE_PLUGIN_DATA, ZCODE_PLUGIN_ID, ZCODE_PLUGIN_NAME. The values come
from the installed plugin (validated manifest name, user-level install or
config paths), never from the workspace.C:\ or with
\\) is written with forward slashes. The text is parsed by the shell, and
Git Bash removes backslashes outside quotes, so an unquoted
bash ${CLAUDE_PLUGIN_ROOT}/x.sh would otherwise get a broken path. Git Bash
accepts C:/... with or without quotes.${CLAUDE_PLUGIN_ROOT:-x} or ${#CLAUDE_PLUGIN_ROOT}), or CLAUDE_SKILL_DIR / ZCODE_SKILL_DIR
(commands have no skill directory). It becomes a note that names the
variable, so the shell never expands it to an empty string.Bash call runs in the session's current
directory, which can differ from the workspace root after an earlier cd;
scripts do not get plugin variables from their environment; a plugin path
that contains $ or a backtick is expanded again by the shell, and an
unquoted path with spaces is split; headless -p
runs have no approval surface, so non-read-only blocks are denied unless the
mode or allow rules permit them.allowed-tools is not a way for a repository file to bypass user policy.
allowed-tools directly when the
permission service accepts the rule syntax.allowed-tools require trust/approval before the
scoped allowlist is applied. In non-interactive mode, lack of approval is a
command error rather than silent fallback.allowed-tools entries are diagnostics and are not applied.This keeps the convenience of the compatible command format while preserving ZCode's audit and permission broker model.
TUI:
/name, argument-hint, short description, and a source suffix
such as project/zcode or user/claude./name for custom commands./commands can show
diagnostics.ZCode app-server:
available_commands_update.disable-noninteractive: true./help includes only ZCode app-server-advertised built-ins and compatible custom
commands./model,
/resume, or /mcp through custom command discovery./goal, /workflow, /compact, /init and the app-only /plan) plus
discovered compatible custom prompt commands.
UI clients must not rebuild this list from app-side command services.source: "builtin" | "custom" so clients
can keep hiding unsupported built-ins while still showing user-defined
commands returned by the agent. Older rows without source are treated as
built-in rows for compatibility./init, /workflow) are expanded by
bootstrap/src/builtin-prompt-command.ts before custom-command lookup runs;
the custom resolver returns "not found" for every reserved name, so a custom
workflow.md can neither shadow the built-in nor bypass a feature gate on it.CLI:
zcode commands list: human list of custom commands.zcode commands list --json: structured metadata and diagnostics.zcode commands inspect <name>: show resolved metadata and file path; body is
shown only with --verbose.Each invocation emits structured runtime/session events:
custom_command_discovered for debug-only discovery summaries.custom_command_invoked with command name, source, scope, path hash, and
whether scoped permissions/model override were requested.custom_command_expanded with body byte count, argument count, dynamic
expansion count, and redacted diagnostics.Logs must not include full command body, full arguments for sensitive commands, API keys, or shell output beyond existing adapter truncation rules.
Minimum test coverage:
.zcode/commands, .agents/commands, and
.claude/commands with deterministic priority.description, argument-hint, allowed-tools, model,
and disable-noninteractive.$ARGUMENTS and $1/$2 expansion work with quoted args on Windows, macOS,
and Linux.! shell blocks are rewritten into Bash hand-off notes that name their
source and resolve plugin variables (Windows paths with forward slashes),
and are never executed during resolution; argument text is not rewritten.allowed-tools is scoped to one command invocation and respects deny rules.zcode --prompt "/custom args" expands and submits a normal runtime turn.zcode commands list --json.P0:
zcode commands list and inspect.$ARGUMENTS, positional args, scoped
allowed-tools, and one-turn model.P1:
@file references through the file-system adapter.P2:
/skill autonomous loading separate from user-invoked /command.