Skip to content

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.

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.

When the CLI resolves which server to connect to, it checks in this order:

  1. --server flag on the current command
  2. CHRONICLE_CONNECTION_STRING environment variable
  3. Active context in ~/.cratis/config.json
  4. 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.

Lists all configured contexts. The active context is marked with an asterisk.

Terminal window
cratis context list

Use --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):

Terminal window
cratis context list -o plain

Example output (tabs shown as spaces):

Current Name Server Event Store User
* dev chronicle://localhost:35000 default -
prod chronicle://prod.example.com:35000/ orders -

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.

Terminal window
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:

Terminal window
cratis context create dev --server chronicle://localhost:35000

Example — staging server with a specific event store and namespace:

Terminal window
cratis context create staging \
--server chronicle://staging.example.com:35000/ \
--event-store orders \
--namespace Production

Switches to a named context, making it the active context for all subsequent commands.

Terminal window
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:

Terminal window
cratis context set prod

Displays the details of the currently active context: server address, event store, namespace, and credentials status.

Terminal window
cratis context show

Use --output json for machine-readable key-value output:

Terminal window
cratis context show -o json

Example output (plain):

Context: default
Server: chronicle://localhost:35000
Event Store: default
Namespace: Default
Client ID: (not set)
Client Secret: (not set)
Logged-in User: (not set)

Removes a named context from the configuration file.

Terminal window
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:

Terminal window
cratis context set dev
cratis context delete staging

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


Renames an existing context. If you rename the active context, the CLI updates the active context reference automatically so you remain connected.

Terminal window
cratis context rename <OLD_NAME> <NEW_NAME>

Example:

Terminal window
cratis context rename dev local

Prints the absolute path to the configuration file. Useful for inspecting, backing up, or diffing the config:

Terminal window
cratis context path

Example output:

/Users/alice/.cratis/config.json

Sets an individual value on the current context without replacing the entire context.

Terminal window
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:

Terminal window
cratis context set-value server chronicle://localhost:35000

Example — set credentials for an authenticated server:

Terminal window
cratis context set-value client-id my-app
cratis context set-value client-secret s3cr3t

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