เรียกใช้ Ollama ผ่าน OpenCode

May 2026  ·  Peerapat A  ·  ← Agentic AI

Local Open WebUI for Secure Code Review

Bottom Line Up Front: You can set up a local, private AI environment for code reviews using Ollama and Open WebUI. This allows you to review sensitive source code securely without sending data to external cloud APIs.

Today I'm showcasing how to integrate Ollama with Opencode to run local AI models seamlessly.

What is Ollama?

Ollama is a tool that makes running large language models (LLMs) on your local machine easy. It supports models like Llama 2, Mistral, and many others with simple commands.

What is Opencode?

Opencode is an AI-powered coding assistant that helps developers write, debug, and optimize code faster. When combined with Ollama, it can run locally without sending your code to external servers.

Understanding AI Agent Context

AI coding assistants like Opencode rely on context files to understand your project structure and coding style. These files contain instructions and information that guide the AI's behavior.

"AGENTS.md"

The "AGENTS.md" file defines system prompts for AI agents. It typically includes:

  • Project goals and architecture - What the codebase is designed to accomplish
  • Technical stack - Languages, frameworks, and tools used
  • Development patterns - Coding standards, naming conventions, and best practices
  • Security guidelines - How to handle sensitive data, authentication, and authorization

"CLAUDE.md"

The "CLAUDE.md" file (named after Claude AI) provides similar context for AI assistants. It often includes:

  • Project overview - High-level description of the system
  • Key directories and their purposes - File organization structure
  • Common tasks and workflows - How to build, test, and deploy
  • Example commands and configurations - Quick reference for common operations

Why Context Files Matter

Without proper context files, AI assistants may:

  • Use incorrect patterns or conventions
  • Introduce security issues
  • Generate code that doesn't fit the project architecture
  • miss important project-specific details

Priority Conditions for "AGENTS.md" and "CLAUDE.md" in Opencode

Opencode follows a specific priority order when loading context files to avoid conflicts and ensure predictable behavior:

Priority 1: "AGENTS.md"

Opencode always checks for "AGENTS.md" first. If this file exists, it takes precedence over all other context files. This file is designed to override system-level settings and provide project-specific instructions.

Priority 2: "CLAUDE.md"

If "AGENTS.md" is not found, Opencode falls back to "CLAUDE.md". This file serves as the default context provider for AI assistants and is inspired by Claude's context-loading behavior.

Priority 3: Project Root README.md

As a final fallback, Opencode may use the README.md file from your project root if neither context file exists.

Key Points:

  • "AGENTS.md" completely overrides "CLAUDE.md" when both are present
  • Context files must be in the project root directory to be detected automatically
  • Use "AGENTS.md" for strict, project-specific guidelines that must be enforced
  • Use "CLAUDE.md" for general project documentation and workflow guidance
  • Neither file supports nested configurations - only the root-level file is used

Quick Setup Guide

  1. Install Ollama: curl -fsSL https://ollama.com/install.sh | sh
  2. Download a model: ollama run qwen3-coder-next:q8_0
  3. Start Ollama server: ollama serve
  4. Configure Opencode to use your local Ollama endpoint
$ vi ~/.config/opencode/opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "models": {
        "qwen3-coder-next:q8_0": {
          "_launch": true,
          "name": "qwen3-coder-next"
        }
      },
      "name": "Ollama",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "http://127.0.0.1:11434/v1"
      }
    }
  }
}

Model Info

root@spark-7dd8:~# ollama show qwen3-coder-next:q8_0
  Model
    architecture        qwen3next    
    parameters          79.7B        
    context length      262144       
    embedding length    2048         
    quantization        Q8_0         
    requires            0.15.5       

  Capabilities
    completion    
    tools         

  Parameters
    temperature    1       
    top_k          40      
    top_p          0.95    

  License
    Apache License               
    Version 2.0, January 2004    
    ...                          

root@spark-7dd8:~# ollama list
NAME                     ID              SIZE     MODIFIED     
qwen3-coder-next:q8_0    3f68e12b44ee    84 GB    20 hours ago    
gemma4:31b               6316f0629137    19 GB    46 hours ago 

