Sub topic 10
User, project, and organization settings: who wins
This chapter assumes you know allow, ask, and deny decisions, approval modes, and how allow and deny patterns match commands. It also assumes you know grant scopes (once, session, always). Here the question is what happens when several configuration files say different things about the same action.
Exact file names and merge behavior differ between tools. The model below is common enough to learn once and then check against your tool's documentation.
Why settings come in layers
A single settings file would not fit the people involved. An organization wants some actions blocked on every machine. A project team wants shared rules, such as "tests may run without asking". An individual wants personal preferences. A single session sometimes needs a one-off change.
Most agents therefore read several layers and combine them. The combining rules decide whether your safety setup holds up.
| Layer | Who controls it | Typical contents | Where it usually lives |
|---|---|---|---|
| Organization (managed) | Security or IT administrators | Hard denies, a maximum approval mode, approved external tools | A system path or a policy pushed to devices |
| User (global) | You | Default mode, personal allow rules | A file in your home directory |
| Project (shared) | The repository's maintainers | Rules for the project's test and build commands | A file committed to the repository |
| Project (local) | You, for one repository | Personal overrides, not committed | An ignored file in the repository |
| Session | You, right now | Command-line flags, grants made in prompts | Memory, gone when the session ends |
Session grants are the "this session" scope from the earlier chapter on grant scope. They are the most specific and the shortest-lived layer.
The two directions of precedence
"Who wins" has two different answers, depending on whether a setting makes the agent more permissive or more restrictive.
- Specificity wins for preferences. For a setting such as the default approval mode, the more specific layer normally overrides the broader one. A session flag beats a project file, and a project file beats your user file.
- Restriction wins for safety. A deny rule in any layer blocks the action, no matter what other layers allow. An organization ceiling on the approval mode cannot be raised by a lower layer.
This follows from the allow, ask, deny precedence you already know. Deny is evaluated first, and the layers extend that principle. A lower layer can add restrictions freely. It can only add permissions inside the space the higher layers leave open.
Lists: merge or replace
Rule lists are where tools differ most, and where mistakes hide. There are two behaviors.
- Merge (union). Entries from all layers are combined. Your user file allows
git status, the project file allowspytest*, and the result allows both. - Replace. The most specific layer that defines the list wins, and the lists from broader layers are ignored.
Replacement is dangerous for deny lists. If a project file defines its own deny list and that replaces your user-level list, the project silently removes your protections. Check how your tool treats each list before you assume that a deny rule you wrote still applies. Organization-level denies should always be merged in, so that no lower layer can drop them.
A working model in code
This sketch implements the model above. Deny rules are a union across all layers. Allow rules are a union. The mode comes from the most specific layer that sets one, and the organization's ceiling caps it.
from fnmatch import fnmatch
MODES = ["read-only", "default", "auto-edit", "autonomous"]
ORDER = ["user", "project", "local", "session"] # least to most specific
def effective(org: dict, layers: dict) -> dict:
deny = list(org.get("deny", []))
allow = []
mode = "default"
for name in ORDER:
cfg = layers.get(name, {})
deny += cfg.get("deny", [])
allow += cfg.get("allow", [])
mode = cfg.get("mode", mode) # most specific layer wins
ceiling = org.get("max_mode", MODES[-1])
if MODES.index(mode) > MODES.index(ceiling):
mode = ceiling # organization cap
return {"deny": deny, "allow": allow, "mode": mode}
def decide(command: str, cfg: dict) -> str:
if any(fnmatch(command, p) for p in cfg["deny"]):
return "deny"
if any(fnmatch(command, p) for p in cfg["allow"]):
return "allow"
return "ask"
org = {"deny": ["curl *"], "max_mode": "auto-edit"}
layers = {
"user": {"allow": ["git status"], "mode": "autonomous"},
"project": {"allow": ["pytest*", "curl *"]},
}
cfg = effective(org, layers)
print(cfg["mode"]) # auto-edit
print(decide("curl example.com", cfg)) # deny
print(decide("pytest -q", cfg)) # allow
print(decide("npm install", cfg)) # askThree things happen here. The user asked for autonomous, but the organization ceiling lowers it to auto-edit. The project allows curl *, but the organization deny wins. Anything no layer mentions falls back to ask.
Project settings are untrusted input
A project settings file is committed to the repository. When you clone a repository, you also receive its agent configuration, and you did not write it. A malicious or careless file could allow dangerous commands, switch the mode to autonomous, or register an external tool server. This is a form of the prompt injection problem: the repository is untrusted content that tries to give the agent orders.
Good tools reduce this risk in several ways:
- They ask you to trust a project before they read its settings.
- They let project files add restrictions freely, but require your confirmation before loosening anything.
- They never let project files change organization policy or raise the mode above your user setting.
When a tool does not do this, review the project's agent configuration before you open an unfamiliar repository with the agent. Treat it like a Makefile or a git hook: it runs with your privileges.
Organization policy: what it can and cannot do
Organization settings are meant to be unoverridable. They are usually delivered through a location only administrators can write, such as a system directory or a device-management profile. Typical uses:
- Deny lists for destructive or network commands that no user should auto-approve.
- A mode ceiling, for example "nobody may run fully autonomous on a laptop".
- An allowlist of external tool servers, so users cannot add arbitrary ones.
- Required sandbox settings, so that enforcement does not depend on user choices.
Organization policy has limits. It is only as strong as the layer below it is honest: a user with full control of their machine can often work around a file-based policy. For a strong guarantee, pair policy with enforcement outside the agent, such as the sandboxes from the earlier chapter or network egress controls. A policy file expresses intent. A sandbox enforces it.
Debugging "why was this allowed?"
Layered settings make behavior harder to predict, so check the effective result and not just the file in front of you. When a command runs without asking, or is blocked unexpectedly, work through this list:
- Find the tool's command or screen that prints the effective configuration, and read which layer each rule came from.
- Check for session grants. A grant made earlier ("always allow this command") may be stored in a settings file you forgot about.
- Look for a local, uncommitted file that overrides the shared project file. Two teammates can see different behavior in the same repository for this reason.
- Confirm the list behavior (merge or replace) for the key you are debugging.
- Check the working directory. Many tools search for project settings upward from where the agent started.
Practical recommendations
- Put hard denies at the highest layer you control, and keep them out of files that lower layers can replace.
- Keep project settings narrow: test, lint, and build commands. Leave modes and secrets handling out of them.
- Keep personal habits, such as a looser mode, in user or local files, not in committed files.
- Review changes to agent configuration in code review, like any other change that affects security.
Exercise
Your user settings deny git push --force*. A teammate adds a project settings file with its own deny list containing only rm -rf *, and your tool replaces lists instead of merging them. What happens when the agent tries git push --force origin main, and what are two ways to fix it?
Show answer
The project's deny list replaces yours, so the force push is no longer denied. It falls through to allow rules or to ask, depending on the other settings. Fixes: move the rule to the organization or another layer that is always merged, so it cannot be replaced. Or repeat the rule in the project file. A better long-term fix is to use a tool or setting that merges deny lists. Add a code-review check for changes to agent configuration so a replacement like this is noticed.
Exercise
The organization sets max_mode to auto-edit. Your user file sets autonomous, and you pass a session flag asking for autonomous as well. Which mode is in effect, and why?
Show answer
auto-edit. The most specific layer (the session flag) wins among preferences, but the organization ceiling caps the result because restrictions from higher layers cannot be raised by lower ones.