Command System Overview
Xec gives a project one operator interface for local and remote execution. Start with a built-in command for a single operation. Keep reusable orchestration in TypeScript or configuration, and expose a native command when it needs its own arguments, options and help.
Choose an interface
| Need | Interface | Example |
|---|---|---|
| Inspect a configured SSH host | Built-in command | xec on hosts.staging node --version |
| Reuse a named sequence | Configuration task | xec run check |
| Branch on typed results or implement recovery | TypeScript script | xec run .xec/scripts/check.ts |
| Offer a validated project operation | Native project command | xec deploy --help, after defining it |
| Embed execution in another application | Core/Ops library | Import the API in that application |
There is no built-in universal deploy, build or test command. Projects own
those definitions. For example, this repository's Xec tasks invoke Turbo to retain
its package graph and cache; Xec owns the surrounding workflow and operator CLI.
Built-in commands
| Command | Purpose |
|---|---|
| run | Run a script, task, inline program or REPL |
| on | Execute on SSH hosts |
| in | Execute in a container or Kubernetes pod |
| copy | Transfer between source and destination paths |
| forward | Forward a port |
| logs | Read or follow target logs |
| watch | Run a declared action after file changes |
docker | Operate Docker resources through the shared Docker API |
| config | Inspect and edit configuration |
| inspect | Inspect targets, tasks and project metadata |
| secrets | Manage values through a secret provider |
| new | Scaffold a project, script, command, task or profile |
| doctor | Inspect the local execution environment |
| completion | Generate shell completion |
Use the pinned installation, for example pnpm exec xec, so the local terminal,
CI and AI agents use the same version. The installed command's --help is the
option reference for that version.
Command structure
pnpm exec xec [global-options] <command> [command-options] [arguments]
pnpm exec xec --cwd ./project config validate
pnpm exec xec run .xec/scripts/check.ts -- --format jsonRoot flags go before the command. --config, --profile and --dry-run are
command-specific, not universal root controls. -- separates a script's own
arguments from Xec's options.
Command resolution
A task may also be invoked by its name (xec check) when no registered command
owns that name. xec run check makes task intent explicit. Built-in and dynamic
commands take precedence over the task shorthand. To run a local executable
unambiguously, use xec -- <executable> [arguments]. Current source preserves
literal argv and bypasses project discovery for this form; remote execution
requires an explicit on, in or task target.
Native project commands
Put JavaScript or TypeScript files under .xec/commands/. Export
command(program), setup(program) or a default registration function. Register
arguments, options, subcommands and actions with the supplied Commander program.
That schema supplies parsing and generated help; do not add a forwarding command
and a second parser behind it.
Project code can use Xec scripting globals and public Core/Ops APIs. Do not import Xec's private CLI base classes. See custom commands for registration and discovery.
Targets and concurrency
pnpm exec xec on "hosts.*" node --version
pnpm exec xec on "hosts.*" node --version --parallel --max-concurrent 4
pnpm exec xec copy --recursive ./assets/ hosts.staging:/srv/example/assets/Parallel execution
on is sequential by default; request bounded parallelism for independent
operations. Quote target patterns so the invoking shell does not expand them.
Qualified names such as hosts.staging, containers.worker and pods.api avoid
ambiguity. A copy command takes two endpoints, not a source, target and destination
as three separate arguments.
Plans, output and failure
Preview
Use a command's supported --dry-run before an effect when useful. It is a
preview contract owned by that command, not a sandbox for arbitrary code.
Current source refuses load-time command evaluation during supported dry runs;
published 0.12.0 does not contain all of those protections.
Output and exit status
Machine-readable output is also command-specific. For example,
xec config --output json validate returns one validation document. A generic
output flag cannot turn a script's arbitrary stdout into a structured receipt.
A lost SSH response or local timeout does not prove that a remote effect never occurred. Inspect the same operation and its target state before retrying. For handled failures and cancellation see exit codes.