OpenCode 使用 Skill 非常方便。它原生支持 Agent Skills 标准,核心机制是:
创建 SKILL.md → OpenCode 自动发现 → Agent 按需加载 → 按 Skill 定义执行任务。
你不需要自己开发 Skill Loader,也不需要把所有 Skill 内容写进 Prompt。
结合你使用的 Windows、OpenCode、Java/Spring Boot 开发环境,我下面给你一套可以直接执行的操作步骤。
官方文档:OpenCode Skills 官方文档。
一、理解 OpenCode Skill 的工作机制
OpenCode Skill Lifecycle
SKILL.md
描述能力、使用场景、执行规范
Skill Discovery
OpenCode 启动时发现 Skill,读取名称和描述
Skill Selection
Agent 根据任务判断是否需要加载
Skill Execution
加载完整指令、读取参考文件、执行工作
这里有一个非常重要的设计:
OpenCode 不会在每次对话时把所有 Skill 的完整内容都加载到上下文中。
它先提供 Skill 的名称和 description,只有 Agent 需要使用时才加载完整内容。这有助于节省 Token。
OpenCode+1
二、Skill 放在哪里?
OpenCode 支持两种主要使用场景。
1. 全局 Skill:所有项目都能使用
适合:
-
Java Code Review
-
Git Commit
-
TDD
-
Debugging
-
Security Review
Windows 路径:
%USERPROFILE%\.config\opencode\skills\
Linux 路径:
~/.config/opencode/skills/
例如:
.config/
└── opencode/
└── skills/
├── java-code-review/
│ └── SKILL.md
├── tdd/
│ └── SKILL.md
└── systematic-debugging/
└── SKILL.md
2. 项目级 Skill:仅当前项目使用
适合:
-
当前项目的 Spring Boot 规范。
-
特定微服务的 API 规范。
-
项目数据库规范。
-
项目专用测试流程。
目录:
my-spring-project/
├── .opencode/
│ └── skills/
│ ├── spring-boot-development/
│ │ └── SKILL.md
│ └── project-code-review/
│ └── SKILL.md
├── src/
├── pom.xml
└── README.md
我的建议: 通用能力放全局,企业和项目业务规则放项目级,并通过 Git 管理项目级 Skills。
此外,OpenCode 还兼容 .agents/skills/ 和 .claude/skills/ 等目录,可以共享符合标准的 Skills。
OpenCode+1
三、手把手创建一个 Skill
我们创建一个实际可用的:
spring-boot-code-review
Step 1:创建目录
Windows PowerShell:
$skillDir = "$env:USERPROFILE\.config\opencode\skills\spring-boot-code-review"
New-Item -ItemType Directory -Force $skillDir
Step 2:创建 SKILL.md
---
name: Spring Boot Code Review
description: Review Java and Spring Boot code for correctness, architecture, security, performance, testing and maintainability. Use when reviewing Java code, pull requests or Spring Boot changes.
---
# Spring Boot Code Review
## Role
You are a senior Java and Spring Boot engineer.
Your responsibility is to perform a rigorous code review.
## Review Workflow
### 1. Understand the Context
- Read the relevant source code.
- Identify the module and business responsibility.
- Check existing coding conventions.
- Understand dependencies and call relationships.
### 2. Correctness
Check:
- Null pointer risks.
- Exception handling.
- Transaction boundaries.
- Concurrency issues.
- Data consistency.
- Boundary conditions.
### 3. Spring Boot
Check:
- Dependency injection.
- Bean lifecycle.
- Configuration management.
- Transaction management.
- REST API conventions.
- Spring Security configuration.
### 4. Database
Check:
- SQL performance.
- N+1 query problems.
- Index usage.
- Transaction isolation.
- Connection management.
### 5. Security
Check:
- SQL injection.
- Authentication and authorization.
- Sensitive information exposure.
- Input validation.
- Dependency vulnerabilities.
### 6. Testing
Check:
- Unit test coverage.
- Integration tests.
- Boundary conditions.
- Mocking strategy.
## Output Format
Provide findings in the following structure:
| Severity | File | Problem | Recommendation |
|---|---|---|---|
Severity:
- Critical
- High
- Medium
- Low
- Informational
## Rules
- Never modify source code during review unless explicitly requested.
- Do not invent issues.
- Provide evidence for every finding.
- Explain the impact of each issue.
- Prioritize correctness and security.
保存为:
spring-boot-code-review/SKILL.md
Step 3:重新启动 OpenCode
cd C:\your-project
opencode
Step 4:使用 Skill
在 OpenCode 对话框中直接输入:
Review the current Spring Boot project.
Use @spring-boot-code-review.
Analyze the code and report all issues.
Do not modify any source files.
也可以使用自然语言,让 Agent 根据 description 自动判断是否需要这个 Skill。
注意:@spring-boot-code-review 是显式指定 Skill ID 的方式,不是文件路径。
OpenCode
四、如何安装 GitHub 上现成的 Skills?
这是最实用的部分。
例如,你想使用社区的 obra/superpowers。
可以先克隆:
git clone https://github.com/obra/superpowers.git
查看仓库中的 Skills 目录,找到包含 SKILL.md 的 Skill 文件夹。
然后将需要的 Skill 复制到:
%USERPROFILE%\.config\opencode\skills\
例如:
Copy-Item `
".\superpowers\skills\some-skill" `
"$env:USERPROFILE\.config\opencode\skills\" `
-Recurse
注意:这里的 some-skill 是示意目录,需要替换成仓库实际存在的目录。
不建议把整个 GitHub 仓库不加筛选地复制进去。先检查:
-
是否有
SKILL.md。 -
是否依赖额外脚本。
-
是否有外部命令或网络调用。
-
是否存在危险权限和数据访问行为。
-
是否兼容当前 OpenCode 版本。
五、一个 Skill 可以包含多个文件吗?
可以,而且我非常推荐这样做。
对于企业级 SDLC Skill,不要把所有内容都塞进一个 SKILL.md。
例如:
spring-boot-code-review/
│
├── SKILL.md
│
├── references/
│ ├── java-coding-standard.md
│ ├── spring-security.md
│ ├── database-guidelines.md
│ └── microservice-guidelines.md
│
├── scripts/
│ ├── checkstyle.sh
│ └── test.sh
│
└── examples/
├── good-example.java
└── bad-example.java
在 SKILL.md 中引用:
## Additional References
Before reviewing Java code:
1. Read references/java-coding-standard.md.
2. Read references/spring-security.md
when security-related code is involved.
3. Read references/database-guidelines.md
when database code is involved.
## Validation
Run scripts/test.sh when the user requests
automated validation.
OpenCode 不会自动加载所有 reference 和 script 内容,而是根据 Skill 指令按需读取。这是控制 Token 成本的关键。
OpenCode+1
六、如何管理多个 Skills?
建议你建立一个 Git 仓库:
enterprise-sdlc-skills/
│
├── README.md
├── requirements/
│ ├── requirement-analysis/
│ │ └── SKILL.md
│ └── user-story/
│ └── SKILL.md
│
├── development/
│ ├── spring-boot-development/
│ │ └── SKILL.md
│ ├── java-code-review/
│ │ └── SKILL.md
│ └── systematic-debugging/
│ └── SKILL.md
│
├── testing/
│ ├── tdd/
│ │ └── SKILL.md
│ └── integration-testing/
│ └── SKILL.md
│
├── security/
│ ├── security-review/
│ │ └── SKILL.md
│ └── foss-review/
│ └── SKILL.md
│
└── cicd/
└── jenkins-pipeline/
└── SKILL.md
你可以通过项目的 opencode.json 或 opencode.jsonc 配置额外的 Skills 目录:
{
"$schema": "https://opencode.ai/config.json",
"skills": [
"./enterprise-sdlc-skills"
]
}
这里的相对路径是相对于当前 OpenCode 工作目录解析的。对于团队共享,也可以配置 HTTP Skills Catalog。
OpenCode
另外,推荐用 Git 管理:
git init
git add .
git commit -m "initial enterprise sdlc skills"
以后每次修改 Skill 都保留版本记录。
七、常见问题排查
| 问题 | 检查方法 |
|---|---|
| Skill 没有被发现 | 检查目录和 |
| Agent 不自动使用 | 检查 description 是否清晰 |
|
| 检查目录名是否与 ID 一致 |
| Skill 无法读取 | 检查 Agent 的 skill 权限 |
| Reference 没有读取 | 检查 SKILL.md 中的引用路径 |
| 修改后没有生效 | 重新启动 OpenCode,检查缓存和加载结果 |
还有一个权限配置值得了解:
{
"permission": {
"skill": {
"*": "allow",
"internal-*": "deny"
}
}
}
不同 OpenCode 配置版本的权限语法可能有所差异。当前官方 Skills 文档也提供了 permissions 规则形式,建议以实际安装版本对应的文档为准。
OpenCode+1
八、我建议你下一步学习的顺序
OpenCode Skills 学习路线
-
第一阶段:使用现成 Skills
安装 TDD、Code Review、Debugging,熟悉自动发现和
@skill-id。 -
第二阶段:自己开发 Skills
掌握 SKILL.md、References、Scripts、Examples。
-
第三阶段:Skills + Agents
将 Developer、Tester、Reviewer 拆成不同 Agent,并让它们使用对应 Skills。
-
第四阶段:Skills + MCP + Workflow
集成 GitHub、Jira、Jenkins,建立自动化 SDLC 流程。
-
第五阶段:企业级 Skill Repository
Git 版本管理、自动测试、安全扫描、质量评估和团队共享。
最后强调一个设计原则:
不要把 Skill 当成一个 Prompt 文件,而应该把它当成一个可版本管理、可测试、可复用的工程能力模块。
对于你的 AI Software Factory,我建议先用 OpenCode 建立 5 个基础 Skills:
-
requirement-analysis -
spring-boot-development -
systematic-debugging -
java-code-review -
tdd
把它们跑通之后,再增加 Developer Agent、Tester Agent 和 Reviewer Agent。
这样你学到的不仅是如何使用 OpenCode Skill,而是如何构建真正可维护的 Agentic Software Engineering 体系。
1552



被折叠的 条评论
为什么被折叠?



