# Autonomy 2: Control Planes for Claude Code

Two kits for running Claude Code across an organization. The first compiles a policy into managed settings that sit above every other settings level. The second is a plugin marketplace that distributes skills, agents and hooks to every team.

| Lab | What it does | Session topics |
|---|---|---|
| `managed_settings.py` | Compiles `policy/org-policy.json` into `managed-settings.json`, or into `managed-settings.d/` drop-ins. It merges another team's drop-in by the documented rules and checks every key against the 247 documented settings keys (scope and type) in `policy/settings_catalog.json`. It flags what a repository's own settings file can't override, then runs policy probes: tool calls that must come out deny, ask or allow. | Configuration (settings hierarchy, managed settings, policies), Environment (sandbox policy, safe defaults), Operations (versioning, rollout) |
| `plugin_marketplace/` | `kit/` is a marketplace (`team-tools`) with two plugins. `guardrails` is a fail-closed PreToolUse guard plus a skill. `release-notes` is a user-only skill with `!` context injection, plus a Haiku subagent. `validate_marketplace.py` checks the kit with the messages `claude plugin validate` uses and lists everything the kit executes. It also runs the guard hook on documented payloads and breaks the kit 14 ways to prove each break is caught. | Portability (plugins, the Agent Skills standard), Knowledge Delivery (plugin distribution) |

## Run

```bash
cd labs
python3 autonomy-2/managed_settings.py                          # compile, merge, validate, probe
python3 autonomy-2/managed_settings.py --layout dropins         # write managed-settings.d/*.json instead
python3 autonomy-2/managed_settings.py --check path/to/settings.json --scope project
python3 autonomy-2/plugin_marketplace/validate_marketplace.py    # validate kit/, hook tests, mutation tests
python3 autonomy-2/plugin_marketplace/validate_marketplace.py --with-claude   # also `claude plugin validate --json` (local, no model call)
```

Both labs run offline and write only to `autonomy-2/out/`. `_refresh_catalog.py --fetch` rebuilds the settings catalog from the live docs (`--dry-run` reports added and removed keys without writing; `--out` writes somewhere else). It is the only script here that uses the network, and only when you pass `--fetch`.

## Install

- **Managed settings** need admin rights, and this lab never writes these paths. Copy `out/managed_settings/managed-settings.json` to the path for your OS:
  - 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. Managed settings bind Claude Code only. Server-managed settings are "a client-side control, not a security boundary".
- **Marketplace:** `claude plugin marketplace add ./autonomy-2/plugin_marketplace/kit`, then `claude plugin install guardrails@team-tools`. For an organization, host `kit/` in a git repo and pair it with the policy above. The policy already declares `team-tools` in `extraKnownMarketplaces`, allows it in `strictKnownMarketplaces` and force-enables `guardrails@team-tools`.

## What you'll see

`managed_settings.py` compiles the policy into drop-ins and merges the data team's overlay into them. The overlay's lists are added to the compiled lists, not swapped in for them:

```text
[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)
```

The default run writes the merged result as one `managed-settings.json`. `--layout dropins` also writes each drop-in to `out/managed_settings/managed-settings.d/`, beside it.

A repository's `.claude/settings.json` is checked against the policy. The table shows what each of its keys still controls:

```text
[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: the classifier doesn't read autoMode from .claude/settings.json or settings.local.json
  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).
```

A `bypassPermissions` (or `auto`) default in project or local settings doesn't fall through to the user's own `defaultMode`: `bypassPermissions` starts the session in Manual, and `auto` falls back to the built-in default.

The probes are policy unit tests. The lab exits non-zero if any decision changes:

```text
[5] Probes: 13/13 decisions as expected (managed + repo rules merged)
ok   project allow can't beat managed deny           Bash: curl https://pypi.org/simple/requests/  deny    deny   Bash(curl *)
ok   edit a key file                                 Edit: deploy/certs/server.pem                 deny    deny   Read(**/*.pem)
ok   normal push asks                                Bash: git push origin feature/x               ask     ask    Bash(git push *)
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
  '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.
```

The policy doesn't allow `git status` or `git diff`: built-in read-only commands already run without asking, so an allow rule for them adds nothing. That's also why the compound probe blames `rm -rf build` and not `git status`.