root@spark-7dd8:~# nvidia-smi -l
Tue Apr  7 07:33:28 2026       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 580.142                Driver Version: 580.142        CUDA Version: 13.0     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0  On |                  N/A |
| N/A   53C    P0             12W /  N/A  | Not Supported          |     98%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A            2663      G   /usr/lib/xorg/Xorg                      126MiB |
|    0   N/A  N/A            3318      G   /usr/bin/gnome-shell                     18MiB |
|    0   N/A  N/A           69548      C   /usr/local/bin/ollama                 89698MiB |
+-----------------------------------------------------------------------------------------+

Benefits of Local AI

  • ✅ Say Hi !! - You never lost 4% of token limit when say "Hi !"
  • ✅ Privacy - Your code never leaves your machine
  • ✅ No API costs - Run models for free
  • ✅ Offline capability - Work without internet
  • ✅ Full control - Choose any model you want

My Experience

Using Ollama with Opencode has been a game-changer for my development workflow. The local AI assistant helps me write better code faster while keeping everything private and on my terms.

Note: This page was written using Opencode with the qwen3-coder-next:q8_0 model running locally via Ollama!

Local Open WebUI สำหรับทำ Code Review

สรุปประเด็นสำคัญ (BLUF): คุณสามารถติดตั้ง Ollama และ Open WebUI เพื่อสร้าง AI สำหรับช่วยทำ Code Review ภายในเครื่องของคุณเอง ซึ่งช่วยให้คุณสามารถตรวจสอบโค้ดที่เป็นความลับได้อย่างปลอดภัยโดยไม่ต้องส่งข้อมูลออกสู่อินเทอร์เน็ต

วันนี้ผมจะมาโชว์วิธีการนำ Ollama มาใช้ร่วมกับ Opencode เพื่อรัน AI models บนเครื่องตัวเองได้อย่างราบรื่นครับ

Ollama คืออะไร?

Ollama เป็นเครื่องมือที่ทำให้การรัน large language models (LLMs) บนเครื่อง local ของเราเป็นเรื่องง่าย รองรับ models อย่าง Llama 2, Mistral, และอื่นๆ อีกมากมายด้วยคำสั่งง่ายๆ

Opencode คืออะไร?

Opencode คือ AI-powered coding assistant ที่ช่วย developers ในการเขียน, debug, และ optimize โค้ดได้เร็วขึ้น เมื่อใช้ร่วมกับ Ollama ก็สามารถรันแบบ local ได้โดยไม่ต้องส่งโค้ดของเราไปยังเซิร์ฟเวอร์ภายนอก

ความเข้าใจเกี่ยวกับ AI Agent Context

AI coding assistants อย่าง Opencode จำเป็นต้องพึ่งพา context files เพื่อทำความเข้าใจ project structure และ coding style ของเรา ไฟล์เหล่านี้ประกอบด้วยคำสั่งและข้อมูลที่ใช้ชี้แนะพฤติกรรมของ AI

"AGENTS.md"

ไฟล์ "AGENTS.md" จะเป็นตัวกำหนด system prompts สำหรับ AI agents ซึ่งโดยปกติจะประกอบด้วย:

  • Project goals และ architecture - โค้ดชุดนี้ถูกออกแบบมาเพื่อจุดประสงค์อะไร
  • Technical stack - ภาษา, frameworks, และ tools ที่ใช้
  • Development patterns - Coding standards, naming conventions, และ best practices
  • Security guidelines - วิธีการจัดการข้อมูลที่ละเอียดอ่อน, authentication, และ authorization

"CLAUDE.md"

ไฟล์ "CLAUDE.md" (ตั้งชื่อตาม Claude AI) จะให้ context ในลักษณะที่คล้ายกันสำหรับ AI assistants ซึ่งมักจะประกอบด้วย:

  • Project overview - คำอธิบายแบบ high-level ของระบบ
  • Key directories และจุดประสงค์ของมัน - โครงสร้างการจัดเก็บไฟล์
  • Common tasks และ workflows - วิธีการ build, test, และ deploy
  • Example commands และ configurations - แหล่งอ้างอิงรวดเร็วสำหรับการทำงานทั่วไป

ทำไม Context Files ถึงสำคัญ

