All Agent Engineering

Check OpenCode file permission and wildcard rule precedence

Rebuild ordered rules, defaults and directory checks per path to get an effective decision table for each read and edit action.

AINavWritten / Updated
On this page

At a glance

File permission mistakes are usually not wrong rules but order, wildcard reach and default policy stacking without being walked through one by one. For "read and write path rules, sensitive files and rule conflicts", this guide produces a per-path effective decision table. Command approval is out of scope; only read, edit and directory boundaries are handled, based on the OpenCode permissions documentation. The product was not run.

Runtime and applicability

Article type
Engineering practice
Verified
Applies to
  • OpenCode Check OpenCode file permission and wildcard rule precedence

Execution locations and responsibilities

  • OpenCode configuration loader and runtime Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Engineering workflow order
Engineering workflow order1. Build the path and action list → 2. Rebuild the ordered rule list → 3. Match each rule by wildcard → 4. Pass the external directory check first → 5. Take the last match and handle multiple resources → 6. Layer saved approvals and policies → 7. Give glob and grep their own column. Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.1. Build the path and action list2. Rebuild the ordered rule list3. Match each rule by wildcard4. Pass the external directory check first5. Take the last match and handle multiple resources6. Layer saved approvals and policies7. Give glob and grep their own column

Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.

When to use

  • The base policy, lower-priority configuration, global rules and agent rules are joined in order, and the last matching rule wins. A later broad rule can cover an earlier narrow one.

When not to use

  • This table covers read and edit paths only. Shell command approval has its own guide and is not repeated here, and path rules cannot stand in for shell rules.
  • The grep resource is a regular expression and the glob resource a pattern; the documentation does not say how they interact with denied paths, so this guide makes no claim.
  • No matching rule defaults to ask, but a matching rule can itself return ask, including default sensitive-file rules. Record its actual source rather than assuming ask appears only without a match.

Prerequisites and input

  • You have a list of paths to check, including sensitive files, example files, subdirectory files and files outside the project.
  • You can obtain every configuration that takes part in the merge: lower-priority configuration, global rules and the current agent's rules, and you know the configuration loader reads them while the runtime enforces them.
  • You can tell allow, ask and deny apart, and accept the documented convention that no matching rule gives ask.

Engineering checks

Rule sequence — The base policy, lower-priority configuration, global rules and agent rules are joined in order, and the last matching rule wins. A later broad rule can cover an earlier narrow one.

Path matching and directory boundary — Wildcards match the whole value and * crosses /. A path outside both the Location and its non-root worktree is checked against external_directory first, then read or edit.

Approvals and policies on top — Saved approvals are project-scoped allow rules and never override a deny; a policy can only turn allow or ask into deny. The table should mark separately whether these two layers were inspected.

1. Build the path and action list

Where: the decision table draft. Input: paths and actions to check. Action: one row per path and action, taking only read and edit; mark whether the path is relative inside the Location or a canonical absolute external path. Done when: every row has an action and a path type. Stop if: you cannot tell whether a path is in the Location, in the non-root worktree or external; settle that first, since a relative mutation path can leave the Location while staying inside the worktree.

2. Rebuild the ordered rule list

Where: the merged ordered permission rules. Input: the current agent identity and all rule sources. Record the base policy, then built-in additions for that agent, including plan edit restrictions or explore action restrictions; explicitly record the absence of a corresponding built-in addition for a custom agent. Append lower-priority configuration, global rules and agent rules in the documented order, applying the last matching rule. Completion: each rule has a source and the baseline matches the current agent identity. Stop without deriving an allow decision if a built-in policy or source is missing.

3. Match each rule by wildcard

Where: the "match" column of the table. Input: the rule list and the paths. Action: match the whole value; * matches zero or more characters including /, ? matches exactly one character, anything else is literal; backslashes are normalized to slashes and matching is case-insensitive on Windows; a leading ~ or $HOME in read, edit and external_directory is expanded when configuration loads. Done when: every rule has a match or no-match for every path. Stop if: a rule's resource is really shell command text; it does not belong in this table, so move it out unchanged.

4. Pass the external directory check first

Where: the directory-check column. Input: external paths. Apply external_directory before read/edit. A default directory allow or absent additional ask means only this directory check may not prompt; read/edit rules, saved approvals and policies can still prompt or deny. It does not establish that the overall access will not prompt. Completion: retain directory effect separately from the subsequent access effect. Stop at the directory-only conclusion if later layers are unknown; final permission remains unconfirmed.

5. Take the last match and handle multiple resources

Where: the "configured-rules result" column. Input: the match results. Action: for each path and action take the effect of the last matching rule; with no match at all the result is ask. When one operation touches several resources, such as a patch changing several files, any deny denies the whole operation, otherwise any ask asks, otherwise it is allowed. Done when: each row holds a single effect. Stop if: one path in a patch cannot be determined; mark the whole patch "undetermined".

6. Layer saved approvals and policies

Where: the last two table columns. Input: the project's saved approvals and any global or managed policies. Action: saved approvals are project-scoped allow rules and never override a configured deny; a policy runs after rules and saved approvals and only turns allow or ask into deny, never granting access; global and Console-managed policies override project configuration. Done when: every row states whether these two layers were inspected. Stop if: saved approvals or managed policies are not visible; write "configured rules only" and do not present the row as a final allow.

7. Give glob and grep their own column

Where: a supplementary area of the table. Input: search actions. Action: the glob resource is the requested glob pattern and the grep resource is the requested regular expression, not the search path, so a path-based read deny cannot be applied to these rows directly. Done when: these actions are listed separately and not mixed into the per-path conclusions. Stop if: you are about to infer from a path rule whether grep can reach a file; the documentation gives no such inference.

Task example

Original paper walkthrough, without observed execution: start with the base rules, then append user read:* allow, read:*.env deny, read:secrets/* deny, and edit:docs/* allow. For .env, the later *.env deny wins. For .env.example and src/.env.local, the last matching rule is the user read:* allow; the earlier default env ask does not remain effective. Both secrets/key.pem and secrets/sub/a.txt match secrets/*, because * can span /. Moving the secrets/* deny before read:* allow reverses that decision. For a built-in agent, also account for its additional policy before judging effective access.

Completion checks

  • Input ownership: each row's path, action, rule source and path type line up.
  • Execution location: you can explain that the configuration loader merges the rules while directory checks and the final decision happen in the runtime, and the table marks layers that were not inspected.
  • Result contract and stop: each row holds one effect or "undetermined", every "configured rules only" row is explained, and you stopped on any rule of unknown origin.

Verification scope

The OpenCode permissions documentation was read. Installation, login, API execution and output were not tested. Paths and rules are invented, and the table must be regenerated against a real configuration.

Sources

All links are official pages; verification dates are listed per source, and links point to the version checked.

  1. OpenCode · OpenCode documentation: opencode-permissions

Found an error? Tell us →