Skip to main content

OpenCode CLI

OpenCode is an open-source terminal AI coding agent. It works excellently with Openference.

Add the provider

Create or edit ~/.config/opencode/opencode.json:
Important: set limit.context and limit.output for every model you add. Without them, OpenCode assumes a small default context window and starts compacting the session around ~100k tokens — far below what models like GLM-5.2 (1M context) support. See Context window values below.

Authenticate

Export your key, then store credentials for the openference provider ID (must match the config key above):
Alternatively, run /connect in the TUI, scroll to Other, enter provider ID openference, and paste your key. If you use {env:OPENFERENCE_API_KEY} in config (shown above), exporting the variable is enough — you do not need a separate auth step.

Select a model

Start OpenCode and run /models to pick openference/GLM-5.2 (or another model you listed).

Verify flow

OpenCode connects by calling GET /v1/models and POST /v1/chat/completions. Openference returns an OpenAI-compatible model list filtered by key restrictions.

Model configuration

Add only the models you use. The model keys must match exactly the IDs shown on the Models page or returned by the API. GLM-5.2 is a good default to start with.

Context window values

Use these values in each model’s limit block. The context value is the safe input budget — the model’s total context wall minus output, with a small ~2% safety buffer. Models with a smaller output cap get a larger input budget. GET /v1/models also advertises each model’s context_length and max_output_tokens, so you can always look up the current values:

Notes

  • Both build and plan agents work through Openference.
  • You can switch agents with Tab and use /undo and /redo freely.
  • See the Compatibility Matrix for an overview of all clients.