OpenCode is an open-source AI coding agent that runs in your terminal and lets you analyze and refactor a Python project through conversational commands. In this guide, you’ll install it on your system, set it up with a free Google Gemini API key, and learn the basics of how to use it in your daily programming work.
Here’s what OpenCode’s main interface looks like:

OpenCode works as a conversational assistant you explicitly direct. Ask it to analyze functions, refactor code, or explain issues. Press Enter to send your query, and you’ll get a response with full awareness of your project context. It supports more than seventy-five AI providers, including Anthropic, OpenAI, and Google Gemini.
If you’re a Python developer who prefers working in the terminal, OpenCode offers deliberate, context-aware assistance and a customizable AGENTS.md configuration file.
Prerequisites
Before you start working with OpenCode, you’ll need to fulfill the following prerequisites regarding your current system and working environment:
- Python 3.11 or higher for the sample project
- A modern terminal emulator
You also need an AI provider account. In this guide, you’ll use Google AI Studio to get a free Gemini API key. The free Gemini tier lets you follow along without any additional costs. However, you can also use Anthropic, OpenAI, or GitHub Copilot if you already have subscriptions to those services.
This guide uses a sample project consisting of a dice-rolling script. You’ll find the full source code in a collapsible block at the start of Step 2. The download below includes the starting script and the final refactored version so you can compare your work when you’re done:
Get Your Code: Click here to download the free sample code you’ll use to learn about AI-assisted Python coding with OpenCode.
You’ll also need some background knowledge of Python programming and basic experience with your operating system’s terminal or command line.
Step 1: Install and Set Up OpenCode
It’s time to install OpenCode and get it talking to a model. You’ll install the tool on your system, authenticate with Gemini using a free API key, configure a default model, and verify that OpenCode responds correctly to your Python questions before you start coding with it.
Install and Launch OpenCode
The quickest way to install OpenCode is to use the official installation script, which you can do with the following command:
$ curl -fsSL https://opencode.ai/install | bash
This script detects your platform, downloads the appropriate binary, installs the tool, and adds it to your PATH.
If you prefer a package manager, you can also install OpenCode with Homebrew on macOS or Linux:
$ brew install anomalyco/tap/opencode
Note that the Homebrew team maintains the official formula and updates it less frequently than the installation script above.
Alternatively, you can install it as a Node.js package using npm if you already have this tool on your system:
$ npm install -g opencode-ai
If you’re on Windows, the best experience comes from using WSL (Windows Subsystem for Linux). Set up WSL first by following Microsoft’s WSL installation guide, then open a WSL terminal and run the curl command above. For optimal performance, you should store your project within the WSL filesystem rather than on a Windows drive.
Note: To learn how to set up a Windows machine for working with Python, check out Your Python Coding Environment on Windows: Setup Guide.