ถ้าไม่มี context files ที่เหมาะสม AI assistants อาจจะ:

  • ใช้รูปแบบหรือ conventions ที่ผิด
  • ก่อให้เกิดปัญหาด้าน security
  • สร้างโค้ดที่ไม่สอดคล้องกับ project architecture
  • พลาดรายละเอียดสำคัญที่มีเฉพาะเจาะจงในแต่ละ project

Priority Conditions สำหรับ "AGENTS.md" และ "CLAUDE.md" ใน Opencode

Opencode ทำตามลำดับความสำคัญ (priority order) ที่เฉพาะเจาะจงในการโหลด context files เพื่อหลีกเลี่ยงข้อขัดแย้งและให้แน่ใจว่าพฤติกรรมจะเป็นไปตามที่คาดการณ์ไว้:

Priority 1: "AGENTS.md"

Opencode จะตรวจสอบหา "AGENTS.md" เป็นอันดับแรกเสมอ หากพบไฟล์นี้ มันจะมีความสำคัญเหนือ context files อื่นๆ ทั้งหมด ไฟล์นี้ถูกออกแบบมาให้ทำหน้าที่ override การตั้งค่าระดับ system และให้คำแนะนำที่เฉพาะเจาะจงกับ project

Priority 2: "CLAUDE.md"

หากหา "AGENTS.md" ไม่พบ Opencode จะไปใช้ "CLAUDE.md" แทน ไฟล์นี้ทำหน้าที่เป็น context provider เริ่มต้นสำหรับ AI assistants และได้รับแรงบันดาลใจจากพฤติกรรมการโหลด context ของ Claude

Priority 3: Project Root README.md

ในท้ายที่สุด หากไม่มี context file ทั้งสองตัว Opencode อาจเลือกใช้ไฟล์ README.md จาก project root ของคุณแทน

Key Points:

  • "AGENTS.md" จะ override "CLAUDE.md" โดยสมบูรณ์หากมีไฟล์ทั้งสอง
  • Context files จะต้องอยู่ใน project root directory เพื่อให้ถูกตรวจจับได้โดยอัตโนมัติ
  • ใช้ "AGENTS.md" สำหรับ guidelines ที่เข้มงวดและเฉพาะเจาะจงกับ project ซึ่งต้องถูกบังคับใช้
  • ใช้ "CLAUDE.md" สำหรับ project documentation ทั่วไป และคำแนะนำด้าน workflow
  • ไฟล์ทั้งสองไม่รองรับ configurations แบบ nested - มีเพียงไฟล์ในระดับ root เท่านั้นที่จะถูกนำมาใช้

Quick Setup Guide

  1. ติดตั้ง Ollama: curl -fsSL https://ollama.com/install.sh | sh
  2. ดาวน์โหลด model: ollama run qwen3-coder-next:q8_0
  3. เริ่มเซิร์ฟเวอร์ Ollama: ollama serve
  4. Configure Opencode ให้ใช้ Ollama endpoint ในเครื่องตัวเอง
$ vi ~/.config/opencode/opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "models": {
        "qwen3-coder-next:q8_0": {
          "_launch": true,
          "name": "qwen3-coder-next"
        }
      },
      "name": "Ollama",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "http://127.0.0.1:11434/v1"
      }
    }
  }
}

Model Info

root@spark-7dd8:~# ollama show qwen3-coder-next:q8_0
  Model
    architecture        qwen3next    
    parameters          79.7B        
    context length      262144       
    embedding length    2048         
    quantization        Q8_0         
    requires            0.15.5       

  Capabilities
    completion    
    tools         

  Parameters
    temperature    1       
    top_k          40      
    top_p          0.95    

  License
    Apache License               
    Version 2.0, January 2004    
    ...                          

root@spark-7dd8:~# ollama list
NAME                     ID              SIZE     MODIFIED     
qwen3-coder-next:q8_0    3f68e12b44ee    84 GB    20 hours ago    
gemma4:31b               6316f0629137    19 GB    46 hours ago 

