Skip to content

fix(exec): run command NAME without the shell function NAME - #324

Merged
gautamsirdeshmukh merged 1 commit into
strands-agents:mainfrom
abhisheksp:feature/exec/command-skips-functions
Nov 19, 2026
Merged

gautamsirdeshmukh merged 1 commit into
strands-agents:mainfrom
abhisheksp:feature/exec/command-skips-functions

Conversation

@abhisheksp

Copy link
Copy Markdown
Contributor

Description

Context. command NAME args runs NAME as a builtin, a registered command, or a program, and never as a shell function. Wrappers depend on that: grep() { command grep "$@"; } adds behavior and then calls the real grep. Claude Code 2.1.328 writes such wrappers for grep and find into the shell it runs commands in.

Before. The command builtin ran NAME through the normal pipeline, which looks up shell functions first. So the wrapper called itself until the stack overflowed. In this repository's differential suite, the new case aborts the test process with a stack overflow, before max_depth refuses the recursion. An embedder that checks each command sees each level as a new request.

After. The command builtin marks the pipeline that it runs to skip a function of that name. The mark applies to the function dispatch, the executable lookup, and the command-fallback check, so command NAME resolves NAME and checks it the same way as when no function exists. run_pipeline takes the mark first, so it cannot reach a later pipeline or a command substitution inside the arguments.

Verification.

  • New differential case command_skips_function, recorded from bash: a function that wraps grep with command grep, command cat past a cat function, and command f for a name that only a function has (exit 127, as in bash), then f again, which runs the function.
  • New command-check tests: past a function, command tool asks the command fallback once and runs it, and a refused fallback runs nothing (exit 126). Both fail without the change. Without the change, the suite aborts with a stack overflow. With it, the suite passes.
  • cargo test: every suite passes. cargo fmt --check passes. cargo clippy --all-targets shows 15 warnings, the same count as on main.

command in a later stage of a pipeline (echo hi | command grep hi) still prints command: command not found. #323 tracks it, with the other forms that Claude Code's wrappers use.

Related Issues

Part of #323.

Documentation PR

None. command now behaves as POSIX specifies.

Type of Change

Bug fix

Testing

  • I ran the relevant test suites for the bindings I touched (cargo test; no binding changed)
  • If I touched Rust, I ran cargo fmt and cargo clippy

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

`command NAME args` ran a shell function named NAME, as a plain call
does. A wrapper such as `grep() { command grep "$@"; }` then called
itself until the process stack overflowed. Bash runs the builtin or the
program instead.

The `command` builtin now marks the next pipeline to skip a function
of that name, in the run, the executable lookup, and the fallback check.
The differential case command_skips_function pins it against bash; the
suite aborts with a stack overflow without the change.
@ferdingler

Copy link
Copy Markdown
Collaborator

@strandly-the-agent review this pr

@strandly-the-agent strandly-the-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. command NAME now skips the shell function NAME and matched bash on every command probe I ran; I found no regression against base. One non-blocking test gap is inline: nothing covers the gate that lets command foo reach a PATH executable past a function foo.

@ferdingler, this is ready for your look.

What I verified

Head 8b9c75e against merge-base 4b0bdbc, aarch64 Linux, debug builds in separate target directories, bash 5.2.15 as the reference.

  • Suite at head: cargo test --workspace --all-targets gives 2664 passed, 0 failed, exit 0. cargo fmt --check is clean.
  • New tests fail on base: with head's test files on base, command_check gives 29 passed and 2 failed (the two new tests), and differential aborts with a stack overflow.
  • .expected matches bash: re-recorded command_skips_function under the README's environment; identical.
  • Mark lifecycle (source): between the set at src/exec.rs:3222 and the take at :3410 there is no await, early return or other caller. execute_pipeline_capture and the compound callers never see it set. All three Process constructors start it false, and Process has no Clone.
  • Gate coverage (mutation): removing the gate at :3321, :3731 or :3876 fails a new test. Removing the one at :3509 does not (inline).
  • 77 scripts under bash, base and head: wrappers, including the Claude Code function grep from #323, in pipeline stages, $(…), loops, an EXIT trap, eval and a background job; command "$name", aliases, env prefixes, heredocs, failed redirects; a function shadowing sh, lash, registered commands and PATH scripts; no leak into a later pipeline or a substitution in the arguments. Head matched bash on all command behaviour in scope.
  • 51 kernel-hook cases, each with and without the shadowing function: identical events and output at head, and every check_command got exactly one finished or dropped. Covered: check_command and check_fallback refusals, deadline, cancellation, output limit, failed redirect.
  • Not run: Python, Node and wasm bindings, release builds, other platforms.
Question (non-blocking)

Would a skip_function argument on execute_pipeline and run_pipeline be simpler than a field on Process? The other transient flags there (pending_exit, refused_array, deadline_stop) carry a result out of a pipeline; this is the first that carries an input into the next one. command in a later stage (#323) will need a per-stage marker in any case, so the field may not outlive that change. It is sound as written.

Appendix: pre-existing, same on base and head (3)
  • command "" returns 0 where bash returns 127, and "$UNSET" is dropped the same way, so [ -n "$UNSET" ] is true. #299 covers the dropped empty word.
  • command command NAME and command eval … print command not found (127). #323 lists command -p, command -- and the pipeline-stage form, but not these.
  • xargs NAME runs the shell function NAME; bash's xargs cannot see functions.

Comment thread src/exec.rs Resolved
@ferdingler
ferdingler requested review from strandly-the-agent and removed request for ferdingler November 19, 2026 15:59
@gautamsirdeshmukh
gautamsirdeshmukh merged commit 55d7816 into strands-agents:main Nov 19, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants