Skip to content

agents: markdown frontmatter "permissions" (V2) parsed but never applied to sessions #50598

Closed

Description

@MikeCHOKKI

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

  1. 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.
  2. Reload (file is re-discovered at service start) and query the resolved agent:

    opencode service restart
    opencode api get /api/agent/reviewer
  3. In the response, compare the two permission fields:

    • data.request.body.permissions contains 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.
  4. Run a session with that agent (e.g. opencode run --agent reviewer) and attempt write/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

Activity

  1. github-actions commented on Sep 22, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. martin-braun commented on Sep 23, 2026

    @martin-braun

    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.

  3. Bigbrotha12 commented on Sep 26, 2026

    @Bigbrotha12

    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 — including permissions — into request.body, so nothing is applied. The common real-world trigger is the legacy name: field.

    Minimal repro (two agents differing only by name:):

    ~/.config/opencode/agents/_fresh_named.md

    ---
    name: _fresh_named
    description: repro with legacy name key
    mode: subagent
    permissions:
      - action: edit
        resource: "*"
        effect: deny
      - action: shell
        resource: "*"
        effect: deny
    ---
    body

    ~/.config/opencode/agents/_fresh_unnamed.md — identical minus the name: line.

    opencode reload then opencode debug agents:

    _fresh_named     top-level permissions=[]                       request.body={'permissions': [edit deny, shell deny]}
    _fresh_unnamed   top-level permissions=[edit deny, shell deny]  request.body={}
    

    So on 2.0.18 the deny rules apply only for the file without name:.

    Additional observations:

    • It is not specific to name. Any unknown key behaves the same: with unknownkey: hello plus permissions, request.body contains both unknownkey and permissions, and the rules are still dropped.
    • The legacy V1 block still works even with name: present (permission: { edit: deny, bash: deny } is applied as shell), so only the native V2 permissions key is affected.
    • The migration guide lists agent name as accepted-but-unsupported and says it is ignored "with a warning"; no warning is emitted and permissions is silently discarded.
    • Impact: a subagent intended to be read-only silently keeps default allow-all.
    • Workaround while migrating: strip legacy/unrecognized frontmatter keys (especially name) so only recognized keys remain.
  4. Kirytho commented on Sep 27, 2026

    @Kirytho

    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 permissions ordering problem.

    tools: is another trigger, and it's a documented v1 key that the migration path tells people to keep

    Two agents that differ only by the legacy tools: key:

    ---
    description: read-only reviewer
    mode: subagent
    tools:
      "sqlite_*": true
    permissions:
      - action: "browser*"
        resource: "*"
        effect: deny
      - action: "sqlite_*"
        resource: "*"
        effect: allow
    ---
    _with_tools     top-level permissions=[]                       request.body={'tools': {...}, 'permissions': [...]}
    _without_tools  top-level permissions=[browser* deny, sqlite_* allow]  request.body={}
    

    So on 2.0.18, tools: behaves exactly like name: — it routes the whole frontmatter into request.body. Worth noting the severity difference from the name: case: name: is undocumented-but-tolerated, whereas tools: is the v1 tool-gating key that the v1→v2 migration path encourages people to carry over, and the docs tell you tools maps to permissions. So a subagent written to encapsulate one MCP is a very natural thing to end up with tools: 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 declared deny rules do not strip anything from the tool catalog, and the permission array is sent to the model provider as an unknown permissions body param on every request.

    Workaround: drop tools: and make the allow the last permissions rule

    The 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 to tools: { "sqlite_*": true } and parses correctly:

    permissions:
      - action: "github_*"
        resource: "*"
        effect: deny
      - action: "browser*"
        resource: "*"
        effect: deny
      - action: "sqlite_*"
        resource: "*"
        effect: allow   # must be last, otherwise the deny above it wins

    With this, opencode debug agents shows 22 rules (9 built-in defaults + 4 global from opencode.json + 8 agent rules + the trailing allow), request.body is {}, and the tool catalog drops from 110 to 12. Ordering matters: with the allow listed before the deny for the same namespace, the deny wins and the tools vanish entirely.

    Two action-name data points that cost me some time

    • browser is a built-in namespace, not an MCP, and its action name is browser* — no underscore. browser_* matches nothing.
    • MCP tools are <server>_<tool>, so the browser* form does not work for them: playwright_*, megamemory_*, codebase-memory-mcp_*, sqlite_*, github_*, context7_*, sequential-thinking_* all work with the underscore. The browser* glob does not cover playwright_*, 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 (as name: arguably should) instead of silently eating the neighbouring permissions.

  5. rekram1-node commented on Oct 22, 2026

    @rekram1-node
    Member

    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, like name, tools, permission or temperature, are ignored with a warning in the log. Files without V2 fields are still read as V1. If your agent mixes tools: with permissions:, move those rules into permissions. See the migration guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions