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, unsupported dynamic syntax, 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 are P1. They should execute
through ExecutionPort, carry trace/span IDs, obey timeout/output limits,
and require permission before execution. In P0 they fail closed with a clear
unsupported-dynamic-syntax diagnostic when invoked.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.! dynamic shell syntax fails closed in P0.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.!`command` through ExecutionPort with permission prompts,
timeout, cancellation, output truncation, and trace spans.P2:
/skill autonomous loading separate from user-invoked /command.