root@spark-7dd8:~# nvidia-smi -l
Tue Apr  7 07:33:28 2026       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 580.142                Driver Version: 580.142        CUDA Version: 13.0     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0  On |                  N/A |
| N/A   53C    P0             12W /  N/A  | Not Supported          |     98%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A            2663      G   /usr/lib/xorg/Xorg                      126MiB |
|    0   N/A  N/A            3318      G   /usr/bin/gnome-shell                     18MiB |
|    0   N/A  N/A           69548      C   /usr/local/bin/ollama                 89698MiB |
+-----------------------------------------------------------------------------------------+

Benefits of Local AI

  • ✅ Say Hi !! - คุณจะไม่ต้องเสีย token limit ถึง 4% ไปกับการแค่พิมพ์ว่า "Hi !" อีกต่อไป
  • ✅ Privacy - โค้ดของคุณจะไม่มีวันออกจากเครื่องของคุณ
  • ✅ No API costs - รัน models ได้ฟรี
  • ✅ Offline capability - ทำงานได้แม้ไม่มีอินเทอร์เน็ต
  • ✅ Full control - เลือกใช้ model ใดก็ได้ตามที่คุณต้องการ

My Experience

การนำ Ollama มาใช้งานร่วมกับ Opencode ได้เข้ามาเปลี่ยน workflow การทำงานของผมไปอย่างสิ้นเชิง AI assistant แบบ local ตัวนี้ช่วยให้ผมเขียนโค้ดได้ดีขึ้นและเร็วขึ้น โดยที่ยังรักษาความเป็นส่วนตัวและอยู่ภายใต้เงื่อนไขที่ผมควบคุมได้ทั้งหมด

Note: หน้าเว็บนี้ถูกเขียนขึ้นโดยใช้ Opencode กับ qwen3-coder-next:q8_0 model ซึ่งกำลังรันแบบ local ผ่าน Ollama!

用于安全代码审查的本地 Open WebUI

核心结论 (BLUF): 您可以使用 Ollama 和 Open WebUI 建立一个本地的私有 AI 环境来进行代码审查。这样可以安全地审查敏感的源代码,而无需将数据发送到外部云 API。

今天,我将展示如何将 Ollama 与 Opencode 集成,以无缝地运行本地的 AI models。

什么是 Ollama?

Ollama 是一个可以轻松地在本地机器上运行 large language models (LLMs) 的工具。它通过简单的命令支持 Llama 2、Mistral 以及许多其他 models。

什么是 Opencode?

Opencode 是一个由 AI 驱动的 coding assistant,可帮助 developers 更快地编写、调试和 optimize 代码。当与 Ollama 结合使用时,它可以在本地运行,而无需将你的代码发送到外部服务器。

了解 AI Agent Context

像 Opencode 这样的 AI coding assistants 依赖于 context files 来理解你的 project structure 和 coding style。这些文件包含用于指导 AI 行为的指令和信息。

"AGENTS.md"

“AGENTS.md” 文件为 AI agents 定义了 system prompts。它通常包括:

  • Project goals 和 architecture - 这个 codebase 旨在实现什么
  • Technical stack - 所使用的语言、frameworks 和 tools
  • Development patterns - Coding standards、naming conventions 和 best practices
  • Security guidelines - 如何处理敏感数据、authentication 和 authorization

"CLAUDE.md"

“CLAUDE.md” 文件(以 Claude AI 命名)为 AI assistants 提供了类似的 context。它通常包括:

  • Project overview - 系统的 high-level 描述
  • Key directories 及其用途 - 文件组织结构
  • Common tasks 和 workflows - 如何 build、test 和 deploy
  • Example commands 和 configurations - 常见操作的快速参考

为什么 Context Files 如此重要

如果没有合适的 context files,AI assistants 可能会:

  • 使用不正确的 patterns 或 conventions
  • 引入 security 问题
  • 生成不符合 project architecture 的代码
  • 遗漏特定于 project 的重要细节

Opencode 中 "AGENTS.md" 和 "CLAUDE.md" 的 Priority Conditions

Opencode 在加载 context files 时遵循特定的优先顺序(priority order),以避免冲突并确保可预测的行为:

Priority 1: "AGENTS.md"

Opencode 总是首先检查 “AGENTS.md”。如果此文件存在,它优先于所有其他 context files。此文件旨在覆盖系统级设置(override system-level settings)并提供特定于 project 的说明。

