Skip to main content

CLI

The Context CLI wraps the SDK into 35+ commands with dual-mode output — human-readable tables in terminals, JSON when piped. Built for both human traders and AI agents.

35+ commands

Markets, orders, portfolio, and account management

JSON output

Structured output for parsing, piping, and automation

Dual mode

Tables in TTY, JSON when piped to other tools

Gasless onboarding

Setup and deposit without ETH for gas

Install

npm install -g context-markets-cli
Requires Node.js 18+.

Quick start

Existing user

If you already have credentials saved in ~/.config/context/config.env, the CLI picks them up automatically:
context markets list --status active
Or pass credentials explicitly:
export CONTEXT_API_KEY="your-api-key"
export CONTEXT_PRIVATE_KEY="0x..."
context markets list --status active

New user

context setup
context account mint-test-usdc --amount 1000
context account deposit 1000
context markets list --status active --limit 5

Agent workflow quickstart

For non-interactive agent and script workflows, use --output json and --save to skip prompts and persist credentials:
context setup --output json --save   # generate wallet, save to config
context approve --output json         # approve contracts
context deposit 100 --output json     # deposit USDC

Setup wizard

context setup walks through account creation and onboarding. The wizard is resumable — it detects existing state and picks up where you left off.
  • Resumes from config: If ~/.config/context/config.env already exists, the wizard loads saved credentials and skips completed steps.
  • Checks approval status: If contracts are already approved, that step is skipped automatically.
  • Balance checks with retry: Shows your ETH and USDC balances, with retry loops so you can fund your wallet mid-setup without restarting.
  • --save flag: Persists the generated wallet and API key to ~/.config/context/config.env without prompting. Useful for agents and CI environments.
  • --output json support: Emits structured JSON at each step for agent consumption.

Shared config

The CLI and MCP server share a single credential store at:
~/.config/context/config.env
This file is created with chmod 600 (owner read/write only) and stores your API key and private key. Any tool that reads this file — the CLI, the MCP server, or your own scripts — gets the same credentials without duplicating secrets.

Credential loading order

Credentials are resolved in the following priority order:
  1. CLI flags — e.g. --api-key, --private-key
  2. Environment variables — e.g. CONTEXT_API_KEY, CONTEXT_PRIVATE_KEY
  3. Config file~/.config/context/config.env (chmod 600)
A flag always wins over an env var, and an env var always wins over the config file.

JSON output

Use the --output json flag or pipe to automatically get JSON:
# Explicit JSON flag
context markets list --status active --output json

# Auto-detected when piped
context markets list --status active | jq '.[0].title'

Global options

FlagEnv varDescription
--api-key <key>CONTEXT_API_KEYAPI key for authentication
--private-key <key>CONTEXT_PRIVATE_KEYPrivate key for signing orders
--chain <chain>CONTEXT_CHAINSelect chain: mainnet (default) or testnet
--rpc-url <url>CONTEXT_RPC_URLCustom RPC endpoint (defaults based on selected chain)
--base-url <url>CONTEXT_BASE_URLOverride API base URL
--output <format>Output format: table (default in TTY) or json (default when piped)
Resolution order: CLI flag > environment variable > config file (~/.config/context/config.env).

Command reference

Full reference for all 35+ commands

Agent workflows

End-to-end scripting patterns for agents