AI 编程智能体(Claude Code、Cursor、Codex、opencode)在运行时可以读你仓库里的任何文件——包括密钥。现有防护各有缺口:
只阻止 git 提交。智能体运行时 cat .env 照样读出来。
只挡 Read 工具。grep . .env 走 Bash,照样把密钥喂给模型。
100% gitignore 语法,零学习成本。readignore 把它翻译成每个智能体当前真正支持的最强防御机制——并诚实标注每一项的实际强度。
# readignore — files this repo's AI agent must not read # Secrets .env .env.* !.env.example # ! negation: allow the template *.pem *.key # SSH / cloud credentials **/id_rsa .aws/
不假装跨智能体等价。readignore 适配到每个智能体实际能强制执行的机制,并把做不到的说清楚。
| 智能体 | 强度 | 机制 | 状态 |
|---|---|---|---|
| Claude Code | hard | PreToolUse 钩子——执行前拦截 Read/Grep/Glob/Bash | check_circle |
| codex CLI | hard | .codex/hooks.json,Claude-style PreToolUse 钩子 | check_circle |
| pi | hard | .pi/extensions TS 扩展覆写内置 read 工具 | check_circle |
| opencode | config | opencode.json 的 permission.read deny/allow glob | check_circle |
| kilo code | config | kilo.json 的 permission.read deny/allow glob | check_circle |
| Cursor | soft | .cursor/rules 自然语言建议(模型可能遵守) | map |
改 .readignore 立即生效——钩子每次调用都实时重读,无需重新 install。和 .gitignore 一样改完即用。
npm i -g readignorereadignore init # 生成 .readignore,内置常见密钥模式readignore install --all # 为检测到的全部智能体安装