spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / sec-default / README.md
107 lines · 6.5 KBPreviewCodeRaw
1# sec-default
2
3The security default for organizations. Function hooks give every plugin a
4say on every event, in chain order, and the plugins a person installs sit
5in the user tier, beneath the organization's prepend tier and above its
6append tier. Some of what an organization sets today (its classic hooks,
7its managed CLAUDE.md and rules, its settings, its MCP allowlist) was never
8within a person's reach before function hooks; seated outermost, this
9plugin keeps exactly those out of the user tier's reach and adds no policy
10of its own. Everything else passes through untouched.
11
12It has three moves and nothing else: continue past the user tier
13(`next.to(e, "append")`), refuse a user-tier caller or module by name
14(`{ deny }` when `next.origin.tier` is `user`, `{ refuse }` when a module's
15pinned `e.tier` is), or pass (`next(e)`). A subject's provenance is the
16event's pinned `e.provider`; policy is read through
17`$.settings.read({ source: "policy" })`, one read serving a burst of tool
18calls; both fail closed, so an unreadable policy counts as a policy in force.
19
20`hooks/register.ts` is the module; `hooks/policy/` reads the managed
21settings it decides by.
22
23## The rows
24
25| event | from the outermost seat |
26| --- | --- |
27| `classic.*` | Continue past the user tier: the organization's settings hooks see the engine's input and their answer stands. |
28| `prompt.section`, `prompt.context`, `skill.prompt`, `attribution.text` | Continue past the user tier: managed CLAUDE.md, rules and policy skills reach the model as written. A person's plugins keep `prompt.submit` and its additive context. |
29| `settings.read` | Continue past the user tier: no user hook rewrites what any caller reads as settings, this plugin's own policy reads included. |
30| `tool.describe`, `command.describe`, `agent.offer`, `agent.spawn` | When the subject's pinned `e.provider.tier` is `prepend` or `append` (a policy-installed plugin, the managed folder, a policy MCP server), continue past the user tier; a subject provided by `user`, `builtin` or `core` passes. |
31| `tool.register` | A caller in `prepend` or `append` continues past the user tier. A `user`-tier caller is refused by name while managed settings hold `allowedMcpServers` (set at all, empty included); otherwise it passes. |
32| `tool.list` | The tools of the organization's managed MCP servers are listed as the organization's tiers listed them; every other tool as the user tier left it. With no policy to read, or a refusal from either listing, the organization's listing stands whole. |
33| `plugin.register` | A hooks module in the `user` tier (one a person installed, named with `--plugin-dir`, or keeps in their mods folder) is refused while managed settings set this plugin's `allowManagedModsOnly` option; otherwise it passes. Modules in `prepend`, `append` and `builtin` are never asked about. |
34| everything else | Passes: `prompt.submit`, `turn.*`, `tool.call`, `tool.check`, `command.run`, `command.register`, `session.*`, `ui.*`, `fs.*`, `http.fetch`, `process.run`, `store.*`, `clock.*`, `model.*`, `mcp.call`, `audio.*`, `agent.list`, `engine.create`. |
35
36## Options an administrator sets
37
38One, in managed settings, under this plugin's own `pluginConfigs` entry,
39keyed by the id the CLI builds the plugin in under (only this spelling of the
40id is read):
41
42```json
43{
44 "pluginConfigs": {
45 "cc-plugin-sec-default@builtin": {
46 "options": { "allowManagedModsOnly": true }
47 }
48 }
49}
50```
51
52`allowManagedModsOnly`: only the mods the organization deploys through
53managed settings, and the ones built into Claude Code, load. A hooks module
54a person installed, named with `--plugin-dir` or keeps in their mods folder
55is refused whenever it loads or reloads (one already running when the option
56is set keeps running until then), with one line that names it: `mods are
57limited to your organization's by policy (allowManagedModsOnly); <plugin>
58was not loaded`
59(in the debug log, and on screen where the session hot-reloads the mod's
60folder). A plain `-p` run has it in the debug log alone; the mod is still
61not loaded. Settings hooks, status lines and `/goal` are not touched by it.
62
63- The decision reads the tier the CLI pins on the module and nothing the
64 module says of itself: a person's copy carrying an organization mod's name
65 is still in the `user` tier and is refused.
66- Refused means nothing of the module joins: no hook, no tool, no command.
67 Its top-level code has run once by then, in the closed context every hooks
68 module is evaluated in, with no call on `$` served.
69- Only managed settings are read (`$.settings.read({ source: "policy" })`):
70 the same entry in a person's, a project's or a `--settings` file neither
71 turns it on nor off. On unless absent or `false`, so a mistyped `"true"` or
72 `1` still locks. A value the settings schema rejects (`null`, an object),
73 here or in any other `pluginConfigs` entry, makes the CLI ignore the whole
74 `pluginConfigs` key with a settings warning, and the option reads as unset.
75- It fails closed: when the read of managed settings is refused (a hook beneath
76 denies it) or this plugin's hook fails, its `.catch` refuses the module,
77 with the same line, and names the failure in the debug log; so a policy
78 that cannot be read keeps every person's mod out at load. Where this plugin
79 is not seated there is no such rule, and mods load as they do without it.
80- Where managed settings define `prependPlugins`, that list must name this
81 plugin (next section) for the option to apply.
82- `claude plugin test` is not covered: it runs a mod's tests in an engine of
83 their own and loads nothing into a session.
84
85## What it hooks
86
87`classic.*`, `prompt.section`, `prompt.context`, `skill.prompt`,
88`attribution.text`, `settings.read`, `tool.describe`, `command.describe`,
89`agent.offer`, `agent.spawn`, `tool.register`, `tool.list`,
90`plugin.register`.
91
92## What it calls on `$`
93
94`settings.read`, and `ui.log` to the debug log. It continues to the `append`
95tier with `next.to`, which only a plugin in a managed tier may do.
96
97## Where it is seated
98
99The CLI seats it first in the prepend tier wherever hooks modules load on a
100machine with managed settings or for a Team or Enterprise organization,
101unless managed settings define `prependPlugins`: then that list is the
102whole prepend tier, and the organization names `sec-default@builtin` in it
103at the position it wants, e.g. `"prependPlugins": ["acme-guard@acme-tools",
104"sec-default@builtin"]`, or leaves it out. It is a plugin folder like any
105other, but its one move that matters, `next.to`, is refused outside a
106managed tier, so loading it with `--plugin-dir` seats a plugin that can
107only pass.