Setting up OpenCode on DCC
OpenCode is an open-source AI coding agent that can be run on a terminal. It can read, change, and run code and assist with agentic AI tasks. Unlike other coding agents like Claude or Codex, OpenCode allows connecting to any free or paid models from multiple providers (including Anthropic and OpenAI) in addition to its included free models.
OpenCode can be used on DCC, either through a SSH terminal or an Open OnDemand Jupyter/RStudio container terminal.
Once you are connected to DCC, enter the following commands on the terminal to set up OpenCode,
Then, you can launch opencode with the command,
and follow the instructions to get started.
If you have an API key from Duke's AI Gateway, create ~/.config/opencode/opencode.json with the following content and run export LITELLM_TOKEN=<your_api_token> from the terminal before you start opencode. Otherwise, replace {env:LITELLM_TOKEN} with your API token in the opencode.json file itself. Thank you, Jeremy Thornhill for sharing your configuration file.
{
"$schema": "https://opencode.ai/config.json",
"default_agent": "plan",
"permission": {
"edit": "ask"
},
"provider": {
"openai": {
"name": "OpenAI via LiteLLM",
"options": {
"baseURL": "https://litellm.oit.duke.edu/v1",
"litellmProxy": true,
"apiKey": "{env:LITELLM_TOKEN}"
}
}
}
}
Important!
If you will be using opencode to perform computationally intensive tasks, first request an interactive session on DCC and run it on that.