Priority 2: "CLAUDE.md"

如果未找到 “AGENTS.md”,Opencode 将退回(fall back)使用 “CLAUDE.md”。该文件作为 AI assistants 的默认 context provider,其灵感来自 Claude 的上下文加载行为。

Priority 3: Project Root README.md

作为最后的手段,如果这两个 context files 都不存在,Opencode 可能会使用 project root 中的 README.md 文件。

Key Points:

  • 当两者都存在时,“AGENTS.md” 将完全覆盖 “CLAUDE.md”
  • Context files 必须位于 project root directory 才能被自动检测到
  • 使用 “AGENTS.md” 来制定必须严格执行的 project 专属指导方针
  • 使用 “CLAUDE.md” 作为一般的 project documentation 和 workflow guidance
  • 这两个文件都不支持嵌套的 configurations(nested configurations) - 仅使用根级别的文件

Quick Setup Guide

  1. 安装 Ollama: curl -fsSL https://ollama.com/install.sh | sh
  2. 下载 model: ollama run qwen3-coder-next:q8_0
  3. 启动 Ollama 服务器: ollama serve
  4. Configure Opencode 以使用本地的 Ollama endpoint
$ vi ~/.config/opencode/opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "models": {
        "qwen3-coder-next:q8_0": {
          "_launch": true,
          "name": "qwen3-coder-next"
        }
      },
      "name": "Ollama",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "http://127.0.0.1:11434/v1"
      }
    }
  }
}

Model Info

root@spark-7dd8:~# ollama show qwen3-coder-next:q8_0
  Model
    architecture        qwen3next    
    parameters          79.7B        
    context length      262144       
    embedding length    2048         
    quantization        Q8_0         
    requires            0.15.5       

  Capabilities
    completion    
    tools         

  Parameters
    temperature    1       
    top_k          40      
    top_p          0.95    

  License
    Apache License               
    Version 2.0, January 2004    
    ...                          

root@spark-7dd8:~# ollama list
NAME                     ID              SIZE     MODIFIED     
qwen3-coder-next:q8_0    3f68e12b44ee    84 GB    20 hours ago    
gemma4:31b               6316f0629137    19 GB    46 hours ago 

root@spark-7dd8:~# nvidia-smi -l
Tue Apr  7 07:33:28 2026       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 580.142                Driver Version: 580.142        CUDA Version: 13.0     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0  On |                  N/A |
| N/A   53C    P0             12W /  N/A  | Not Supported          |     98%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A            2663      G   /usr/lib/xorg/Xorg                      126MiB |
|    0   N/A  N/A            3318      G   /usr/bin/gnome-shell                     18MiB |
|    0   N/A  N/A           69548      C   /usr/local/bin/ollama                 89698MiB |
+-----------------------------------------------------------------------------------------+

Benefits of Local AI

  • ✅ Say Hi !! - 你再也不会因为说一句“Hi !”而损失 4% 的 token limit 了
  • ✅ Privacy - 你的代码永远不会离开你的机器
  • ✅ No API costs - 免费运行 models
  • ✅ Offline capability - 无需互联网即可工作
  • ✅ Full control - 选择任何你想要的 model

My Experience

将 Ollama 与 Opencode 结合使用彻底改变了我的 development workflow。这个本地的 AI assistant 帮助我更快地编写出更好的代码,同时保留了所有的隐私权,一切尽在我的掌控之中。

Note: 此页面是使用 Opencode 以及通过 Ollama 在本地运行的 qwen3-coder-next:q8_0 model 编写的!

セキュアなコードレビューのためのローカル Open WebUI

要点 (BLUF): Ollama と Open WebUI を使用して、コードレビュー用のローカルでプライベートな AI 環境を構築できます。これにより、機密データを外部のクラウド API に送信することなく安全にレビューできます。

今日は、Ollama を Opencode と統合し、ローカルの AI models をシームレスに実行する方法を紹介します。

Ollama とは?

Ollama は、ローカルマシン上で large language models (LLMs) を簡単に実行するためのツールです。Llama 2、Mistral、その他の多くの models をシンプルなコマンドでサポートしています。

