zzqayy
发布于 2026-07-29 / 2 阅读
0

opencode简要说明

opencode简要说明

官网

https://opencode.ai/zh

安装

sudo npm install -g opencode-ai --registry=https://registry.npmmirror.com

配置

配置文件位置

优先级顺序

配置源按以下顺序加载(后面的源覆盖前面的源):

  1. 远程配置​(来自 .well-known/opencode)- 组织默认值
  2. 全局配置​(~/.config/opencode/opencode.json)- 用户偏好
  3. 自定义配置​(OPENCODE_CONFIG 环境变量)- 自定义覆盖
  4. 项目配置​(项目中的 opencode.json)- 项目特定设置
  5. .opencode 目录 - 代理、命令、插件
  6. 内联配置​(OPENCODE_CONFIG_CONTENT 环境变量)- 运行时覆盖

这意味着项目配置可以覆盖全局默认值,全局配置可以覆盖远程组织默认值。

注意.opencode 和 ~/.config/opencode 目录的子目录使用复数名称:agents/、commands/、modes/、plugins/、skills/、tools/ 和 themes/。为了向后兼容,也支持单数名称(例如 agent/)。

设置回答全中文

在配置文件夹下创建文件 global-language.md(内容来自qwen)

# Output language preference: Chinese

## Rule
You MUST always respond in **Chinese** regardless of the user's input language.
This is a mandatory requirement, not a preference.

## Exception
If the user **explicitly** requests a response in a specific language (e.g., "please reply in English", "用中文回答"), switch to the user's requested language for the remainder of the conversation.

## Keep technical artifacts unchanged
Do **not** translate or rewrite:
- Code blocks, CLI commands, file paths, stack traces, logs, JSON keys, identifiers
- Exact quoted text from the user (keep quotes verbatim)

## Tool / system outputs
Raw tool/system outputs may contain fixed-format English. Preserve them verbatim, and if needed, add a short **Chinese** explanation below.

配置

{
	"$schema": "https://opencode.ai/config.json",
	"instructions": [
		"global-language.md绝对地址"
	]
}

自定义模型

{
	"$schema": "https://opencode.ai/config.json",
	"provider": {
   	  "ollama": {
         "npm": "@ai-sdk/openai-compatible",
         "name": "Ollama (local)",
         "options": {
           "baseURL": "http://localhost:11434/v1"
          },
       "models": {
          "qwen3.5:2b": {
            "name": "qwen3.5:2b"
           }
        }
      }
    }
}

外部文件读取

说明文档: https://opencode.ai/docs/zh-cn/permissions/

主要通过修改配置文件

此处允许的任何目录都会继承与当前工作空间相同的默认值。由于 read 默认为 allow,external_directory 下的条目也允许读取,除非另行覆盖。当需要在这些路径中限制某个工具时,请添加显式规则,例如在保留读取的同时阻止编辑:

{
  "$schema": "https://opencode.ai/config.json",
  "permission": {
    "external_directory": {
      "~/projects/personal/**": "allow"
    },
    "edit": {
      "~/projects/personal/**": "deny"
    }
  }
}