Skip to content

Support denyMainOnly permission scope: restrict tools to subagents only #30161

Closed as not planned

Description

@amaurel

Problem

When a tool is denied (via deniedTools in settings or hook deny decision), the restriction applies equally to the main conversation and all subagents. There is no way to deny a tool to the main conversation while allowing subagents to use it.

Use Case

I want to restrict write-access MCP tools (e.g., patch_object, delete_object) so the main conversation LLM cannot call them directly, but specialized subagents — which have focused prompts and limited tool sets — can. This provides a safety layer: the main conversation must delegate writes to purpose-built agents rather than calling write tools directly.

Example settings (desired behavior):

{
  "permissions": {
    "denyMainOnly": ["mcp__server__patch_object", "mcp__server__delete_object"]
  }
}

Current Behavior

  • deniedTools / deny blocks the tool for both main and subagents
  • PreToolUse hooks cannot distinguish main from subagent — all fields (session_id, transcript_path, permission_mode, env vars) are identical
  • No workaround exists short of process tree inspection (fragile)

Proposed Solution

Add a permission scope that denies tools to the main conversation but allows subagents to use them. Possible approaches:

  1. New permission list: denyMainOnly — denied for main conversation, allowed for subagents
  2. Subagent override: allowForSubagents list that overrides deny when called from a subagent
  3. Hook context field: Add is_subagent / caller / agent_depth to PreToolUse hook input so hooks can make the decision themselves

Option 1 or 2 would be the cleanest — no hook scripting needed.

Why This Matters

Subagents are the natural delegation mechanism in Claude Code. Being able to restrict the main conversation to read-only while letting specialized agents write is a practical safety pattern, especially for MCP tools that modify external systems.

Activity

  1. github-actions commented on Mar 2, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. Allow MCP tools to be available only to subagent #6915
    2. [FEATURE] Expose Agent Context in Hook Event Payloads for Multi-Agent Observability #16424
    3. Feature: Per-agent MCP tool filtering to improve agent focus and accuracy #4380

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. Nxt3 commented on Mar 5, 2026

    @Nxt3
  3. github-actions commented on Apr 3, 2026

    @github-actions

    Closing for now — inactive for too long. Please open a new issue if this is still relevant.

  4. github-actions commented on Apr 10, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  5. locked as resolved and limited conversation to collaborators on Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions