Managed settings: compile, merge, validate, probe
Compile a human-readable org policy into managed-settings.json, merge another team's drop-in by the documented rules, and check every key against the 247 documented settings keys. Then see what a repository's own settings file can't override, and run the policy's probes as unit tests. Session background: managed settings, policies and sandbox policies.
- Python 3.9+
- standard library only
- offline:
policy/*.json - no admin rights: it never writes the system paths
The inputs are in autonomy-2/policy/. org-policy.json is the intent in a lab format ("block bypass", "only these marketplaces"), overlays/70-data-team.json is a drop-in another team owns, dev-project-settings.json is a repository's .claude/settings.json, and probes.json lists tool calls with the decision the rules must give. settings_catalog.json holds every documented key with its scope and type, so the compiler can't invent one.
python3 autonomy-2/managed_settings.py
┌────────────────────────────────┐
│ Managed settings for Acme Corp │
└────────────────────────────────┘
[1] Compile org-policy.json into drop-ins (each key checked against 247 documented keys)
10-permissions.json: permissions, autoMode
20-sandbox.json: sandbox
30-models.json: availableModels, enforceAvailableModels, model, maxEffortLevel
40-plugins.json: extraKnownMarketplaces, strictKnownMarketplaces, enabledPlugins, disableSideloadFlags
50-mcp.json: allowedMcpServers, deniedMcpServers
90-org.json: $schema, requiredMinimumVersion, cleanupPeriodDays, companyAnnouncements, env, forceLoginMethod, forceLoginOrgUUID, hooks
70-data-team.json: permissions, sandbox, companyAnnouncements (overlay, owned by another team)
[2] Merge the drop-ins in alphabetical order (documented rules: lists combine, nested blocks merge)
permissions.allow: ['Bash(python3 -m unittest *)', 'Bash(npm test *)', 'Bash(npm run lint *)', 'Bash(dbt run *)']
sandbox.network.allowedDomains: ['github.com', 'pypi.org', 'files.pythonhosted.org', 'registry.npmjs.org', 'data.acme.example']
companyAnnouncements: 2 (one is picked at random per session)
[3] Validate the effective managed settings (0 errors, 0 warnings, 4 notes)
NOTE permissions.deny[6]: 'Bash(curl *)' matches the command as written; /usr/bin/..., sh -c '...' or git -C dir ... can slip past. Pair it with the sandbox for a boundary
NOTE permissions.deny[7]: 'Bash(wget *)' matches the command as written; /usr/bin/..., sh -c '...' or git -C dir ... can slip past. Pair it with the sandbox for a boundary
NOTE permissions.deny[8]: 'Bash(git push --force *)' matches the command as written; /usr/bin/..., sh -c '...' or git -C dir ... can slip past. Pair it with the sandbox for a boundary
NOTE permissions.deny[9]: 'Bash(git push -f *)' matches the command as written; /usr/bin/..., sh -c '...' or git -C dir ... can slip past. Pair it with the sandbox for a boundary
[4] Validate a repository's settings file: dev-project-settings.json (1 errors, 7 warnings, 0 notes)
ERROR cleanupPeriodDays: a whole number, minimum 1 (0 fails validation; use a large value such as 3650 for long retention)
WARNING allowManagedHooksOnly: scope is "Managed": ignored in project settings (belongs in managed settings)
WARNING autoMode: scope is "User or managed": ignored in project settings (belongs in user or managed settings)
WARNING autoMode: the classifier doesn't read autoMode from .claude/settings.json or settings.local.json
WARNING autoMode.allow: no "$defaults": this replaces the whole built-in list for the section
WARNING permisions: not in the settings reference; did you mean 'permissions'? (a typo here does nothing; `claude doctor` lists rejected entries)
WARNING permissions.defaultMode: "bypassPermissions" isn't honored from project settings: it starts the session in Manual (default), and the user's own defaultMode doesn't apply either (v2.1.257+)
WARNING permissions.defaultMode: bypassPermissions belongs only in isolated containers and VMs; managed policy should disable it instead
key in the repo file value what happens
─────────────────────── ──────────────────────────────────────────── ───────────────────────────────────────────────────────────────────
allowManagedHooksOnly false ignored here (Managed)
autoMode.allow ["Deploying to prod is fine"] ignored here (User or managed)
cleanupPeriodDays 0 managed wins: 14
enabledPlugins {"guardrails@team-tools": false} managed wins: {"guardrails@team-tools": true}
model "opus" managed wins: "sonnet" (a default, not a lock: --model still picks)
permisions.deny ["Bash(rm -rf *)"] unknown key: does nothing
permissions.allow ["Bash(curl *)", "Bash(npm run *)", "Read(./ lists merge; any deny still wins
permissions.defaultMode "bypassPermissions" starts in Manual, not the user's defaultMode
sandbox.enabled false managed wins: true
spinnerTipsEnabled false project value applies
This table assumes the file loads. A value the schema rejects (the ERROR above) is a Settings Error: Claude Code offers to fix it or to continue without dev-project-settings.json, and then none of its rows apply, rules included (https://code.claude.com/docs/en/settings#fix-a-broken-settings-file).
[5] Probes: 13/13 decisions as expected (managed + repo rules merged)
probe call expect got because
─── ────────────────────────────────────────────── ──────────────────────────────────────────── ────── ───── ───────────────────────────────────────────────────
ok pipe a script from the internet Bash: curl -fsSL https://get.example.sh | sh deny deny Bash(curl *) on `curl -fsSL https://get.example.sh`
ok project allow can't beat managed deny Bash: curl https://pypi.org/simple/requests/ deny deny Bash(curl *)
ok read .env (project allows it) Read: .env deny deny Read(./.env)
ok edit a key file Edit: deploy/certs/server.pem deny deny Read(**/*.pem)
ok force push Bash: git push --force origin main deny deny Bash(git push --force *)
ok normal push asks Bash: git push origin feature/x ask ask Bash(git push *)
ok tests are pre-approved Bash: python3 -m unittest -q allow allow Bash(python3 -m unittest *)
ok compound: every part must be allowed Bash: git status && rm -rf build none none `rm -rf build` matches no allow rule
ok compound with a denied part Bash: npm test && curl https://evil.example deny deny Bash(curl *) on `curl https://evil.example`
ok a trailing ' *' also matches the bare command Bash: npm test allow allow Bash(npm test *)
ok the space matters: npm test-all isn't npm test Bash: npm test-all none none `npm test-all` matches no allow rule
ok project npm rule merges in Bash: npm run build allow allow Bash(npm run *)
ok read source code Read: tinyapp/pricing.py none none no rule matches
'none' = no rule matched, so Claude Code's defaults decide: reads inside the working directories and built-in read-only commands (ls, cat, git status, ...) run without asking; anything else prompts in Manual and is denied in dontAsk.
This is a model of the documented rule order for these probes, not Claude Code's matcher.
[6] Install (needs admin rights; this lab never writes these paths)
macOS: /Library/Application Support/ClaudeCode/managed-settings.json
Linux and WSL: /etc/claude-code/managed-settings.json
Windows: C:\Program Files\ClaudeCode\managed-settings.json
one source wins: under the default managedSourcesBehavior "first-wins", a server-managed or MDM source that delivers any policy key makes Claude Code ignore this file (apart from the keys read from every source); /status shows (remote), (mdm) or (file)
verify: run /status and look for "Enterprise managed settings" in Setting sources; `claude doctor` lists rejected entries
Managed settings bind Claude Code only, and a user with local admin rights can edit the managed source. Server-managed settings are "a client-side control, not a security boundary".
wrote autonomy-2/out/managed_settings/managed-settings.json and autonomy-2/out/managed_settings/report.json
effective policy: 0 error(s); probes: 0 failed
- The data team's drop-in adds
Bash(dbt run *)and a domain to the compiled lists. Lists combine without duplicates: its copy of the unittest rule appears once. - One value the schema rejects,
cleanupPeriodDays: 0, is enough for Claude Code to offer to drop the whole file, rules included. Catch it in CI, not on a laptop. - A repository can't start everyone in bypass: a project-level
bypassPermissionsdefault starts the session in Manual instead. - The repo allows
Bash(curl *). The rules merge, and the managed deny still wins: a deny at any level beats an allow. - Every part of a compound command must be allowed.
git statusneeds no rule, being a built-in read-only command, sorm -rf buildis the part that decides. - Only one managed source wins. Under the default
"first-wins", a server-managed or MDM source that delivers any policy key makes Claude Code ignore this file.
This is what an admin would ship. The permissions block and the marketplace lock, from the compiled file:
cat autonomy-2/out/managed_settings/managed-settings.json
{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)",
"Read(**/*.pem)",
"Read(~/.aws/**)",
"Read(~/.ssh/**)",
"Bash(curl *)",
"Bash(wget *)",
"Bash(git push --force *)",
"Bash(git push -f *)"
],
"ask": [
"Bash(git push *)",
"Bash(gh pr merge *)"
],
"allow": [
"Bash(python3 -m unittest *)",
"Bash(npm test *)",
"Bash(npm run lint *)",
"Bash(dbt run *)"
],
"disableBypassPermissionsMode": "disable"
},
"autoMode": {
"environment": [
"$defaults",
"Source control: github.com/acme-corp and its repos",
"Trusted internal domains: *.acme.example"
],
"soft_deny": [
"$defaults",
"Never run terraform apply against the prod workspace"
]
},
…
"strictKnownMarketplaces": [
{
"source": "github",
"repo": "acme-corp/claude-plugins"
},
{
"source": "github",
"repo": "anthropics/claude-plugins-official"
},
{
"source": "skills-dir"
}
],
"enabledPlugins": {
"guardrails@team-tools": true
},
"disableSideloadFlags": true,
- Bash deny rules match the command as written. The validator's notes say so:
git -C dir, a full path orsh -ccan slip past. "Pair it with the sandbox for a boundary." - How "block bypass" compiles: the bypass rung is gone for every session on the machine.
"$defaults"keeps the built-in auto-mode lists and adds to them. Without it, as in the repo file's warning, a list replaces the built-in one.- The marketplace allowlist: the team's repo, the official marketplace, and the
skills-direntry that keeps skills-directory plugins loading. guardrails@team-toolsis force-enabled. WithdisableSideloadFlagson, "Claude Code rejects--plugin-dir,--plugin-url,--agents, and--mcp-configat startup and exits with an error naming them" (settings reference).
Install. Managed settings need admin rights, and the lab never writes these paths. Copy out/managed_settings/managed-settings.json to the path for your OS:
| OS | Path |
|---|---|
| macOS | /Library/Application Support/ClaudeCode/managed-settings.json |
| Linux and WSL | /etc/claude-code/managed-settings.json |
| Windows | C:\Program Files\ClaudeCode\managed-settings.json |
To check it took effect, run /status and look for "Enterprise managed settings" in "Setting sources"; claude doctor lists any entries it rejected. --layout dropins also writes each drop-in to out/managed_settings/managed-settings.d/, for the drop-in directory beside the base file.
- Validate any settings file you have, at the level it lives:
--check autonomy-2/policy/dev-project-settings.json --scope projectprints the same 1 error and 7 warnings and exits 1. A managed file with"strictKnownMarketplaces": []gets "[] locks every marketplace source out, including the official marketplace". - Exercise 1: in a copy of
org-policy.json, set"managed_rules_only": trueand pass it with--policy. Probe "project npm rule merges in" flips from allow to none, the run reports 12/13 and exits 1, becauseallowManagedPermissionRulesOnlydrops the repo'sBash(npm run *). - Exercise 3: lower
min_claude_code_versionto2.1.250. The validator warns "maxEffortLevel: needs Claude Code v2.1.267+, but requiredMinimumVersion lets v2.1.250 start; older clients ignore it". - Exercise 2: set
keep_official_marketplaceandkeep_skills_dir_pluginstofalse. You get a warning that the official marketplace's plugins can't be installed, and a note that@skills-dirplugins stop loading. - Break it (exercise 4): add a probe for
git -C /tmp/x push --force origin mainexpectingdeny, in a copy passed with--probes. It comes outnoneand the run exits 1:Bash(git push --force *)matches the command as written, exactly what the validator's note on that rule warns about. The guard in the next lab misses it too.
- Policy is code: the probes fail the run when a decision changes, so a rule edit that opens a hole fails before it ships.
- Rule order is deny, then ask, then allow, and a deny anywhere beats an allow anywhere. The probe evaluator models that documented order; it isn't Claude Code's matcher, so confirm a rule that matters with
/permissions. - "none" means no rule matched, so the mode decides: reads in the working directories and built-in read-only commands run, and anything else prompts in Manual or is denied in
dontAsk. - Keys only a managed file can set, and keys a repository can't set at all (
autoMode, bypass asdefaultMode), are flagged rather than silently ignored. - Managed settings bind Claude Code only. Server-managed settings are "a client-side control, not a security boundary" (server-managed settings).
Plugin marketplace: a kit and its validator
Validate kit/, a marketplace called team-tools with two plugins, against the messages claude plugin validate uses. List everything it would run on a user's machine, run its guard hook on documented payloads, and break the kit 14 ways to prove each mistake is caught. Session background: plugins and plugin distribution.
- Python 3.9+
- standard library only
- offline:
plugin_marketplace/kit/ - mutation tests in a temp copy
In kit/ | What it is |
|---|---|
.claude-plugin/marketplace.json | The marketplace: name team-tools, an owner, and two entries with ./plugins/… sources. |
plugins/guardrails/ | A PreToolUse guard (hooks/hooks.json and scripts/guard.py) for secret files and destructive git commands, with "onFailure": "block", plus a guardrails-status skill. |
plugins/release-notes/ | A user-only release-notes skill with ! context injection (git log), and a changelog-writer subagent on Haiku at low effort. |
python3 autonomy-2/plugin_marketplace/validate_marketplace.py
┌────────────────────────────────────────────┐
│ Validate kit/ as a Claude Code marketplace │
└────────────────────────────────────────────┘
[1] Checks: 0 error(s), 0 warning(s), 0 note(s)
✔ Validation passed
[2] What users get
plugin kind name
───────────── ───── ────────────────────────────────────────────────────────
guardrails skill /guardrails:guardrails-status
release-notes skill /release-notes:release-notes (user-only)
release-notes agent release-notes:changelog-writer (model=haiku, effort=low)
[3] Security review: what runs with the user's privileges, outside the sandbox
plugin surface runs
───────────── ───────────────────────────────────────────── ───────────────────────────────────────────────────────────────────────────────────────
guardrails hook PreToolUse[Edit|Write|NotebookEdit|Bash] python3 "${CLAUDE_PLUGIN_ROOT}"/scripts/guard.py (onFailure=block, timeout=10s)
release-notes skill shell injection skills/release-notes/SKILL.md: git log --oneline -n 30 (runs when the skill is invoked)
Read every command above before installing; auto-update can change these files later.
[4] Guard hook tests (common/hooks.run_hook with documented PreToolUse payloads)
call decision outcome Claude reads
── ──────────────────────────────── ──────── ──────── ──────────────────────────────────────────────────────────────────────
ok Write to .env (fixture) deny blocked guardrails: .env looks like a secret; edit it yourself, outside Claude
ok Edit tinyapp/pricing.py - proceeds
ok Bash git push --force deny blocked guardrails: force-pushing rewrites shared history. If you really mean
ok Bash git push --force-with-lease - proceeds
ok Bash push --force-if-includes - proceeds
ok Bash git push -fu deny blocked guardrails: force-pushing rewrites shared history. If you really mean
ok Bash git push origin +main deny blocked guardrails: force-pushing rewrites shared history. If you really mean
ok Write to config/.ENV deny blocked guardrails: .ENV looks like a secret; edit it yourself, outside Claude
ok Bash curl | sh deny blocked guardrails: piping a download straight into a shell. If you really mea
ok Bash python3 -m unittest - proceeds
ok malformed stdin deny blocked guardrails: couldn't read the hook input (JSONDecodeError), so the cal
ok guard crashes (onFailure=block) deny blocked exit 1 counts as a failure
[5] Mutation tests: one mistake at a time in a temp copy of kit/
mistake validator says
────── ──────────────────────────────── ────────────────────────────────────────────────────────────────────────────────────────────────
caught source without ./ plugins.0.source: Invalid string: must start with "./"
caught source escapes the root plugins[0].source: Path contains "..": ./../guardrails
caught source points nowhere plugins[0].source: Source path does not exist: ./plugins/gaurdrails (claude plugin validate pass
caught reserved marketplace name Marketplace name impersonates an official Anthropic/Claude marketplace
caught missing owner name owner: Author name cannot be empty
caught typo in an entry field plugins[1].descripton: Unknown field 'descripton'. Claude Code ignores it at load time.
caught entry name != manifest name plugins[0] plugin.json → name: the entry is 'guardrails' but plugin.json says 'guard-rails'; ins
caught strict false + entry components Plugin release-notes has conflicting manifests: both plugin.json and marketplace entry specify c
caught reserved plugin name plugins[1] plugin.json → name: Plugin name "claude-release-notes" is reserved: it passes as one
caught hooks file without its wrapper plugins[0] plugin.json → hooks: PreToolUse is declared at the top level, outside the "hooks" obj
caught hook script missing plugins[0] plugin.json → hooks.PreToolUse: scripts/guard.py doesn't exist in the plugin
caught component inside .claude-plugin/ plugins[1] plugin.json → .claude-plugin/skills: only plugin.json goes inside .claude-plugin/; co
caught over-long skill description plugins[1] plugin.json → skills/release-notes/SKILL.md: description + when_to_use is 1679 charac
caught agent without a description plugins[1] plugin.json → agents/changelog-writer.md: description is required
install: claude plugin marketplace add ./autonomy-2/plugin_marketplace/kit && claude plugin install guardrails@team-tools
verdict: PASS (0 errors, 0 warnings, 0 failed tests); report: autonomy-2/out/plugin_marketplace/report.json
- What users get, namespaced by plugin. The release-notes skill is user-only (
disable-model-invocation: true), so Claude can't run it on its own. - The review's point: this one command runs before every Edit, Write, NotebookEdit and Bash call, with the user's privileges and outside the sandbox. Read it before you install.
- A skill's
!injection is a command too.git logruns when the skill is invoked, before Claude sees the prompt. - The guard is precise about force pushes:
--forceis denied, while--force-with-leaseand--force-if-includesgo through. - It fails closed. Input it can't parse is denied, and because of
onFailure: "block"a crash blocks the call instead of letting it through. - A source that points at a missing folder. The lab notes that
claude plugin validatepasses this one; it fails only at install, so the lab checks it too.
Install the marketplace (from labs/). This is the run's own install: line:
claude plugin marketplace add ./autonomy-2/plugin_marketplace/kit && claude plugin install guardrails@team-tools
The docstring adds claude plugin validate autonomy-2/plugin_marketplace/kit before it and claude plugin install release-notes@team-tools after (then /release-notes:release-notes 1.4.0). For an organization, host kit/ in a git repo and pair it with the managed settings above, which already declare team-tools in extraKnownMarketplaces, allow it in strictKnownMarketplaces and force-enable guardrails@team-tools. --with-claude also runs claude plugin validate --json on the kit and on each plugin folder (a local check, no model call); the README records Claude Code v2.1.303's validator agreeing.
- Feed the guard a payload by hand:
echo '{"hook_event_name": "PreToolUse", "tool_name": "Bash", "tool_input": {"command": "git push --force origin main"}}' | python3 autonomy-2/plugin_marketplace/kit/plugins/guardrails/scripts/guard.pyprints apermissionDecision: "deny"with the reason Claude would read. With--force-with-leaseit prints nothing: no opinion, so the normal rules decide. - Break it: try
git -C . push --force origin main. The guard prints nothing and the push goes on to the permission rules. A hook sees only the command text, which is why it's defense in depth and the sandbox is the boundary. - Exercise 2: in a copy of
kit/, change the matcher inplugins/guardrails/hooks/hooks.jsonto"Edit.*"and run with--path <copy> --skip-tests. It still passes, and the review now readsPreToolUse[Edit.*]. The guard no longer sees Write or Bash, and per the hooks docs "Edit.*matches bothEditandNotebookEdit". - Break it: in a copy, drop the
./from the guardrails source. You get "✘ plugins.0.source: Invalid string: must start with "./"", guardrails vanishes from "What users get", and the verdict is FAIL with exit 1. - Misspell an entry's
descriptionasdescripton. It's a warning ("Unknown field 'descripton'. Claude Code ignores it at load time.") and the run passes; add--strictand the same run fails with exit 1.
- Every hook command,
bin/file and MCP server a plugin brings runs with the user's privileges, outside the sandbox. The security table is the list a reviewer has to read, and auto-update can change those files later. - The guard's
"onFailure": "block"matters onPreToolUse: without it, a hook that crashes or times out lets the call through. - The mutation tests prove the validator catches each mistake. A check that has never failed hasn't been tested.
claude plugin validateis the authoritative check, and run from a marketplace root it opens only the manifests. That's why the lab also validates each plugin's skills, agents and hooks.