The install step also says which managed source wins:

```text
  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)
```

If you lower `min_claude_code_version` to `2.1.250`, the validator warns about keys that older clients ignore:

```text
  WARNING maxEffortLevel: needs Claude Code v2.1.267+, but requiredMinimumVersion lets v2.1.250 start; older clients ignore it
```

`validate_marketplace.py` lists what users get and every command the kit can run:

```text
[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)
[4] Guard hook tests (common/hooks.run_hook with documented PreToolUse payloads)
ok  Write to .env (fixture)           deny      blocked   guardrails: .env looks like a secret; edit it yourself, outside Claude
ok  Bash git push --force-with-lease  -         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/
caught  source without ./                 plugins.0.source: Invalid string: must start with "./"
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  strict false + entry components   Plugin release-notes has conflicting manifests: both plugin.json and marketplace entry specify c
caught  hooks file without its wrapper    plugins[0] plugin.json → hooks: PreToolUse is declared at the top level, outside the "hooks" obj
verdict: PASS (0 errors, 0 warnings, 0 failed tests); report: autonomy-2/out/plugin_marketplace/report.json
```

With `--with-claude`, Claude Code v2.1.303's own validator agrees. Run from the marketplace root, `claude plugin validate` checks `marketplace.json` and each `plugin.json` but doesn't open skill, agent or hook files, so the lab also validates each plugin folder:

```text
[6] claude plugin validate (the authoritative check)
target         success  errors  warnings  exit
─────────────  ───────  ──────  ────────  ────
kit            True     0       0         0
guardrails     True     0       0         0
release-notes  True     0       0         0
```

## Formats and where they come from

| Encoded format | Source (fetched 2026-10-20) |
|---|---|
| Every settings key, its scope and type (`policy/settings_catalog.json`, re-fetched 2026-10-24: 247 keys) | https://code.claude.com/docs/en/settings-reference |
| Managed file paths, drop-in directory and merge rules, managed-only keys, `managedSourcesBehavior` (first-wins) | https://code.claude.com/docs/en/managed-settings |
| Precedence (managed > `--settings` > local > project > user), list merging | https://code.claude.com/docs/en/settings |
| Permission rule syntax and order, compound commands, `Bash(x *)` vs `Bash(x*)`, Read/Edit paths, built-in read-only commands | https://code.claude.com/docs/en/permissions |
| `allowedMcpServers` / `deniedMcpServers` entries (one key: `serverUrl`, `serverCommand` or `serverName`) | https://code.claude.com/docs/en/managed-mcp |
| `strictKnownMarketplaces` (exact entries, `owner/*` repos, `hostPattern`, `pathPattern`, the `skills-dir` entry), `extraKnownMarketplaces`, `enabledPlugins` | https://code.claude.com/docs/en/plugins/org , https://code.claude.com/docs/en/settings-reference |
| `defaultMode: "bypassPermissions"` / `"auto"` in project or local settings (Manual / the built-in default, v2.1.257+) | https://code.claude.com/docs/en/permission-modes |
| `autoMode` and `"$defaults"` | https://code.claude.com/docs/en/auto-mode-config |
| `marketplace.json` fields, plugin sources, reserved names, validation messages | https://code.claude.com/docs/en/plugins/marketplace-reference |
| `plugin.json` fields, name rules, path rules, the hooks file wrapper | https://code.claude.com/docs/en/plugins/manifest-reference |
| Plugin component folders; plugin agents ignore `hooks`, `mcpServers`, `permissionMode` | https://code.claude.com/docs/en/plugins/components |
| `SKILL.md` frontmatter and the 1,536-character listing cap | https://code.claude.com/docs/en/skills |
| Agent frontmatter (`name`, `description` required; `model`, `effort`, `tools`) | https://code.claude.com/docs/en/sub-agents |
| PreToolUse input and `permissionDecision` output, `onFailure` | https://code.claude.com/docs/en/hooks |

`org-policy.json` and `probes.json` are lab formats. The probe evaluator models the documented rule order for these probes: deny, then ask, then allow; every part of a compound command, `$(...)` included; bare names and single-segment deny patterns at any depth; and `./name` anchored at the current directory. It isn't Claude Code's matcher, so confirm a rule that matters with `/permissions` or a real run.