Opencode とは?

Opencode は、developers がコードをより早く記述、デバッグ、そして optimize するのを支援する AI-powered の coding assistant です。Ollama と組み合わせることで、外部サーバーにコードを送信することなく、ローカルで実行できるようになります。

AI Agent Context について

Opencode のような AI coding assistants は、project structure や coding style を理解するために context files に依存しています。これらのファイルには、AI の挙動を導くための指示や情報が含まれています。

"AGENTS.md"

「AGENTS.md」ファイルは、AI agents のための system prompts を定義します。これには通常、以下の内容が含まれます:

  • Project goals と architecture - その codebase が何を達成するために設計されているか
  • Technical stack - 使用されている言語、frameworks、および tools
  • Development patterns - Coding standards、naming conventions、および best practices
  • Security guidelines - 機密データ、authentication、および authorization の処理方法

"CLAUDE.md"

「CLAUDE.md」ファイル(Claude AI にちなんで名付けられました)は、AI assistants に同様の context を提供します。これにはしばしば以下の内容が含まれます:

  • Project overview - システムの high-level な説明
  • Key directories とその目的 - ファイルの構成構造
  • Common tasks と workflows - build、test、deploy の方法
  • Example commands と configurations - 一般的な操作のためのクイックリファレンス

Context Files が重要な理由

適切な context files がないと、AI assistants は以下のような問題を起こす可能性があります:

  • 間違った patterns や conventions を使用する
  • security の問題を引き起こす
  • project architecture に適合しないコードを生成する
  • project 固有の重要な詳細を見落とす

Opencode における "AGENTS.md" と "CLAUDE.md" の Priority Conditions

Opencode は、競合を避け、予測可能な挙動を保証するために、context files をロードする際に特定の優先順位 (priority order) に従います:

Priority 1: "AGENTS.md"

Opencode は常に最初に「AGENTS.md」をチェックします。このファイルが存在する場合、他のすべての context files よりも優先されます。このファイルは、システムレベルの設定を override し、project 固有の指示を提供するために設計されています。

Priority 2: "CLAUDE.md"

「AGENTS.md」が見つからない場合、Opencode は「CLAUDE.md」にフォールバック (fall back) します。このファイルは AI assistants のデフォルトの context provider として機能し、Claude のコンテキストロード挙動からインスピレーションを得ています。

Priority 3: Project Root README.md

最後のフォールバックとして、どちらの context file も存在しない場合、Opencode は project root の README.md ファイルを使用することがあります。

Key Points:

  • 両方が存在する場合、「AGENTS.md」は「CLAUDE.md」を完全に override します
  • 自動的に検出されるためには、Context files は project root directory に配置する必要があります
  • 強制されるべき厳密で project 固有の guidelines には「AGENTS.md」を使用します
  • 一般的な project documentation や workflow guidance には「CLAUDE.md」を使用します
  • どちらのファイルも nested configurations(ネストされた設定)をサポートしていません - root レベルのファイルのみが使用されます

Quick Setup Guide

  1. Ollama のインストール: curl -fsSL https://ollama.com/install.sh | sh
  2. model のダウンロード: ollama run qwen3-coder-next:q8_0
  3. Ollama サーバーの起動: ollama serve
  4. Configure Opencode: ローカルの Ollama endpoint を使用するように Opencode を設定する
$ vi ~/.config/opencode/opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "models": {
        "qwen3-coder-next:q8_0": {
          "_launch": true,
          "name": "qwen3-coder-next"
        }
      },
      "name": "Ollama",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "http://127.0.0.1:11434/v1"
      }
    }
  }
}

Model Info

root@spark-7dd8:~# ollama show qwen3-coder-next:q8_0
  Model
    architecture        qwen3next    
    parameters          79.7B        
    context length      262144       
    embedding length    2048         
    quantization        Q8_0         
    requires            0.15.5       

  Capabilities
    completion    
    tools         

  Parameters
    temperature    1       
    top_k          40      
    top_p          0.95    

  License
    Apache License               
    Version 2.0, January 2004    
    ...                          

