auto 模式(以及 bypass 模式)插给模型的那段提醒里,有一句让模型在 Bash 里用 grep 和 find 搜索。这个 mod 只拿掉这一句,换成用 Grep 工具搜内容、用 Glob 工具找文件名;提醒的其余部分原样保留。认不出这句时整段原样放行。子 agent 收不到这段提醒,所以每个子 agent…

In auto mode (and bypass mode), Claude Code adds a reminder for the model. It tells the model to do much of its work in the Bash tool, including "search with grep and find". This mod changes only that clause: it removes the clause and adds one sentence at the end of the reminder, so the model searches file contents with the Grep tool and file names with the Glob tool, and does not chain a grep after another command either. The rest of the reminder (reading files with cat/head, editing files with sed, and so on) is left exactly as the engine wrote it.
prompt.attachment, matched on { type: 'auto_mode' }. It does not touch the system prompt, the auto-mode classifier, or any other reminder.agent.spawn the mod adds the same sentence to the end of each subagent's task (Agent tool calls and workflow agents). It skips forks, which already carry the main loop's reminder, resumed agents, whose task cannot be rewritten, and teammates.--allowedTools=Glob or --tools. Naming either one in --allowedTools brings both back.claude --plugin-dir ./prefer-search-tools # load for this session
command claude plugin test ./prefer-search-tools
Tested with Claude Code 2.1.296; the agent.spawn part with 2.1.309. In an interactive auto-mode session, the debug log shows prompt.attachment auto_mode: … rewrote it (479 -> 568 characters). In -p mode the engine does not send this reminder at all.
hooks/prefer-search-tools.ts 34 lines1// The auto-mode reminder (type `auto_mode`, also sent in bypass mode) steers the model to Bash for reading, searching
2// and editing. Only its search clause is taken out and replaced by a sentence naming the Grep and Glob tools; the rest
3// of the reminder stays as the engine wrote it. A reminder without the clause (another build) goes on unchanged.
4//
5// Subagents get no auto-mode reminder (seen on 2.1.309), so the same sentence goes at the end of the task each one
6// starts with. A fork already carries the main loop's rewritten reminder, a resume cannot be rewritten (the types say
7// it can only be refused), and a teammate is left as its lead asked.
8
9import type { On } from 'claude-code'
10
11/** The clause as 2.1.296 writes it, in both its strict and relaxed variants. */
12export const SEARCH_CLAUSE = 'search with grep and find, '
13
14export const SEARCH_STEER = 'For searches, use the Grep tool for file contents and the Glob tool for file names, not grep or find through Bash, '
15 + 'and not chained after another command with ; or && either. Piping another command\'s output into grep is fine.'
16
17/** The reminder with its search clause replaced, or undefined when it has none. */
18export function steered(text: string): string | undefined {
19 if (!text.includes(SEARCH_CLAUSE)) return undefined
20 return `${text.replace(SEARCH_CLAUSE, '')}\n\n${SEARCH_STEER}`
21}
22
23export function register(on: On): void {
24 on('prompt.attachment', { type: 'auto_mode' }, async ($, e, next) => {
25 const text = steered(e.text)
26 return next(text === undefined ? e : { ...e, text })
27 })
28
29 on('agent.spawn', async ($, e, next) => {
30 if (e.fork || e.resume !== undefined || e.isTeammate || e.prompt.includes(SEARCH_STEER)) return next(e)
31 return next({ ...e, prompt: `${e.prompt}\n\n${SEARCH_STEER}` })
32 })
33}
34