Hooks
Atrium learns everything it knows about a session from its runner's hooks. Without them, a session is invisible until it makes a gated tool call.
What the board wires for you
Open the rooms tab and press hooks on the claude row, or on the codex row. The button counts what is
missing. Atrium writes the entries into your own settings file, ~/.claude/settings.json for claude and
~/.codex/hooks.json for codex, and keeps a dated copy of the old file first.
| Hook | What it gives you |
|---|---|
SessionStart | A card appears when a session opens, before it does anything. |
SessionEnd | The card goes to finished when the session closes. |
PreToolUse | Tool activity, plus the installed Claude permission gate. |
PermissionRequest | Codex native approvals wait for an answer on the board. |
PostToolUse, PostToolUseFailure | When that tool finished, so the card stops claiming it. |
UserPromptSubmit | You answered, so the card leaves ready. |
SubagentStart, SubagentStop | The subagent count on the card. |
Notification | The session put a question on screen and is blocked on you. |
PreCompact | The session is compacting, and still working. |
Stop | A queued message reaches a session sitting idle. Offered by name, never installed by default. |
Each entry is a subcommand of atrium itself, such as atrium hook --event tool-start, with the absolute path of
the binary the room runs from.
The installer keeps any key it does not know, keeps your matchers and timeouts, and replaces an entry that reports the same event instead of adding a second one. Running it twice adds nothing. It refuses to touch a file that will not parse. Sessions already running keep their old settings, because Claude Code reads the file when a session starts.
A Stop hook that answers block tells the model to keep going. That is how a queued message reaches an idle
session, and it is also the risk. Atrium's version exits silently when stop_hook_active is set and delivers
each message once. That is why "install all" leaves it out and the board asks for it by name.
The permission gate
The installer writes Claude's gate under PreToolUse and Codex's under PermissionRequest. Both post to the
room's agent port and wait for its permission chain. Claude's gate runs on eligible tool calls. Codex's gate
runs only when Codex itself needs approval, so already-permitted calls do not consult Atrium rules.
For Codex, run atrium hook install --runner codex. Add --event turn-end in a separate invocation to opt into
Stop and queued-message delivery at turn end. Restart Codex and review the hook definitions with /hooks.
Codex skips untrusted hooks. Keep native approvals enabled, for example with
codex --ask-for-approval on-request --sandbox workspace-write.
A native Codex approval cannot rewrite tool input. If you edit a command on the board, the hook denies the original call and tells the model to retry with the approved edit. Missing room or malformed responses leave Codex's own approval flow in control. There is no terminal prompt detection or answer typing.
The manual script below remains a Claude PreToolUse example. Avoid installing it alongside the installed gate, which would ask the same question twice. Codex PermissionRequest uses a different output format.
The contract
POST http://localhost:7777/permission
{
"agent": "fix-login",
"tool": "Bash",
"command": "go test ./...",
"cwd": "/home/me/src/api",
"pid": 4242,
"tool_use_id": "toolu_01...",
"details": "the diff for an edit, or the content for a write"
}
The reply arrives when you, a rule or auto mode decides:
{ "decision": "approve", "reason": "", "command": "" }
decisionisapproveorblock. On a block, handreasonback to the agent. It is your "do this instead".commandis present only when the operator edited the command before approving. That approval is for the edited command, not the original. A hook must run the replacement, or refuse, and never run the original. The script below refuses and tells the agent the edited command to run instead.pidis the runner's own process. It lets atrium tell a live session from a dead one for free.tool_use_idis Claude Code's id for this attempt. Send it, so a retried request is recognised as the same question and never asked twice.detailsis what the tool would do. Send it, and the board draws a real diff.
Which sessions to gate
ATRIUM_PERM_GATE in the session's environment decides first:
| Value | Effect |
|---|---|
on | Gate every session. |
off | Every atrium hook exits at once. Nothing is reported or gated. |
| unset | Ask atrium: GET /gate?agent=<name> answers {"gate":true} after the session ran atrium join. |
Asking atrium is what makes atrium join and atrium leave take effect on the very next tool call, with no
restart.
A starting script
This PowerShell hook follows the contract. It is a starting point, not a finished tool: adapt the command it sends
for the tools you care about, and add details for edits. It needs PowerShell 7 (pwsh) on the PATH. Every docs
build runs this exact script against a mock of atrium: approve, block, an edited approval, an ungated session,
both ATRIUM_PERM_GATE values, and atrium being unreachable (website/scripts/test-gate-hook.js).
Every failure path exits 0 with no decision, so Claude Code falls back to its own permission prompt. That is the fail-open rule below. A session is never stuck because atrium stopped, and it is also not gated by atrium while atrium is away.
# atrium-gate.ps1: the permission gate. Every path exits 0, and an unreachable atrium means ungated.
try {
if ($env:ATRIUM_PERM_GATE -eq 'off') { exit 0 }
$in = [Console]::In.ReadToEnd() | ConvertFrom-Json
$hub = if ($env:ATRIUM_HUB_URL) { $env:ATRIUM_HUB_URL } else { 'http://localhost:7777' }
$agent = if ($env:ATRIUM_AGENT_NAME) { $env:ATRIUM_AGENT_NAME } else { Split-Path -Leaf $in.cwd }
if ($env:ATRIUM_PERM_GATE -ne 'on') {
$g = Invoke-RestMethod "$hub/gate?agent=$([uri]::EscapeDataString($agent))" -TimeoutSec 2
if (-not $g.gate) { exit 0 }
}
$command = if ($in.tool_input.command) { $in.tool_input.command } else { $in.tool_input.file_path }
$body = @{
agent = $agent; tool = $in.tool_name; command = $command
cwd = $in.cwd; tool_use_id = $in.tool_use_id
} | ConvertTo-Json -Compress
$r = Invoke-RestMethod "$hub/permission" -Method Post -Body $body -ContentType 'application/json'
$decision = if ($r.decision -eq 'approve') { 'allow' } else { 'deny' }
$reason = $r.reason
# An approval of an EDITED command does not approve the original. Refuse, and hand the edit to the agent.
if ($decision -eq 'allow' -and $r.command -and $r.command -ne $command) {
$decision = 'deny'
$reason = "The operator approved an edited command instead. Run exactly this: $($r.command)"
}
@{ hookSpecificOutput = @{
hookEventName = 'PreToolUse'; permissionDecision = $decision; permissionDecisionReason = $reason
} } | ConvertTo-Json -Compress
} catch { }
exit 0
Register it beside atrium's own PreToolUse entry, with a long timeout, because the request waits for you:
{
"hooks": {
"PreToolUse": [
{
"matcher": "",
"hooks": [
{ "type": "command", "command": "pwsh -NoProfile -File /path/to/atrium-gate.ps1", "timeout": 86400 },
{ "type": "command", "command": "/path/to/atrium hook --event tool-start" }
]
}
]
}
}
Rules every atrium hook follows
Keep these in any hook you write. They are why the gate is safe to leave on.
- A hook never fails a session. Exit 0 whatever happens. A session must never fail to start, end a turn or make a tool call because atrium was not listening.
- Unreachable means ungated. When atrium is down, approve instead of blocking. A gate that fails closed stops all work the moment atrium does.
- Nothing is retried on the hot path.
PreToolUseruns constantly. - Nothing is logged on success. A hook that prints on every tool call is a hook you turn off.