Claude Code: restrict Haiku subagents to code exploration only
In Claude Code, Haiku subagents can be forced to read, search, and report on the codebase without making changes, leaving edits to the main agent.
In a Claude Code setup where Sonnet is the main model, Opus acts as an advisor, and Haiku runs subagents, it is recommended to use Haiku subagents exclusively for exploring the codebase.
You can force subagents into a read-only exploration mode while leaving all code changes to the main agent.
To do this, install two hooks:
- Subagents Explore Only — uses
SubagentStartto allow subagents only to read files, perform searches, and report results without modifying files. - Subagent Read Only Guard — uses
PreToolUseto block file writes and forbidden commands. If a subagent tries to change files, the hook blocks the action.
Install them with one command:
npx claude-code-templates --setting hooks/subagents-explore-only --hook security/subagent-read-only-guard
The main agent keeps its normal access rights, while subagents focus solely on exploring the codebase.
Why it matters
AnalysisThis reduces the risk of unintended code changes during automated exploration. It also enforces a clearer separation between research and write operations.
Discuss in community
Share your questions and insights with developers
Related in Ecosystem
Practical guides, core terminology, and agent skills
Claude Code Projects: How a Single AI Orchestrates a Team of Autonomous Agents
A deep dive into Claude Code Projects: Coordinator and Threads architecture, parallel branches, shared memory via MEMORY.md, and cloud agent management.
Claude Code
The official terminal agent from Anthropic, operating directly in the command line via Claude 3.7 Sonnet with native support for Bash, Git, file systems, and the MCP protocol.
Claude Code adds automatic fixes for excessive token usage in /usage menu
Starting with Claude Code 2.1.305, users can automatically apply fixes that reduce excessive token usage and inspect Prompt cache hit/miss statistics.
Subagents and Parallel Execution in Claude Code: Running Multiple Tasks Simultaneously
A comprehensive guide to task parallelization in Claude Code: subagent architecture, shared vs. isolated context, Fan-Out and Swarm patterns, headless CLI orchestration with -p, and token economics.