Manage Chronicle connections with Cratis CLI contexts
A Cratis CLI context is a named connection profile for a Cratis Chronicle server. Save a context for each server you work with, then switch profiles instead of retyping connection strings. A context also holds the default event store and namespace, which determine which data your Chronicle commands use.
To set up a profile, use create, then set to activate it and show to inspect its settings. A context is a local connection choice; it is not the project’s environment configuration.
Configuration File
Section titled “Configuration File”All contexts are stored in ~/.cratis/config.json. The CLI creates this file automatically when you create your first context. You can inspect its location with cratis context path.
Connection Resolution Order
Section titled “Connection Resolution Order”When the CLI resolves which server to connect to, it checks in this order:
--serverflag on the current commandCHRONICLE_CONNECTION_STRINGenvironment variable- Active context in
~/.cratis/config.json - Default:
chronicle://localhost:35000
A --server flag or CHRONICLE_CONNECTION_STRING value overrides the server saved in the active
context. If a command connects somewhere unexpected, check those overrides before changing the
profile. Event store and namespace options likewise take precedence over their context defaults.
Commands
Section titled “Commands”Lists all configured contexts. The active context is marked with an asterisk.
cratis context listUse --output plain for scripting — it emits a header line followed by one tab-separated row per context, without decorations. The columns are the current marker (* for the active context), name, server, event store and logged-in user (- when nobody is logged in):
cratis context list -o plainExample output (tabs shown as spaces):
Current Name Server Event Store User* dev chronicle://localhost:35000 default - prod chronicle://prod.example.com:35000/ orders -create
Section titled “create”Creates a new named context. The new context becomes active only when no context is active yet (or it is the only context). Running cratis for the first time in an interactive terminal already creates and activates a default context, so after that create leaves the active context unchanged and prints the cratis context set <NAME> command that switches to the new one.
cratis context create <NAME> --server <CONNECTION_STRING>Options:
| Option | Short | Description |
|---|---|---|
--server |
Chronicle server connection string | |
--event-store |
-e |
Default event store for this context (default: default) |
--namespace |
-n |
Default namespace for this context (default: Default) |
Example — local development server:
cratis context create dev --server chronicle://localhost:35000Example — staging server with a specific event store and namespace:
cratis context create staging \ --server chronicle://staging.example.com:35000/ \ --event-store orders \ --namespace ProductionSwitches to a named context, making it the active context for all subsequent commands.
cratis context set <NAME>The command validates that the named context exists before activating it. If the name does not match any stored context, it reports an error.
Example:
cratis context set prodDisplays the details of the currently active context: server address, event store, namespace, and credentials status.
cratis context showUse --output json for machine-readable key-value output:
cratis context show -o jsonExample output (plain):
Context: defaultServer: chronicle://localhost:35000Event Store: defaultNamespace: DefaultClient ID: (not set)Client Secret: (not set)Logged-in User: (not set)delete
Section titled “delete”Removes a named context from the configuration file.
cratis context delete <NAME>You cannot delete the active context or the built-in default context. Switch to a different context first, then delete the one you no longer need:
cratis context set devcratis context delete stagingThe command asks for confirmation and defaults to No. In automation or another non-interactive environment, pass --yes explicitly or the command returns a nonzero validation exit code without deleting the context.
rename
Section titled “rename”Renames an existing context. If you rename the active context, the CLI updates the active context reference automatically so you remain connected.
cratis context rename <OLD_NAME> <NEW_NAME>Example:
cratis context rename dev localPrints the absolute path to the configuration file. Useful for inspecting, backing up, or diffing the config:
cratis context pathExample output:
/Users/alice/.cratis/config.jsonset-value
Section titled “set-value”Sets an individual value on the current context without replacing the entire context.
cratis context set-value <KEY> <VALUE>Valid keys:
| Key | Description |
|---|---|
server |
Chronicle server connection string |
event-store |
Default event store name |
namespace |
Default namespace name |
client-id |
OAuth client ID for authenticated servers |
client-secret |
OAuth client secret (masked in output) |
Example — update the server URL:
cratis context set-value server chronicle://localhost:35000Example — set credentials for an authenticated server:
cratis context set-value client-id my-appcratis context set-value client-secret s3cr3tThe client secret is stored in the config file and masked whenever the CLI displays context details. Masking the output does not remove the secret from the file; treat the configuration file as sensitive when you inspect or back it up.
Once the connection is set, verify appended events to check what an application wrote, or use the other troubleshooting scenarios.