Configuration¶
Capsula is configured using a capsula.toml file. This page documents all configuration options.
Configuration File Location¶
Capsula looks for capsula.toml in the following order:
- Path specified with
--configflag - Current directory (
./capsula.toml) - Parent directories (walking up the tree)
Tip
Place capsula.toml in your project root so it works from any subdirectory.
Basic Structure¶
[vault]
name = "vault-name"
[[pre-run.hooks]]
id = "hook-type"
# hook configuration...
[[post-run.hooks]]
id = "hook-type"
# hook configuration...
Top-Level Options¶
dotenv (optional)¶
Load environment variables from a .env file.
Relative paths are resolved from the directory containing capsula.toml.
server (optional)¶
The Capsula server used by capsula push and capsula vaults. The simplest form is a plain URL:
The URL can also be set with the --server flag or the CAPSULA_SERVER_URL environment variable, which take priority over the config file (in that order). When [server.headers] is configured, an override must point at the same origin (scheme, host, and port) as the configured url — credentials are never sent to a different origin, and a cross-origin override is rejected with an error.
server.headers (optional)¶
When the server sits behind an authenticating reverse proxy (Cloudflare Access, oauth2-proxy, etc.), use the table form to attach HTTP headers to every request:
[server]
url = "https://capsula.example.com"
[server.headers]
Authorization = { env = "CAPSULA_TOKEN", prefix = "Bearer " }
Each entry becomes one HTTP header line. With CAPSULA_TOKEN=abc123 in the environment, the example above sends Authorization: Bearer abc123.
Each header value is one of three sources:
| Form | Meaning |
|---|---|
"literal string" |
Used as-is |
{ env = "VAR", prefix = "Bearer " } |
Read from environment variable; optional prefix prepended |
{ command = "..." } |
Run the command, use trimmed stdout as the value |
Common setups:
[server.headers]
# Plain bearer token against any authenticating reverse proxy
Authorization = { env = "CAPSULA_TOKEN", prefix = "Bearer " }
# Cloudflare Access, interactive user (JWT from cloudflared login session)
cf-access-token = { command = "cloudflared access token --app=https://capsula.example.com" }
# Cloudflare Access service token (CI)
CF-Access-Client-Id = { env = "CF_ACCESS_CLIENT_ID" }
CF-Access-Client-Secret = { env = "CF_ACCESS_CLIENT_SECRET" }
Commands are split with shell-like word splitting and executed directly (no shell) from the project root (the directory containing capsula.toml), and their stdout is trimmed of trailing newlines. If a command fails (e.g. an expired login session), the push aborts with the command's stderr.
HTTP redirects are never followed: a redirect (e.g. to a login page) is reported as an error instead of forwarding credentials to the redirect target.
Trust model
command entries execute arbitrary commands when you run capsula push or capsula vaults. Only use them with a trusted capsula.toml — the same caution that already applies to the capture-command hook.
Secrets
Never write secret values directly in capsula.toml. Reference them with env (combined with the top-level dotenv option if convenient), or use command sources whose credentials live with the external tool (e.g. ~/.cloudflared/).
Vault Configuration¶
The [vault] section defines where Capsula stores captured data.
name (required)¶
The vault name. Creates a subdirectory under .capsula/.
Creates: .capsula/ml-experiments/
path (optional)¶
Custom path for the vault. Can be absolute or relative.
Hook Configuration¶
Hooks are configured in two sections: pre-run and post-run.
For the configuration of each hook, refer to its specific documentation.
Pre-Run Hooks¶
Pre-run hooks are executed before your command, in the order listed. If any pre-run hook fails or errors, Capsula still runs the remaining pre-run hooks, writes pre-run.json, and then stops before running your command with exit code 125.
[[pre-run.hooks]]
id = "capture-git-repo"
name = "my-project"
path = "."
[[pre-run.hooks]]
id = "capture-cwd"
Post-Run Hooks¶
Post-run hooks are executed after your command, in the order listed. If any post-run hook fails or errors, Capsula still runs the remaining post-run hooks and writes post-run.json. For capsula run, a post-run failure makes the CLI exit with 1 when the wrapped command succeeded; if the wrapped command already failed, Capsula preserves the command's exit code. For capsula run-end, a post-run failure makes the command exit with 1 after recording post-run.json.
Hook Failures¶
Each hook either succeeds, fails, or errors:
- A hook fails when it runs but its result violates the configured policy, for example
capture-git-repofinding uncommitted changes withallow_dirty = false, orcapture-commandexiting with a status not listed insuccess_codes. The reason is recorded in__meta.failure_reason. - A hook errors when it cannot produce a result, for example when a file cannot be read or the Slack API cannot be reached. The message is recorded in
__meta.error.
Both make __meta.success false and count as a failure of the phase. Capsula runs the remaining hooks of the phase, writes the phase's JSON file, and prints each failed hook to stderr. A pre-run failure stops Capsula before your command; see Exit Status for the resulting exit codes.
Capsula checks the configuration of every hook in both phases before it creates the run. An invalid hook configuration, such as an unknown field, makes Capsula exit with status 1 before any hook or your command runs, and no run is created. Paths in a hook configuration, such as cwd of capture-command, are resolved when the hook runs, so a post-run hook can refer to a directory that your command creates.
Any pre-run failure stops the run
Every pre-run hook guards your command, including hooks that only report on it. For example, if notify-slack cannot reach Slack because of a temporary network problem, the command does not run. Put hooks that are not essential for the record of the run, such as notifications, in post-run. A post-run failure is still reported, but only after your command has finished.
Complete Example¶
dotenv = ".env"
[vault]
name = "research-experiments"
[[pre-run.hooks]]
id = "capture-git-repo"
name = "research"
path = "."
allow_dirty = false
[[pre-run.hooks]]
id = "capture-cwd"
[[pre-run.hooks]]
id = "capture-env"
name = "PATH"
[[pre-run.hooks]]
id = "capture-machine"
[[pre-run.hooks]]
id = "capture-file"
glob = "config.yaml"
mode = "copy"
hash = "sha256"
[[post-run.hooks]]
id = "capture-file"
glob = "results/*.json"
mode = "copy"
[[post-run.hooks]]
id = "notify-slack"
channel = "#experiments"
attachment_globs = ["results/*.png"]
Multiple Configurations¶
You can use different config files for different purposes: