[FEATURE] Allow perl/sed for bulk regex find-and-replace across files

Resolved 💬 4 comments Opened Jan 16, 2026 by PaulRBerg Closed Feb 28, 2026

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 the find, grep, cat, head, tail, sed, awk, or echo commands... 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:

  1. The same pattern replacement needs to be applied across multiple files
  2. The replacement is regex-based or mechanical (not requiring semantic understanding)
  3. 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 perl or sed with 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

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