Skip to main content
Version: v5.7.1

opschain context use

Included from Basic tier

opschain context use <name>

Switch the active context to a defined one and persist the choice to $OPSCHAIN_HOME/contexts.json. The reserved name local clears the active context, returning to local mode:

opschain context use production
Switched to context production
Wrote /opt/opschain/contexts.json (home: from OPSCHAIN_HOME)

opschain context use local
Switched to context local
Wrote /opt/opschain/contexts.json (home: from OPSCHAIN_HOME)

The second line names the contexts file written and how its home was chosen (from --home, from OPSCHAIN_HOME, the per-OS default): the switch applies only to commands that resolve the same home — a shell with a different OPSCHAIN_HOME (or none) keeps its own active context. -q suppresses both lines. Switching does not touch stored credentials — the token recorded by opschain login for that server is picked up again as soon as the context is active. Note that --server and OPSCHAIN_SERVER still outrank the active context on any later command, and --local outranks everything; when OPSCHAIN_SERVER is set, the switch warns on stderr that it takes precedence.

An undefined name errors with context "<name>" is not defined — the full message names the opschain login invocation that both logs in and records the context (exit 1).

Exit codes: 0 on success, 1 for an undefined name or a contexts file that cannot be read or written, 2 for a missing argument.

See also​

  • opschain docs cli/context-list — what can be switched to.
  • opschain docs cli/login — define a context.