iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🆓

Building a Free AI Agent Coding Environment on Windows 11 Using gpt-oss and OpenCode

に公開

Introduction

I built a coding environment on Windows that allows using AI agents for free by combining an open-source (OSS) version of GPT and OpenCode.

The build process follows these steps:

  • Build a local LLM on Windows using Ollama (OSS version of GPT)
  • Set up an open-source AI coding environment (OpenCode)
  • Call the local LLM from OpenCode to perform coding via AI agents

1. Building a Local LLM with Ollama and OSS GPT

■ Install Ollama from the official page

Install the Windows version of Ollama from the official page.

■ Introducing the OSS version of GPT

Open PowerShell and run the following command to set up an environment where the OSS version of GPT can run on Ollama.
*Example using gpt-oss:20b

$ ollama pull gpt-oss:20b
pulling manifest
pulling b112e727c6f1: 100% ▕██████████████████████████████████████████████████████████▏  13 GB
pulling fa6710a93d78: 100% ▕██████████████████████████████████████████████████████████▏ 7.2 KB
pulling f60356777647: 100% ▕██████████████████████████████████████████████████████████▏  11 KB
pulling d8ba2f9a17b3: 100% ▕██████████████████████████████████████████████████████████▏   18 B
pulling 55c108d8e936: 100% ▕██████████████████████████████████████████████████████████▏  489 B
verifying sha256 digest
writing manifest
success

■ Testing the OSS version of GPT

After downloading the model, you can run prompts with the following command:

$ ollama run gpt-oss:20b

After a short wait, you will be able to enter prompts as shown below:

2. Installing OpenCode

■ Download and Extract the OpenCode ZIP File from the Release Page

According to the official page, scripted installation for the Windows version is unstable, so it is recommended to use the Windows binary instead.

Download "opencode-windows-x64.zip" from the OpenCode release page.

After downloading the ZIP file, place the Exe file at the following path:

  • C:\Users<Username>.opencode\bin\opencode.exe
    *Please create the ".opencode/bin" folder manually.

■ Setting Environment Variables

After placing the Exe file, set the environment variables using the following commands:

New-Item -ItemType Directory -Force "$HOME\.opencode\bin" | Out-Null
setx PATH "$env:PATH;$HOME\.opencode\bin"

Note: You can also manually set the following environment variable:

  • C:\Users<Username>.opencode\bin

■ Verify the OpenCode Installation

Run the following command; if the version is displayed, the installation was successful.

$ opencode --version
0.5.8

3. Let's Try OpenCode

■ Preparation 1: Creating Configuration Files

Now, let's try vibe coding using OpenCode.

Create a project folder of your choice and place the following files directly inside it.

Project folder

  • AGENTS.md
  • opencode.json

AGENTS.md

This file defines the rules for OpenCode to follow when executing prompts.

# Tooling rules for OpenCode
- Use OpenCode tools only: read, write, edit, list, glob, grep, webfetch, bash, task, todowrite, todoread.
- Do NOT call non-existent tools like Repo_browser.\* .
- Prefer `edit` for modifying existing files; use `read` to inspect before editing.

opencode.json

This is the configuration file for vibe coding with OpenCode.

{
  "$schema": "https://opencode.ai/config.json",

  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama (local)",
      "options": {
        "baseURL": "http://localhost:11434/v1"
      },
      "models": {
        "gpt-oss:20b": { "name": "gpt-oss 20B (local)" }
      }
    }
  },

  "model": "ollama/gpt-oss:20b",

  "agent": {
    "build": {
      "description": "Default coding mode with only OpenCode tools.",
      "tools": {
        "read": true,
        "write": true,
        "edit": true,
        "bash": true,
        "grep": true,
        "glob": true,
        "list": true,
        "webfetch": true,
        "patch": true,
        "todoread": true,
        "todowrite": true
      },
      "prompt": "{file:./AGENTS.md}"
    }
  },

  "instructions": ["AGENTS.md"]
}

■ Preparation 2: Starting Ollama

To use OpenCode, you need to have Ollama running. (To enable integration with the OSS version of GPT)

Run the following command to check if Ollama is running.

$ Get-Process -Name ollama -ErrorAction SilentlyContinue
Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    267      20    51992      55004       0.19  30512   1 ollama

If no process is displayed, start Ollama with the following command:

$ ollama serve

■ Trying OpenCode

Thank you for waiting. Let's try out OpenCode.

While in any project directory, run the following command.
Note: Please ensure the directory name does not contain any Japanese characters.

$ opencode

It is successful if the following screen appears.

This time, we will use the following prompt to have it create a maze exploration game.
Note: "\n" is intentionally included because pasting with line breaks will execute the prompt.

You are in OpenCode. Do not use todowrite/todoread. \nUse only: read, write, edit, list, glob, grep, webfetch, bash, patch, task. \nGoal: Create a simple maze exploration game using HTML, CSS, and JavaScript Files to create (use the write tool): \n1) index.html \n2) style.css \n3) main.js\n\nUse the write tool with both filePath and content.\nExample:\n{ \"filePath\": \"index.html\", \"content\": \"<!doctype html>...\" }\n\nNow create index.html, style.css, and main.js for the maze game.


When executed, OpenCode × OSS GPT will automatically devise a creation plan and start building the game.

Finally, when I opened the HTML file created by OpenCode in a browser, the maze exploration game was created without any issues!

Appendix

■ Integrating with Other Models

By running the following command, you can integrate with models provided by various providers.

$ opencode auth login

┌  Add credential

◆  Select provider

│  Search: _
│  ● Anthropic (recommended)
│  ○ GitHub Copilot
│  ○ OpenAI
│  ○ Google
│  ○ OpenRouter
│  ○ Vercel AI Gateway
│  ○ Alibaba
│  ...
│  ↑/↓ to select • Enter: confirm • Type: to search

Example: Integrating OpenCode with GitHub Copilot

If you select "GitHub Copilot", you can integrate it by following the instructions in PowerShell.

┌  Add credential

◇  Select provider
│  GitHub Copilot

●  Go to: https://github.com/login/device

●  Enter code: XXXX-XXXX

◇  Login successful

└  Done

Check the model in OpenCode to confirm that it is integrated with GitHub Copilot.

Discussion