Skip to content

bug: Read-only mode hooks don't block Write/Edit tools, only Bash #887

Closed

Description

@vybe

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

  1. Create an agent and enable read-only mode via the UI or API (PUT /api/agents/{name}/read-only)
  2. Send the agent a task that asks it to write or edit a file (e.g. "save a note about me")
  3. Observe the execution transcript — the agent calls Write and the file is created successfully
  4. Check permission_denials in 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

  1. vybe commented on May 18, 2026

    @vybe
    ContributorAuthor

    /claim

  2. added
    status-in-progress
    on May 18, 2026
  3. github-actions commented on May 18, 2026

    @github-actions

    Claimed by @vybe. Label status-in-progress added.

    Next steps:

    1. Create branch: feature/887-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #887
  4. added
    status-in-dev
    and removed
    status-in-progress
    on May 18, 2026
  5. vybe commented on Jun 1, 2026

    @vybe
    ContributorAuthor

    Shipped in v0.6.0 (released via #998).

  6. removed
    status-in-dev
    on Jun 1, 2026
  7. added a commit that references this issue on Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority-p1type-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions