You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Claude Code's grep and find wrappers need [[ ]], exec -a, typeset, and command in a pipeline #323
Claude Code 2.1.316 and later writes shell functions for grep, find, and rg into the shell it runs commands in. The functions run Claude Code's own binary under another name. Strands Shell cannot run them, because it does not support four forms that the functions use. Bash runs each form.
The last row is command in a stage of a pipeline. command NAME as a whole pipeline also ran the shell function NAME, so a wrapper such as grep() { command grep "$@"; } called itself until the stack overflowed. A fix for that part, with a differential case and command-check tests, is ready; it will link here.
What the functions look like
From the snapshot that Claude Code 2.1.328 writes (paths shortened):
functiongrep {
local _cc_a
for_cc_ain${1+"$@"};docase"$_cc_a"in -*-filter*|-*-config*|---*|-[Zz]*|--null) command grep ${1+"$@"};return ;; esacdoneif [[ -x /path/to/claude ]];thenif [[ -n${ZSH_VERSION:-} ]];then
ARGV0=ugrep /path/to/claude -G --ignore-files --hidden -I ${1+"$@"}else
(exec -a ugrep /path/to/claude -G --ignore-files --hidden -I ${1+"$@"})
fielsecommand grep ${1+"$@"};fi
}
if!hash rg 2>/dev/null &&!typeset -f rg >/dev/null 2>&1;thenfunctionrg { ... same shape, with exec -a rg ... }
fi
Also
A shell function costs a lot of stack in each call. With the default max_depth of 64, the differential suite's test thread (2 MiB stack, debug build) overflowed and aborted before the depth limit refused the recursion. An embedder that runs the shell on a thread with the default stack cannot rely on max_depth to stop deep recursion. #318 reduces the stack that each level uses.
Expected
[[ … ]] with the common tests (-n, -z, -x, -f, -d, ==, !=, &&, ||, !).
exec -a NAME program args, or a clear refusal of -a.
#324 (command NAME skips the function NAME) and #325 ([[ ]]) together make Claude Code's grep and find wrappers work. I measured this in an embedder that runs the shell under a policy, with Claude Code 2.1.316 and 2.1.328: echo hi | grep -c hi prints 1, grep -rn and find -name find the file, and nothing recurses. When the embedder refuses access to the agent's own binary, the wrappers fall back to command grep and command find.
Neither PR covers exec -a, typeset, or command in a later pipeline stage. Those wrappers need them only on paths that run the agent's own binary, so I leave them open here.
Also seen: find . -type f -exec grep -l needle {} \; and ... -exec grep -l needle {} + print nothing where bash lists the file.
Activity
abhisheksp commentedon Nov 19, 2026
#324 (
command NAMEskips the function NAME) and #325 ([[ ]]) together make Claude Code'sgrepandfindwrappers work. I measured this in an embedder that runs the shell under a policy, with Claude Code 2.1.316 and 2.1.328:echo hi | grep -c hiprints1,grep -rnandfind -namefind the file, and nothing recurses. When the embedder refuses access to the agent's own binary, the wrappers fall back tocommand grepandcommand find.Neither PR covers
exec -a,typeset, orcommandin a later pipeline stage. Those wrappers need them only on paths that run the agent's own binary, so I leave them open here.Also seen:
find . -type f -exec grep -l needle {} \;and... -exec grep -l needle {} +print nothing where bash lists the file.