CLI Reference¶
Complete reference for Capsula command-line interface.
Global Options¶
--config <PATH>¶
Specify a custom configuration file.
Default: Looks for capsula.toml in current directory and parent directories.
--vault-path <PATH>¶
Override the vault path. Can also be set via the CAPSULA_VAULT_PATH environment variable (after dotenv loading).
--version¶
Show Capsula version.
--help¶
Show help information.
capsula run¶
Execute a command with hook capture.
Usage¶
Examples¶
capsula run echo "Hello, World!"
capsula run python train.py --epochs 100
capsula run bash -c 'python generate.py | grep result > output.txt'
Environment Variables¶
Your command runs with these environment variables:
| Variable | Description | Example |
|---|---|---|
CAPSULA_RUN_ID |
Unique run identifier (ULID) | 01K8WSYC91YAE21R7CWHQ4KYN2 |
CAPSULA_RUN_NAME |
Human-readable run name | happy-river |
CAPSULA_RUN_DIRECTORY |
Absolute path to run directory | /path/.capsula/vault/2025-01-09/143022-happy-river |
CAPSULA_RUN_TIMESTAMP |
ISO 8601 timestamp (UTC) | 2025-01-09T14:30:22.473+00:00 |
CAPSULA_RUN_COMMAND |
Shell-quoted command string | python train.py --epochs 100 |
CAPSULA_PRE_RUN_OUTPUT_PATH |
Path to pre-run.json | /path/.capsula/.../pre-run.json |
CAPSULA_PROJECT_ROOT |
Project root directory | /path/to/project |
Example using environment variables:
If a pre-run hook fails, Capsula does not run the command. See Exit Status for how capsula run reports hook failures.
capsula run-start¶
Start a manual run: create the run directory and execute pre-run hooks.
Use this when you want to capture context before and after an external process
(e.g., a GUI-triggered analysis) that capsula does not manage directly.
The auto-generated run name is printed to stdout so callers can capture it,
then later finalize the run with run-end.
Usage¶
Example¶
# Start a manual run and capture the name
name=$(capsula run-start)
# ... perform your external process ...
# Finalize the run
capsula run-end "$name"
If a pre-run hook fails, run-start exits with status 125 and prints no run name, so check its exit status before starting the external process. The run directory and pre-run.json are still written so that you can inspect the failure. See Exit Status.
run-start also checks the configuration of the post-run hooks, so that a mistake in it is reported before you start the external process rather than by run-end.
capsula run-end¶
End a manual run: execute post-run hooks for an existing run.
Finalizes a run previously started with run-start. This command will fail
if the run has already been finalized (i.e., post-run.json already exists)
or if any post-run hook fails. In the latter case the run is still finalized:
post-run.json records the failure, and running run-end again fails because
the run has already been finalized. See Exit Status.
run-end refuses a run whose pre-run hooks failed, because run-start
stopped that run before it was started. It runs no post-run hook for such a
run.
Usage¶
Example¶
capsula list¶
List all captured runs.
Usage¶
Output Format¶
TIMESTAMP (UTC) NAME COMMAND
---------------------------------------------------------------------------------------------
2025-01-09 14:30:29 happy-river echo hello
2025-01-09 14:30:28 clever-mountain python script.py
2025-01-09 14:30:26 quiet-lake cargo build --release
capsula show¶
Show detailed information about a specific run, including metadata, command result, and hook summaries.
Usage¶
Options¶
| Option | Description |
|---|---|
--json |
Output the full run data as JSON |
Example¶
$ capsula show happy-river
Run: happy-river
ID: 01K8WSYC91YAE21R7CWHQ4KYN2
Timestamp: 2025-01-09 14:30:22 UTC
Command: python train.py --epochs 100
Directory: /path/.capsula/vault/2025-01-09/143022-happy-river
Result: exit 0 (1.23s)
Pre-run hooks:
[ok] capture-git-repo
[ok] capture-env
Post-run hooks:
[ok] capture-file
A hook that failed or errored is shown with its reason. When a pre-run hook
failure stopped the run, there is no Result: line because the command did
not run:
$ capsula show quiet-lake
Run: quiet-lake
ID: 01K8WSYC91YAE21R7CWHQ4KYN3
Timestamp: 2025-01-09 14:35:10 UTC
Command: python train.py --epochs 100
Directory: /path/.capsula/vault/2025-01-09/143510-quiet-lake
Pre-run hooks:
[FAILED] capture-git-repo: repository has uncommitted changes
[ok] capture-env
Runs recorded by Capsula v0.15.1 and earlier
capsula show displays hook results as they were recorded. Earlier
versions recorded a hook that stopped the run by policy (for example,
capture-git-repo with allow_dirty = false on a dirty repository) as
successful, so it is shown as [ok]. They also omitted the hook ID from
hook errors, so such a hook is shown as [FAILED] unknown. To tell whether
the command of such a run was executed, check whether
_capsula/command.json exists.
capsula run-dir¶
Print the run directory for a run name.
Usage¶
Example¶
capsula push¶
Push run data to a capsula server.
Runs restored by capsula pull (marked with
_capsula/pulled.json) are lossy reconstructions: a direct push of one is
refused, and push --all skips them.
Usage¶
Options¶
| Option | Description |
|---|---|
--all |
Push all runs in the vault |
--server <URL> |
Server URL (can also be set via CAPSULA_SERVER_URL env var or server field in capsula.toml) |
Examples¶
# Push a single run by name
capsula push happy-river
# Push a single run by ID
capsula push 01K8WSYC91YAE21R7CWHQ4KYN2
# Push all runs
capsula push --all
# Push to a specific server
capsula push happy-river --server https://capsula.example.com
capsula pull¶
Download a run from a capsula server and restore it to the local vault.
The run is restored at {YYYY-MM-DD}/{HHMMSS}-{name}, using the same layout as a locally created run. Downloaded files are verified against their recorded sizes and SHA-256 hashes. Absolute paths and paths containing .. are rejected.
Where the run lands depends on its vault:
- Runs of the configured vault go into the configured vault directory (
[vault] pathincapsula.toml). - Runs of another vault go into that vault's default location,
.capsula/<VAULT>/under the project root, because the configured path describes the configured vault only. - A
--vault-path <PATH>override (orCAPSULA_VAULT_PATH) always wins and is used as the destination for either vault.
The _capsula metadata is reconstructed from the server's structured data. A _capsula/pulled.json marker records the source server and pull time.
--force only replaces runs previously created by capsula pull, as identified by _capsula/pulled.json. Locally produced runs are never overwritten. Pulled runs cannot be uploaded again with capsula push.
Usage¶
Options¶
| Option | Description |
|---|---|
--vault <NAME> |
Expected vault of the run (defaults to the vault in capsula.toml). The pull fails if the run belongs to a different vault. |
--vault-path <PATH> |
Global option; restore the run into this directory instead of the vault's default location. |
--server <URL> |
Server URL (can also be set via CAPSULA_SERVER_URL env var or server field in capsula.toml) |
--force |
Replace a previously pulled copy of the run if it already exists. Locally produced runs are never replaced. |
Examples¶
# Pull a run by ID
capsula pull 01K8WSYC91YAE21R7CWHQ4KYN2
# Pull a run that belongs to another vault (restored into .capsula/other-vault/)
capsula pull 01K8WSYC91YAE21R7CWHQ4KYN2 --vault other-vault
# Pull a run into an explicit directory
capsula --vault-path /custom/vault/path pull 01K8WSYC91YAE21R7CWHQ4KYN2 --vault other-vault
# Pull from a specific server, replacing a previously pulled copy
capsula pull 01K8WSYC91YAE21R7CWHQ4KYN2 --server https://capsula.example.com --force
Limitations¶
A pulled run is a subset of the original local run. Data that was not uploaded by capsula push cannot be restored, including:
- symlinks
- empty directories
- files added after the push
- the original _capsula/*.json file contents
- sub-millisecond command duration
The reconstructed metadata may therefore differ from the original files. Phases with no hook outputs do not produce pre-run.json or post-run.json. Command strings stored by older server versions are normalized to JSON arrays.
capsula tui¶
Launch an interactive terminal UI for starting and ending runs.
The TUI provides a visual interface for managing manual runs, as an alternative
to using run-start and run-end from the command line.
Usage¶
capsula vaults¶
Manage vaults on the server.
capsula vaults list¶
List all vaults on the server.
Options¶
| Option | Description |
|---|---|
--server <URL> |
Server URL (can also be set via CAPSULA_SERVER_URL env var or server field in capsula.toml) |
Exit Status¶
capsula run exits with one of the following statuses. Following the convention of wrappers such as GNU env, timeout, and docker run, 125 means that the command was not executed.
| Status | Meaning |
|---|---|
0 |
The command exited with 0 and every post-run hook succeeded. |
| The command's status | The command exited with a non-zero status. A post-run hook failure does not change it. A command killed by signal N gives 128 + N. |
125 |
A pre-run hook failed or errored. The command was not executed. |
1 |
The command exited with 0, but a post-run hook failed or errored. Also used when Capsula itself fails, for example on an invalid configuration (detected before any hook or the command runs) or when the command cannot be started. |
capsula run-start exits with 125 when a pre-run hook fails or errors, and with 1 when Capsula itself fails. capsula run-end exits with 1 when a post-run hook fails or errors, or when Capsula itself fails.
Capsula prints each failed hook to stderr with its phase, position, and reason:
ERROR Aborting run due to pre-run hook failure:
pre[0] capture-git-repo: repository has uncommitted changes
The exit status alone cannot distinguish Capsula's statuses from the command's own, because the command may itself exit with 1 or 125. Check the run directory instead:
_capsula/command.jsonexists only if the command was executed. Itsexit_codeis the command's own status.- In
_capsula/pre-run.jsonand_capsula/post-run.json, a hook that failed has__meta.success: falsewith the reason in__meta.failure_reason, or in__meta.errorif the hook errored. See Hook Failures. capsula show <RUN_NAME>summarizes both.