Home AIOpenCode: An AI Coding Agent Like Claude Code, But For Any LLM

OpenCode: An AI Coding Agent Like Claude Code, But For Any LLM

OpenCode is a Flexible Claude Code Alternative for AI Coding in the Terminal.

By sk
Published: Updated: 2.6K views 8 mins read

Are you a programmer looking for a smarter, faster way to write code? Imagine having an AI coding assistant right inside your computer's terminal window. That's exactly what OpenCode offers! It is a Claude Code–like AI agent that works with any LLM.

In this post, we will discuss what OpenCode is, explore its features, and how to install and use OpenCode in Linux.

What is OpenCode?

OpenCode is an AI coding agent built for your computer's terminal. You can think of it as a helpful assistant that understands and writes code directly within your terminal window.

In terms of capability, OpenCode is very similar to Claude Code. Unlike Claude Code, which is coupled to a specific provider (Anthropic), OpenCode is not tied to any single AI provider.

OpenCode is designed to be responsive, easy to use, and can be customised with different looks (themes).

A key feature is that it automatically loads the correct Language Server Protocols (LSPs), which helps the AI make fewer mistakes when writing code.

OpenCode is very flexible because it supports over 75 different Large Language Model (LLM) providers through a system called Models.dev.

For those wondering, Models.dev is an open-source database that contains details like specifications, pricing, and features of many AI models.

OpenCode can also use models you run on your own computer. This means you are not limited to one AI company.

It is a 100% open-source project and is licensed under the MIT license.

Key Features

OpenCode ships with several key features that make coding simpler and more efficient:

  • Native Terminal Interface: OpenCode works directly in your terminal, providing a smooth and responsive experience. You can even change its look with different themes to match your preference
  • Smarter Code, Fewer Mistakes: It automatically finds and uses the right Language Server Protocols (LSPs). LSPs are like smart tools that help the AI make fewer mistakes when writing code.
  • Multiple AI Assistant Support: You can have many AI assistants working at the same time on different parts of your project.
  • Share Your Work: If you need to share your session with a colleague or ask for help, OpenCode lets you create special links to your coding sessions.
  • Work with Any AI Model: OpenCode is not tied to one company's AI. It can work with many different AI providers and models. While Anthropic is often recommended, OpenCode can use models from OpenAI, Google, Amazon Bedrock, Azure, DeepSeek, Groq, and even models you run on your own computer.
  • Client/Server Model: OpenCode has a special design called a client/server architecture. This allows the AI to run on one computer, while you can control it from another device, like a mobile phone. The terminal interface is just one way to use it.
  • Powered by Models.dev: How does OpenCode know about so many AI models? It uses Models.dev, which is an open-source database of AI model information. This database has important details like how much each model costs to use (per million tokens), its features (like if it supports tool calling or file attachments), and how much text it can understand at once (context limit). OpenCode uses this information to help you pick the right model and understand its capabilities. You can even contribute to this database to keep it updated!
  • Free and Open source: It is completely open-source, and its code is freely available on GitHub for anyone to see and improve.

Install OpenCode in Linux

You can install OpenCode using Node.js package managers like npm, Bun, pnpm, or Yarn.

For example:

npm install -g opencode-ai

You can also install OpenCode using the official installer script:

curl -fsSL https://opencode.ai/install | bash

If you're on Arch Linux, you can use Paru or Yay AUR helpers to install OpenCode.

Using Paru:

paru -S opencode-bin

Or using Yay:

yay -S opencode-bin

How to Use OpenCode

OpenCode has special commands you can type into your computer's terminal to use it.

To begin using OpenCode in your current project folder, simply type:

opencode

You can also specify a different project folder:

opencode /path/to/project

OpenCode Basic Commands

1. run [message..] command

Need a quick code snippet or an explanation without starting the full interactive tool? You can use the run [message..] command.

You can give it a prompt directly, which is useful for scripts or getting a quick answer. For example:

opencode run Explain the use of context in Go

You can use flags like --continue (-c) to pick up the last session, --session (-s) for a specific session, --share to share the session, and --model (-m) to pick a specific AI model.