root@spark-7dd8:~# ollama list
NAME                     ID              SIZE     MODIFIED     
qwen3-coder-next:q8_0    3f68e12b44ee    84 GB    20 hours ago    
gemma4:31b               6316f0629137    19 GB    46 hours ago 

root@spark-7dd8:~# nvidia-smi -l
Tue Apr  7 07:33:28 2026       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 580.142                Driver Version: 580.142        CUDA Version: 13.0     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0  On |                  N/A |
| N/A   53C    P0             12W /  N/A  | Not Supported          |     98%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A            2663      G   /usr/lib/xorg/Xorg                      126MiB |
|    0   N/A  N/A            3318      G   /usr/bin/gnome-shell                     18MiB |
|    0   N/A  N/A           69548      C   /usr/local/bin/ollama                 89698MiB |
+-----------------------------------------------------------------------------------------+

Benefits of Local AI

  • ✅ Say Hi !! - 「Hi !」と言うだけで 4% の token limit を失うことはもうありません
  • ✅ Privacy - コードがあなたのマシンから出ることはありません
  • ✅ No API costs - 無料で models を実行できます
  • ✅ Offline capability - インターネットなしで作業できます
  • ✅ Full control - 好きな model を自由に選択できます

My Experience

Ollama を Opencode とともに使用することは、私の development workflow にとってゲームチェンジャーとなりました。このローカルの AI assistant のおかげで、すべてをプライベートに、自分の思い通りに保ちながら、より良いコードをより速く書くことができるようになりました。

Note: このページは、Ollama 経由でローカルで実行されている qwen3-coder-next:q8_0 model とともに Opencode を使用して作成されました!

Lokale Open WebUI für sicheres Code-Review

Zusammenfassung (BLUF): Sie können eine lokale, private AI-Umgebung für Code-Reviews mit Ollama und Open WebUI einrichten. So können Sie sensiblen Quellcode sicher überprüfen, ohne Daten an externe Cloud-APIs zu senden.

Heute zeige ich, wie man Ollama mit Opencode integriert, um lokale AI models nahtlos auszuführen.

Was ist Ollama?

Ollama ist ein Tool, das die Ausführung von large language models (LLMs) auf Ihrem lokalen Rechner einfach macht. Es unterstützt Models wie Llama 2, Mistral und viele andere mit einfachen Befehlen.

Was ist Opencode?

Opencode ist ein AI-powered coding assistant, der Developern hilft, Code schneller zu schreiben, zu debuggen und zu optimize. In Kombination mit Ollama kann es lokal ausgeführt werden, ohne dass Ihr Code an externe Server gesendet wird.

AI Agent Context Verstehen

AI coding assistants wie Opencode sind auf Context files angewiesen, um Ihre project structure und Ihren coding style zu verstehen. Diese Dateien enthalten Anweisungen und Informationen, die das Verhalten der AI steuern.

"AGENTS.md"

Die Datei "AGENTS.md" definiert System prompts für AI agents. Sie enthält typischerweise:

  • Project goals und architecture - Was die codebase erreichen soll
  • Technical stack - Verwendete Sprachen, Frameworks und Tools
  • Development patterns - Coding standards, Naming conventions und Best practices
  • Security guidelines - Wie mit sensiblen Daten, Authentication und Authorization umgegangen wird

"CLAUDE.md"

Die Datei "CLAUDE.md" (benannt nach Claude AI) bietet einen ähnlichen Context für AI assistants. Sie enthält oft:

  • Project overview - High-level Beschreibung des Systems
  • Key directories und ihre Zwecke - Dateiorganisationsstruktur
  • Common tasks und workflows - Wie man build, test und deploy durchführt
  • Example commands und configurations - Kurze Referenz für häufige Operationen

Warum Context Files Wichtig Sind

Ohne geeignete Context files könnten AI assistants:

  • Falsche Patterns oder Conventions verwenden
  • Security-Probleme einführen
  • Code generieren, der nicht zur project architecture passt
  • Wichtige projektspezifische Details übersehen

Priority Conditions für "AGENTS.md" und "CLAUDE.md" in Opencode

Opencode folgt einer spezifischen priority order beim Laden von Context files, um Konflikte zu vermeiden und ein vorhersehbares Verhalten sicherzustellen:

