Repository navigation
Description
Summary
In opencode 2.0.12, a custom Markdown agent's V2 permissions: frontmatter list is parsed into agent.request.body.permissions but never merged into the effective session permissions. Deny rules have no effect and the agent keeps the default allow-all tools. The legacy permission: block is still applied correctly.
Environment
- opencode version: 2.0.12
- OS: Linux 7.0.0-31-generic (linux x64)
- Terminal: xterm-256color, COLORTERM=truecolor
- Shell: /usr/bin/zsh
- Install/channel: latest
- Active plugins: none found in config
Reproduction
-
Create
~/.config/opencode/agents/reviewer.md:--- description: read-only reviewer mode: subagent permissions: - action: edit resource: "*" effect: deny - action: shell resource: "*" effect: deny --- Review the changes. Do not edit files.
-
Reload (file is re-discovered at service start) and query the resolved agent:
opencode service restart opencode api get /api/agent/reviewer
-
In the response, compare the two permission fields:
data.request.body.permissionscontains the declared rules (edit * deny,shell * deny).data.permissions(the merged list the session runner uses) does not contain them — it ends with global rules and the built-in default* → allow.
-
Run a session with that agent (e.g.
opencode run --agent reviewer) and attemptwrite/shell— both succeed.
Contrast: using the legacy frontmatter permission: { edit: deny, bash: ask } produces matching rules in data.permissions, and edit is denied at session level.
Expected Behavior
permissions: in Markdown agent frontmatter should be applied: data.permissions should include the agent rules (appended after global permissions, last-match-wins), and sessions with that agent should deny the listed tools — same as documented for JSONC agents and for the legacy permission: block.
Actual Behavior
The frontmatter permissions: list is parsed but only stored in request.body.permissions, which the session runner does not use. Session permissions stay allow-by-default; write, edit, and shell remain available to an agent that declared them denied.
Observed API evidence (redacted):
// data.request.body.permissions — parsed but inert
[ { "action": "*", "resource": "*", "effect": "deny" },
{ "action": "edit", "resource": "*", "effect": "deny" } ]
// data.permissions (tail) — agent rules absent, default allow wins
[ ..., { "action": "edit", "resource": "*", "effect": "ask" },
{ "action": "read", "resource": "*", "effect": "allow" } ]Additional Context
- Config: global
~/.config/opencode/opencode.jsonc; agents as.mdfiles in~/.config/opencode/agents/. - Workaround: keep using the legacy
permission:frontmatter block; v2.0.12 still applies it (edit→edit * deny,bashpatterns →shell * rules,task→subagent * allow). - Reproducible consistently on every reload.
- Related: docs page https://opencode.ai/v2/docs/agents documents
permissions:for Markdown frontmatter.
Activity
github-actions commentedon Sep 22, 2026
This issue might be a duplicate of existing issues. Please check:
permissionsrules ignored — global deny wins over agent-level allow rules; very similar mechanics (V2 permissions parsed but not applied to the effective session ruleset)permissionmerges additively with defaults instead of replacing them — related root cause analysis of how agent permission rules are mergedpermission.ask) not enforced at runtime — same symptom of declared permissions having no effect on tool executionmartin-braun commentedon Sep 23, 2026
Confirmed, the V2 permissions do not work as documented. I had to revert my migration to the V1 format. However, the V2 permissions in opencode.json work. Indeed a duplicated of #50149.
Bigbrotha12 commentedon Sep 26, 2026
Confirming this still reproduces on 2.0.18 (not fixed since 2.0.12), with a narrower trigger.
On 2.0.18 the V2
permissions:list works when the frontmatter contains only recognized keys, but any unrecognized top-level key routes the entire frontmatter — includingpermissions— intorequest.body, so nothing is applied. The common real-world trigger is the legacyname:field.Minimal repro (two agents differing only by
name:):~/.config/opencode/agents/_fresh_named.md~/.config/opencode/agents/_fresh_unnamed.md— identical minus thename:line.opencode reloadthenopencode debug agents:So on 2.0.18 the deny rules apply only for the file without
name:.Additional observations:
name. Any unknown key behaves the same: withunknownkey: hellopluspermissions,request.bodycontains bothunknownkeyandpermissions, and the rules are still dropped.name:present (permission: { edit: deny, bash: deny }is applied asshell), so only the native V2permissionskey is affected.nameas accepted-but-unsupported and says it is ignored "with a warning"; no warning is emitted andpermissionsis silently discarded.name) so only recognized keys remain.Kirytho commentedon Sep 27, 2026
Same root cause as described above, but I hit it with a different and — I think more common — trigger, and I have a verified workaround that also works around the
permissionsordering problem.tools:is another trigger, and it's a documented v1 key that the migration path tells people to keepTwo agents that differ only by the legacy
tools:key:So on 2.0.18,
tools:behaves exactly likename:— it routes the whole frontmatter intorequest.body. Worth noting the severity difference from thename:case:name:is undocumented-but-tolerated, whereastools:is the v1 tool-gating key that the v1→v2 migration path encourages people to carry over, and the docs tell youtoolsmaps topermissions. So a subagent written to encapsulate one MCP is a very natural thing to end up withtools:in the frontmatter — and it silently keeps every tool it was meant to hide. In my case the subagent advertised "sqlite only" but had 110 tools available (browser, playwright, megamemory, codebase-memory) instead of 12.Verified the tool-level effect: with
tools:present, the declareddenyrules do not strip anything from the tool catalog, and the permission array is sent to the model provider as an unknownpermissionsbody param on every request.Workaround: drop
tools:and make the allow the lastpermissionsruleThe
tools:key is not needed to allow a namespace — the allow is just a rule, and the last matching rule wins. So this is equivalent totools: { "sqlite_*": true }and parses correctly:With this,
opencode debug agentsshows 22 rules (9 built-in defaults + 4 global fromopencode.json+ 8 agent rules + the trailing allow),request.bodyis{}, and the tool catalog drops from 110 to 12. Ordering matters: with theallowlisted before thedenyfor the same namespace, the deny wins and the tools vanish entirely.Two action-name data points that cost me some time
browseris a built-in namespace, not an MCP, and its action name isbrowser*— no underscore.browser_*matches nothing.<server>_<tool>, so thebrowser*form does not work for them:playwright_*,megamemory_*,codebase-memory-mcp_*,sqlite_*,github_*,context7_*,sequential-thinking_*all work with the underscore. Thebrowser*glob does not coverplaywright_*, so both forms are needed if you want to hide both.opencode_*is also matchable and covers the mutating built-ins (session_move,session_rename).Open question
Is
tools:meant to be recognized-and-deprecated in v2 rather than unrecognized? If the fix for the unrecognized-key path is to route the known keys correctly instead of discarding the whole frontmatter,tools:could at least warn (asname:arguably should) instead of silently eating the neighbouringpermissions.rekram1-node commentedon Oct 22, 2026
Will be fixed with #58218. Agent files will be read as one format. A file that uses any V2 field (
permissions,request,system,disabled) is read as V2, and V1 fields in it, likename,tools,permissionortemperature, are ignored with a warning in the log. Files without V2 fields are still read as V1. If your agent mixestools:withpermissions:, move those rules intopermissions. See the migration guide.