Documentation/Command System Overview

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

NeedInterfaceExample
Inspect a configured SSH hostBuilt-in commandxec on hosts.staging node --version
Reuse a named sequenceConfiguration taskxec run check
Branch on typed results or implement recoveryTypeScript scriptxec run .xec/scripts/check.ts
Offer a validated project operationNative project commandxec deploy --help, after defining it
Embed execution in another applicationCore/Ops libraryImport 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

CommandPurpose
runRun a script, task, inline program or REPL
onExecute on SSH hosts
inExecute in a container or Kubernetes pod
copyTransfer between source and destination paths
forwardForward a port
logsRead or follow target logs
watchRun a declared action after file changes
dockerOperate Docker resources through the shared Docker API
configInspect and edit configuration
inspectInspect targets, tasks and project metadata
secretsManage values through a secret provider
newScaffold a project, script, command, task or profile
doctorInspect the local execution environment
completionGenerate 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 json

Root 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.

See Also

MADE FOR BUILDERS.Static pages. Local search. Built with Lumen + Prism.