Priority 1: "AGENTS.md"

Opencode sucht immer zuerst nach "AGENTS.md". Wenn diese Datei existiert, hat sie Vorrang vor allen anderen Context files. Diese Datei ist so konzipiert, dass sie system-level Einstellungen überschreibt (override) und projektspezifische Anweisungen liefert.

Priority 2: "CLAUDE.md"

Wenn "AGENTS.md" nicht gefunden wird, greift Opencode auf "CLAUDE.md" zurück (fall back). Diese Datei dient als Standard-Context provider für AI assistants und ist vom Context-Ladeverhalten von Claude inspiriert.

Priority 3: Project Root README.md

Als letztes Fallback kann Opencode die Datei README.md aus dem project root verwenden, wenn keine der Context files existiert.

Key Points:

  • "AGENTS.md" überschreibt "CLAUDE.md" vollständig (override), wenn beide vorhanden sind
  • Context files müssen sich im project root directory befinden, um automatisch erkannt zu werden
  • Verwenden Sie "AGENTS.md" für strikte, projektspezifische Guidelines, die durchgesetzt werden müssen
  • Verwenden Sie "CLAUDE.md" für allgemeine project documentation und workflow guidance
  • Beide Dateien unterstützen keine verschachtelten Konfigurationen (nested configurations) - nur die Datei auf Root-Ebene wird verwendet

Quick Setup Guide

  1. Installieren von Ollama: curl -fsSL https://ollama.com/install.sh | sh
  2. Download eines models: ollama run qwen3-coder-next:q8_0
  3. Starten des Ollama-Servers: ollama serve
  4. Configure Opencode für die Verwendung Ihres lokalen Ollama-Endpoints
$ vi ~/.config/opencode/opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "models": {
        "qwen3-coder-next:q8_0": {
          "_launch": true,
          "name": "qwen3-coder-next"
        }
      },
      "name": "Ollama",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "http://127.0.0.1:11434/v1"
      }
    }
  }
}

Model Info

root@spark-7dd8:~# ollama show qwen3-coder-next:q8_0
  Model
    architecture        qwen3next    
    parameters          79.7B        
    context length      262144       
    embedding length    2048         
    quantization        Q8_0         
    requires            0.15.5       

  Capabilities
    completion    
    tools         

  Parameters
    temperature    1       
    top_k          40      
    top_p          0.95    

  License
    Apache License               
    Version 2.0, January 2004    
    ...                          

root@spark-7dd8:~# ollama list
NAME                     ID              SIZE     MODIFIED     
qwen3-coder-next:q8_0    3f68e12b44ee    84 GB    20 hours ago    
gemma4:31b               6316f0629137    19 GB    46 hours ago 

root@spark-7dd8:~# nvidia-smi -l
Tue Apr  7 07:33:28 2026       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 580.142                Driver Version: 580.142        CUDA Version: 13.0     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0  On |                  N/A |
| N/A   53C    P0             12W /  N/A  | Not Supported          |     98%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A            2663      G   /usr/lib/xorg/Xorg                      126MiB |
|    0   N/A  N/A            3318      G   /usr/bin/gnome-shell                     18MiB |
|    0   N/A  N/A           69548      C   /usr/local/bin/ollama                 89698MiB |
+-----------------------------------------------------------------------------------------+

Benefits of Local AI

  • ✅ Say Hi !! - Sie verlieren nie wieder 4% des Token-Limits, nur weil Sie "Hi !" sagen
  • ✅ Privacy - Ihr Code verlässt niemals Ihren Rechner
  • ✅ No API costs - Führen Sie Models kostenlos aus
  • ✅ Offline capability - Arbeiten Sie ohne Internet
  • ✅ Full control - Wählen Sie jedes gewünschte Model

My Experience

Die Verwendung von Ollama zusammen mit Opencode war ein Game-Changer für meinen Development workflow. Der lokale AI assistant hilft mir, besseren Code schneller zu schreiben, während alles privat und unter meiner Kontrolle bleibt.

Note: Diese Seite wurde mit Opencode und dem lokal über Ollama ausgeführten qwen3-coder-next:q8_0 Model geschrieben!