In a Claude Code subagent definition, how do the `tools` and `disallowedTools` fields differ, and how would you scope a read-only security reviewer?
answer
- allowlist versus denylist
- omitted means inherit
- which one applies first
- a specifier removes the whole tool
- Bash can still write files
basics
~20 stools is an allowlist and disallowedTools a denylist applied first; omit both and the subagent inherits every subagent tool. A read-only reviewer lists Read, Grep and Glob, because keeping Bash still lets it change files.
solid answer
~50 s`tools` is an allowlist: the subagent gets only what it names, and no MCP tools unless you list them, for example `mcp__github`. Omit it and the subagent inherits every built-in and MCP tool available to subagents. `disallowedTools` is a denylist removed from that pool. If both are set, `disallowedTools` applies first and `tools` resolves against what remains, so a tool in both is gone. A specifier in `disallowedTools`, such as `Bash(git push *)`, removes all of Bash; to block one command, put a deny rule in `permissions.deny`, which also applies inside subagents. For a read-only security reviewer, `tools: Read, Grep, Glob` is the honest scope: dropping Edit and Write is not enough while Bash remains, since a shell command can rewrite files. If it needs `git diff`, keep Bash and add deny rules or a `PreToolUse` hook.
code
yaml · 6 lines---
name: security-reviewer
description: Reviews changed code for injection, authorization and secret-handling flaws. Use after edits to auth or input handling.
# Allowlist: nothing else exists for this subagent (no Bash, no MCP tools, no Agent)
tools: Read, Grep, Glob
---go deeper
Remember tools is an allowlist, disallowedTools a denylist, and that leaving both out means the subagent inherits every tool available to subagents.
Explain the resolution order, the MCP server patterns, and why a specifier in disallowedTools drops the whole tool instead of one command.
Scope a reviewer so it truly cannot write: drop Bash or fence it with deny rules or a hook, and spot fields such as memory that add write tools back.
Decide which layer holds each constraint across a team's agents: frontmatter for tool sets, managed deny rules for commands nobody may run, prompts only for style.
## Two fields, two directions Every Claude Code subagent starts from a **tool pool**: the built-in and MCP tools of the main conversation, minus a short list Claude Code removes from subagents (such as `AskUserQuestion` and `EnterPlanMode`). Two frontmatter fields shape that pool. - **`tools`** is an **allowlist**. The subagent gets exactly the tools it names. Accepts a comma-separated string (`Read, Grep, Glob`) or a YAML list. - **`disallowedTools`** is a **denylist**. It removes the named tools from whatever the subagent would otherwise have. - **Neither set**: the subagent **inherits every tool available to subagents**, including every MCP tool in the session. Omitting `tools` is not "no tools"; it is "all of them". ## How they combine When both fields are present, Claude Code resolves them in a fixed order: 1. Apply `disallowedTools` to the pool. 2. Resolve `tools` against what is left. 3. A tool named in both is therefore **removed**; the allowlist does not win. If every entry in `tools` fails to resolve (a typo such as `Grpe`, or a tool not available to subagents), Claude Code usually **refuses to launch** the subagent and the Agent tool returns an error naming the unresolved entries, rather than starting an agent with nothing to work with. | You write | The subagent gets | |---|---| | no `tools`, no `disallowedTools` | every tool available to subagents | | `tools: Read, Grep, Glob` | those three only; no Bash, no MCP tools | | `disallowedTools: Write, Edit` | everything else, including Bash and MCP tools | | `tools: Read, Edit, Bash` + `disallowedTools: Edit` | Read and Bash | | `disallowedTools: mcp__github` | everything except the `github` server's tools | ## MCP patterns and the specifier trap Both fields accept **server-level MCP patterns**: `mcp__<server>` or `mcp__<server>__*` grants or removes every tool from that server, and in `disallowedTools` the pattern `mcp__*` removes every MCP tool from any server. The common mistake is treating `disallowedTools` like a permission rule. An entry with a **specifier**, such as `Bash(git push *)`, does **not** block only pushes: it removes the **whole Bash tool** from the subagent. When you want Bash minus a few commands, leave Bash in the pool and add a deny rule such as `Bash(git push *)` to `permissions.deny` in a settings file. That rule applies to the main conversation and to every subagent. The rule grammar itself belongs to the permission-rules material; the point here is which layer can express "this command, not that one". ## Scoping a read-only security reviewer The reviewer's job is to read code and report. It needs to search and read; it must not change the tree. - **Minimal and enforceable**: `tools: Read, Grep, Glob`. No Edit, no Write, no Bash, no MCP tools, and no `Agent`, so it cannot spawn helpers of its own. - **Why not "everything except Edit and Write"**: `disallowedTools: Write, Edit` keeps Bash, and a shell can rewrite a file with a redirect or an in-place edit. Removing the file-editing tools is not the same as making the agent read-only. - **If it must run `git diff` or `git log`**: keep Bash in `tools`, then constrain it with deny rules for writing commands, or with a `PreToolUse` hook in the subagent's own frontmatter that rejects anything outside an allowed set. The prompt saying "never modify files" is guidance; the tool list and the deny rules are what Claude Code enforces. - **Watch other fields that add tools**: enabling `memory` turns on Read, Write and Edit so the subagent can maintain its memory files, which quietly undoes a read-only scope. ```yaml --- name: dependency-auditor description: Lists third-party packages and flags risky versions. Use when manifests change. # Denylist variant: inherits the pool, minus file writes and every MCP tool disallowedTools: Write, Edit, mcp__* --- ``` That denylist variant still has Bash, so it suits an auditor that must run read-only commands under deny rules; it would be the wrong shape for the reviewer. ## Where the subagent runs changes the result A subagent that runs in the **background** (the default in interactive sessions) keeps every MCP tool but only a fixed set of built-ins, so the same definition can resolve to fewer tools there than in the foreground. Design the list for the tools the job needs, and keep it short enough that the background filter does not remove something essential. ## The principle in one line Put the hard limit in the field Claude Code enforces: the **allowlist** for a narrow agent, the **denylist** for a broad one with a few exclusions, and **permission rules** when the limit is narrower than a whole tool.
- How do you let the reviewer run `git diff` but never `git push`?Keep Bash in `tools` and add `Bash(git push *)` to `permissions.deny` in a settings file; deny rules apply inside subagents too. Alternatively give the subagent a `PreToolUse` hook in its frontmatter that rejects non-allowed commands. Do not use `disallowedTools: Bash(git push *)`, which removes Bash entirely.
- What happens if every entry in `tools` is misspelled?Claude Code usually refuses to launch the subagent, and the Agent tool returns an error naming the entries that did not resolve, for example `Grpe`. Fix the spelling or the tool name; a subagent is not started with an empty tool list.
- disallowedTools: Bash(git push *) blocks pushes and keeps the rest of Bash.
- Keeping Bash is still read-only because Edit and Write are not listed.
- Omitting the tools field gives the subagent no tools at all.
- A tool listed in both fields stays available because the allowlist wins.
- A tools allowlist automatically includes the session's MCP tools.