2. auth [command]

OpenCode makes it easy to log into your AI provider accounts (like Anthropic or OpenAI) using auth [command]. This command helps you manage your login details for AI providers.

  • auth login: Lets you log into a provider.
  • auth list or auth ls: Shows your logged-in providers.
  • auth logout: Logs you out of a provider.

3. upgrade [target] Command

The upgrade [target] command updates OpenCode to the newest version or a specific older version.

To upgrade to the latest, run:

opencode upgrade

To upgrade to a specific version, like v0.1.48:

opencode upgrade v0.1.48

OpenCode also accepts these general flags when you run it:

  • --help (-h): Shows help information.
  • --version: Prints the version number of OpenCode.
  • --print-logs: Shows log messages in the terminal.
  • --prompt (-p): Lets you give a prompt to OpenCode.
  • --model (-m): Specifies which AI model to use, in the format provider/model.

How to Configure OpenCode

OpenCode uses a JSON configuration file to let you customise its settings. This file can be in two places:

  • Globally: In your home directory (~/.config/opencode/config.json). This is good for general settings like themes or providers.
  • Per Project: In your project's main folder (opencode.json). You can safely share this file with others using Git. This is helpful if different projects use different AI providers.

When OpenCode starts, it looks for this configuration file in your current folder or by looking up through your project's folders until it finds a Git directory.

The configuration file uses a special pattern called a "schema" (https://opencode.ai/config.json) to help your code editor check for errors and suggest options.

You can set many options in this file, including:

  • theme: Changes the look of OpenCode.
  • model: Sets the default AI model to use, for example, "anthropic/claude-sonnet-4-20250514".
  • autoshare: Automatically shares sessions (can be true or false).
  • autoupdate: Automatically updates OpenCode (can be true or false).
  • provider: Lets you add custom AI providers and their models.
  • log_level: Controls how much information OpenCode saves in its log files. Options include DEBUG (all messages), INFO (general messages, which is the default), WARN (warnings and errors), and ERROR (only errors). Log files are stored in specific folders depending on your operating system.
  • keybinds: Allows you to change the keyboard shortcuts you use with OpenCode.
  • mcp: Configures settings for MCP servers.
  • disabled_providers: A list of providers that OpenCode should not load, even if their login details are available.

Models and Providers

OpenCode uses a system called Models.dev, which is an open-source database of AI model information.

This database has details about over 75 different AI providers and their models, including their costs, features, and limits. OpenCode uses this information internally.

Models.dev helps OpenCode support many different AI models, including those you can run locally on your machine.

You can even see the details of models like Amazon Bedrock's Claude models, Anthropic's Claude models, Azure's GPT models, Google's Gemini models, and many others, along with their input/output costs and context limits.

Managing Providers

You can log into a provider and save your login details using the command:

opencode auth login

OpenCode will then load these providers from a special file on your computer (~/.local/share/opencode/auth.json).

OpenCode can also automatically load providers if it finds API keys in your computer's environment settings or in a .env file in your project.

You can see a list of all your authenticated providers by typing:

opencode auth list

Or,

opencode auth ls

To log out of a provider, you can clear its details from the credentials file using:

opencode auth logout

You can also disable certain providers in your OpenCode configuration. This stops them from loading, even if you have their login details.

Selecting Models

If you have many models, you can choose which one to use by typing /models within OpenCode.

OpenCode decides which model to use by checking your configuration file, remembering the last model you used, or picking one based on its internal priority.

Custom and Local Models

You can add your own custom providers by specifying their npm package in your OpenCode configuration. For local models, you also need to provide the baseURL where they are running.

Conclusion

OpenCode is designed to be a powerful AI coding agent right in your terminal.

It offers flexibility by supporting many different AI models and providers through Models.dev. This means you can choose the best and most cost-effective AI for your needs.

Its ability to load LSPs helps the AI write more accurate code, and features like multi-session support and shareable links make it a versatile tool for developers.

For more details, check OpenCode GitHub repository.

Related Read:

You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More