Repository navigation
Description
Summary
When an agent is placed in read-only mode, it can still write arbitrary files using the native Claude Code Write and Edit tools. Read-only mode is enforced via hooks that intercept Bash commands, but Write, Edit, and NotebookEdit are separate tool calls that don't go through Bash — so they bypass the restriction entirely. An agent explicitly configured as read-only can freely create and modify files in its workspace.
Component
Agent Runtime / Read-Only Mode / Hooks
Priority
P1
Observed Behavior
An agent with read-only mode enabled received a user request to save a memory. The agent called the Write tool directly and successfully created files at /home/developer/.claude/projects/-home-developer/memory/. No permission denial was recorded (permission_denials: []).
The execution init event shows the full Write, Edit, and NotebookEdit tools present in the tool list, with no hook blocking them.
Root Cause
Read-only mode is implemented via hooks that scan/deny Bash tool calls. These hooks fire on PreToolUse (or equivalent) for Bash only. The native file tools — Write, Edit, NotebookEdit — execute directly against the filesystem without going through a shell, so they are never intercepted by the bash-scanner hooks.
Additionally, agents run with permissionMode: bypassPermissions, which disables the permission prompt system entirely. Even if write tools would normally prompt for approval, they proceed without pause.
Reproduction Steps
- Create an agent and enable read-only mode via the UI or API (
PUT /api/agents/{name}/read-only) - Send the agent a task that asks it to write or edit a file (e.g. "save a note about me")
- Observe the execution transcript — the agent calls
Writeand the file is created successfully - Check
permission_denialsin the execution result — it will be empty
Suggested Fix
Add PreToolUse hooks for Write, Edit, and NotebookEdit (and any other file-mutating tools) in the read-only mode hook injection logic, mirroring the existing Bash hook. When read-only mode is enabled, these hooks should deny the tool call and return an error to the agent explaining the restriction.
Alternatively, the hook could be a single wildcard PreToolUse hook that checks the tool name against a denylist of write-capable tools: Write, Edit, NotebookEdit, plus any Bash command that modifies files.
# Conceptual read-only PreToolUse hook logic
WRITE_TOOLS = {"Write", "Edit", "NotebookEdit"}
def pre_tool_use(tool_name, tool_input):
if read_only_mode_enabled and tool_name in WRITE_TOOLS:
return {"deny": True, "reason": "Agent is in read-only mode — file writes are disabled."}
if read_only_mode_enabled and tool_name == "Bash":
# existing bash scanner logic
...Impact
Any agent in read-only mode can silently write to its workspace, undermining the security guarantee of the feature. This is particularly problematic for public-facing agents where the operator expects read-only to be a hard boundary.
Related
- Read-only mode feature:
PUT /api/agents/{name}/read-only - GUARD-001: baseline hooks injected at container build (bash/file/output scanners)
- INJECT-136: platform instructions injected via
--append-system-prompt
Activity
vybe commentedon May 18, 2026
/claim
github-actions commentedon May 18, 2026
Claimed by @vybe. Label
status-in-progressadded.Next steps:
feature/887-<short-slug>Fixes #887docs(flows): sync feature-flows.md and test catalog for #887
fix(read-only): bake guard into base image, cover MultiEdit, fail-clo…
Merge remote-tracking branch 'origin/dev' into AndriiPasternak31/issu…
vybe commentedon Jun 1, 2026
Shipped in v0.6.0 (released via #998).
Release: v0.7.0 (#1319)
fix(security): move guardrail hook registration out of the agent's wr…
fix(security): move guardrail hook registration out of the agent's wr…