[FEATURE] Allow perl/sed for bulk regex find-and-replace across files
Problem
When performing identical or pattern-based find-and-replace operations across many files, Claude Code currently uses the Edit tool repeatedly for each file. This is token-inefficient—a task that could be accomplished with a single perl -i -pe or sed -i command instead requires N separate Edit tool calls, each consuming tokens for file content and tool overhead.
The system prompt currently instructs Claude to avoid sed and awk:
"Avoid using Bash with thefind,grep,cat,head,tail,sed,awk, orechocommands... Instead, always prefer using the dedicated tools"
This makes sense for general editing where the Edit tool provides better safety and visibility, but for bulk regex operations it's counterproductive.
Proposed solution
Allow Claude to use shell-based tools (perl -i -pe, sed -i, or similar) when:
- The same pattern replacement needs to be applied across multiple files
- The replacement is regex-based or mechanical (not requiring semantic understanding)
- The user explicitly requests bulk/batch operations
This could be implemented as:
- A heuristic in the system prompt allowing shell tools for bulk operations
- A dedicated "BulkEdit" tool that wraps
perlorsedwith appropriate safety checks - Guidance in CLAUDE.md/AGENTS.md that users can add to enable this behavior
Alternatives considered
- Current approach: Use Edit tool N times for N files—works but wastes tokens
- User workaround: Users can instruct Claude via CLAUDE.md to use sed/perl, but this fights against the system prompt
Prior art
OpenAI's Codex CLI performs well with perl and sed for these bulk operations, achieving significant token efficiency for large-scale mechanical replacements.
Priority
Medium
Category
File operations
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