Introduction: Meet OpenCode

Welcome to "Foundation — Getting Started with OpenCode." In this course, we will change the way you interact with code. You might be used to writing every single character yourself or perhaps copying and pasting snippets from the web. This lesson introduces a powerful new tool called OpenCode, an autonomous coding agent that lives in your terminal.

OpenCode is designed to handle complex coding tasks independently. Instead of simply chatting with an AI, you give OpenCode a task, and it can create files, edit code, run commands, and fix errors directly in your project. By the end of this lesson, you will understand the difference between standard AI assistants and agentic AI, and you will have OpenCode installed, configured, and running on your system.

Agentic AI vs Chat-Based Assistants

To understand why OpenCode is special, we first need to look at the tools you might already know, like ChatGPT or Google Gemini. These are known as Chat-Based Assistants. When you ask them a question, they read your text and predict the best text response. They are fantastic at explaining concepts or writing a snippet of code for you to copy, but they cannot actually touch your files or run your code. You act as the middleman, moving code between the chat window and your editor.

Agentic AI, like OpenCode, works differently because it has permission to execute actions. It doesn't just suggest code; it acts on it. When you give an agent a goal, it breaks that goal down into steps. It can read your file structure, create new files, install packages, and run terminal commands to test its own work. If it encounters an error, it reads the error message and tries to fix the code automatically.

You should use Chat-Based Assistants when you need to brainstorm ideas, ask for explanations, or get a quick snippet of logic. You should use Agentic AI when you want to automate a workflow, refactor a large file, or build a feature from scratch without constantly copy-pasting code. OpenCode allows you to step back and act as a supervisor while the AI does the heavy lifting in your terminal.

Installing OpenCode

Now that you understand what OpenCode is, let's get it installed. OpenCode is a command-line tool, which means you install and run it from your terminal. While OpenCode is already pre-installed in your CodeSignal environment for the practice exercises, it is important to know how to install it on your own computer.

There are three main ways to install OpenCode depending on your setup and preferences.

Option 1: npm (Node.js)

The most common way to install OpenCode is by using npm (Node Package Manager). This is a standard tool for installing JavaScript-based software. Using the global flag (-g) ensures that the opencode command is available in every folder on your computer, not just the current one.

Output:

Option 2: Install Script

If you do not have Node.js installed, or if you prefer a standalone installation, you can download the binary directly using the official install script. This script automatically detects your operating system and downloads the correct files for you.

Output:

Option 3: Homebrew (macOS and Linux)

Configuring Your API Key

OpenCode provides the interface and the tools to edit files, but it needs a "brain" to do the thinking. This brain comes from an AI Provider, such as Anthropic (Claude), OpenAI (GPT-4), or others. Before you can use OpenCode, you must log in and connect it to one of these providers using an API Key.

To start this process, we use the authentication command. This will trigger an interactive menu in your terminal where you use the arrow keys to make selections.

The tool will ask you to select a provider. For this course, we often use Anthropic because its models are very good at coding, but you can choose whichever provider you have an account with.

Next, it will ask how you want to log in. Usually, you will select "Manually enter API Key." This requires you to go to the provider's website (like console.anthropic.com), copy your key, and paste it here.

Once you see "Credential added successfully," OpenCode is connected to the AI provider and ready to assist you.

Launching Your First Session

Now that everything is installed and configured, let's learn how to interact with the tool. Before diving into a coding session, it is helpful to see what commands are available. The --help flag is a universal standard in command-line tools that displays a manual or list of options.

Output:

To start your actual coding session, you simply type opencode (or opencode followed by a folder path). This launches the TUI (Text User Interface). This interface is where you will spend most of your time.

Output:

The TUI shows you the current agent (Build), the active model (Claude Haiku 4.5), and the provider (Anthropic). At the bottom, you can see keyboard shortcuts: ctrl+t to switch model variants, to change agents, and to open the command palette. You can also type to access slash commands like , , or to exit the program.

Summary and Next Steps

In this lesson, we established the foundation for using OpenCode. We discussed how OpenCode differs from traditional chat assistants by having the ability to execute commands and edit files directly. We covered three different installation methods using npm, the binary script, or Homebrew, then configured the tool with an API Key and successfully launched the user interface.

In the next section, you will get hands-on with OpenCode and send your first prompt to the AI agent. This practice exercise will let you experience the power of agentic coding firsthand.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal