opencode-agentignoreOpenCode plugin that blocks reads/edits on files matching .agentignore / .claudeignore (gitignore syntax)
0
567
近 7 天 28
35.8
生态多维模型
27 天前
2026-07-23
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-agentignore@1.2.3"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-agentignore@1.2.3"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-agentignoreopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
OpenCode plugin that blocks reads, edits, writes, globs, and greps on files
matching .agentignore / .claudeignore (gitignore syntax). Uses the
battle-tested ignore library
for pattern matching.
Ported from claude-ignore.
How it works
Two hooks run together:
tool.execute.beforeonread|edit|write|glob|grep|multiedit|list. Walks up from the target file's parent to/, collecting every.agentignoreand.claudeignorealong the way. Patterns from co-located files are merged at each directory level using theignorelibrary. If any level matches the (symlink-resolved) path, the call is denied.tool.execute.afterongrep. Re-inspects the response after ripgrep runs. Grep'stool.execute.beforeonly sees the search root, so a project- wide search could return match lines from protected files. This hook extracts each path in the response, checks it against the same ignore chain, and replaces the result with a block message — the original content is never shown to the model. Supports both ripgrep raw output and OpenCode native grep format.
Install
Add to your OpenCode config (~/.config/opencode/opencode.json or
opencode.json):
{
"plugin": ["opencode-agentignore@latest"]
}
OpenCode installs it from npm on next start.
Usage
Create a .claudeignore or .agentignore in any directory:
# Secrets
.env
.env.*
*.pem
secrets/
# Generated
dist/
node_modules/
The plugin walks up from each target file's directory, so you can place
ignore files at the project root, in subdirectories, or in ~ for
truly global rules.
.agentignore vs .claudeignore
Both are checked at every directory level and their patterns are merged.
Use whichever you prefer — .agentignore for OpenCode-native workflows,
or .claudeignore for compatibility with claude-ignore / Claude Code.
Key semantics
- Walk-up starts from the target file, not the cwd — rules apply regardless of where OpenCode was launched.
- Fail-closed across files. A leaf-level
!patterncannot re-include a file ignored higher up. Unreadable/corrupt ignore files also fail closed. However, negations within a single ignore file work normally. Globresults aren't filtered. The model can still learn that a protected file exists (e.g.Glob("**/.env")returns paths). OnlyGrepis post-filtered, since it can leak file contents.bashis not hooked. Shell commands (cat .env,grep -r SECRET .) bypass the ignore files entirely.
Configuration
The plugin requires no configuration. Drop the ignore files and it works.
Testing
npm test
38 tests covering the ignore library integration, hierarchical
lookup, block/allow matching, symlink handling, merged .agentignore +
.claudeignore, and grep post-filter extraction.
License
MIT