Skip to content

feat(ctl): innerwarden agent install-hook — enforce the guard in Claude Code#1129

Merged
maiconburn merged 1 commit into
mainfrom
feat/agent-install-hook
Jun 28, 2026
Merged

feat(ctl): innerwarden agent install-hook — enforce the guard in Claude Code#1129
maiconburn merged 1 commit into
mainfrom
feat/agent-install-hook

Conversation

@maiconburn

Copy link
Copy Markdown
Collaborator

What

agent mcp-serve and POST /api/agent/check-command are advisory — a coding agent running its raw shell tool never asks. New innerwarden agent install-hook wires the enforcing path for Claude Code:

  • writes a fail-closed guard script (~/.config/innerwarden/claude_code_guard.sh) that POSTs each proposed shell command to the loopback check-command brain,
  • idempotently merges a PreToolUse Bash hook into the agent's settings.json (~/.claude/settings.json by default) pointing at it.

So every command the agent proposes is inspected before it runs and blocked (exit 2) when the verdict is deny (or review with --block-review); if the agent is unreachable the hook fails closed.

Flags: --agent (default claude-code), --settings, --url (default https://127.0.0.1:8787), --block-review.

Why

The 2026-06-27 AI-coding-agent guardrail evaluation showed the marketed guardrail only inspects MCP-proxied or check-command-POSTed calls; a raw-shell agent (claude -p --dangerously-skip-permissions) bypassed it entirely. A deterministic PreToolUse hook is the in-path enforcement that survives the model misjudging a command. Proven live: an always-deny hook blocked the agent's shell tool even in headless mode, and a curl|sh installer (check-command deny) was blocked.

Tests

  • merge: empty / idempotent / preserves existing keys+hooks / repairs non-object root.
  • guard script: deny-only vs --block-review, the check-command call, fail-closed on error.
    cargo clippy -p innerwarden-ctl -D warnings + fmt clean.

CI note: the ctl suite currently has one unrelated red — ops::cmd_tune_applies_raise_suggestion_and_writes_audit, a UTC/local-date boundary flake fixed by #1128. Once #1128 lands, this branch rebases green.

🤖 Generated with Claude Code

@maiconburn maiconburn requested a review from esteves-uk as a code owner June 27, 2026 23:22
@codecov

codecov Bot commented Jun 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.15385% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/ctl/src/commands/agent_install_hook.rs 84.21% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

@maiconburn maiconburn force-pushed the feat/agent-install-hook branch from d4f61ec to a681699 Compare June 27, 2026 23:46
…de Code

mcp-serve and the check-command endpoint are advisory; a coding agent
running its raw shell tool bypasses them. New 'agent install-hook' wires
the ENFORCING path: it writes a fail-closed guard script and a PreToolUse
Bash hook into the agent's settings.json so every shell command the agent
proposes is POSTed to the loopback check-command brain and blocked
(exit 2) before it runs when dangerous. Currently supports Claude Code
(~/.claude/settings.json); --settings/--url/--block-review override.
Idempotent JSON merge preserves existing settings + hooks. Unit tests
cover the merge (empty/idempotent/preserves/repairs) and the generated
script (deny-only vs block-review, check-command call, fail-closed).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@maiconburn maiconburn force-pushed the feat/agent-install-hook branch from a681699 to 40c77e8 Compare June 27, 2026 23:59
@maiconburn maiconburn merged commit 714ab8d into main Jun 28, 2026
21 checks passed
@maiconburn maiconburn deleted the feat/agent-install-hook branch June 28, 2026 00:10
maiconburn added a commit that referenced this pull request Jun 28, 2026
…#1132)

Bump workspace version 0.15.29 -> 0.15.30 and roll [Unreleased] into
[0.15.30]. Contents:
- agent-guard now denies commands that disable InnerWarden itself (#1127)
- innerwarden agent install-hook: enforcing PreToolUse hook for Claude Code (#1129)
- admin-action audit filename in UTC, not local time (#1128)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants