Skip to content

Add host-protection hooks for Claude Code and Copilot CLI#16

Merged
aniongithub merged 1 commit into
mainfrom
feature/host-protection-hooks
May 11, 2026
Merged

Add host-protection hooks for Claude Code and Copilot CLI#16
aniongithub merged 1 commit into
mainfrom
feature/host-protection-hooks

Conversation

@aniongithub
Copy link
Copy Markdown
Owner

Summary

PreToolUse hooks that block bash/shell tool calls when a .devcontainer/devcontainer.json exists in the working directory, forcing agents to use devcontainer-mcp MCP tools instead of executing on the host.

Changes

  • hooks/devcontainer-guard.sh — shared hook script supporting both Claude Code (tool_name/tool_input) and Copilot CLI (toolName/toolArgs) payload formats
  • .github/hooks/devcontainer-guard.json — Copilot CLI hook config for this repo
  • install.sh / install.ps1 — auto-install hooks and configure agent environments (Claude Code ~/.claude/settings.json, Copilot CLI ~/.copilot/hooks/) during installation
  • skills/footer.md / SKILL.md — mention hook enforcement in the "What NOT to do" section
  • 10 integration tests (crates/devcontainer-mcp-core/tests/hook_guard_test.rs) validating block/allow/bypass behavior across both agent formats

How it works

  1. Hook fires on every bash/shell tool call
  2. Checks if USER_CONFIRMED_HOST_OPERATION=1 is in the command → allows through (human bypass)
  3. Checks if .devcontainer/devcontainer.json exists in cwd → denies with helpful message
  4. Otherwise → allows through

The bypass string is a semantic tripwire: even if an LLM discovers it by reading the hook script, generating USER_CONFIRMED_HOST_OPERATION=1 means falsely asserting that a user confirmed the operation — directly conflicting with honesty training.

PreToolUse hooks that block bash/shell tool calls when a
.devcontainer/devcontainer.json exists, forcing agents to use
devcontainer-mcp MCP tools instead of executing on the host.

- hooks/devcontainer-guard.sh: shared hook script supporting both
  Claude Code and Copilot CLI payload formats
- .github/hooks/devcontainer-guard.json: Copilot CLI hook config
  for this repo
- install.sh/install.ps1: auto-install hooks and configure agent
  environments during installation
- 10 integration tests validating block/allow/bypass behavior
- SKILL.md footer updated to mention hook enforcement

Bypass: USER_CONFIRMED_HOST_OPERATION=1 in the command allows
through, designed as a semantic tripwire that LLMs cannot
honestly generate.
@aniongithub aniongithub merged commit 4e20f27 into main May 11, 2026
1 check passed
@aniongithub aniongithub deleted the feature/host-protection-hooks branch May 11, 2026 07:31
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.

1 participant