openclaw - 💡(How to fix) Fix [Bug]: exec tool silently corrupts 2>&1 / 2>/dev/null shell redirect arguments

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

When using the OpenClaw exec tool, arguments containing 2>&1 or 2>/dev/null (shell redirect syntax where 2 and > are separated by whitespace) get their whitespace silently stripped during OpenClaw's argument tokenization, causing them to be passed as a single merged token to the underlying shell/process. This corrupts commands in ways that are hard to diagnose.

Error Message

This bug was discovered while investigating a separate webchat UI issue (GitHub issues #87875, #87649, #87387). While running gh search issues --state open2>&1 to search for related OpenClaw bugs, the command failed with the error shown above.

Root Cause

Actual behavior

Whitespace between 2 and > in redirect syntax is silently dropped, causing:

  1. open2>&1 is treated as a single malformed argument instead of open + 2>&1
  2. --json title,state2>&1 is parsed as JSON field state2 instead of state + 2>&1
  3. Any command using command 2>&1 gets "command": command not found because 2>&1 is passed as the first argument to the command

Fix Action

Fix / Workaround

Impact assessment

  • Severity: Medium — blocks stderr redirection for any CLI tool invoked through exec
  • Workaround: Use --json without 2>&1, or use curl with GitHub REST API instead of gh CLI
  • Affected commands: Any tool invoked via exec that uses 2>&1 / 2>/dev/null / 1>&2 redirect syntax

The workaround is to either:

  1. Omit 2>&1 from the command (works for gh since it outputs to stdout by default)
  2. Use curl with the GitHub REST API + python3 parsing instead of gh CLI

Code Example

# Command intended (with stderr redirected):
gh search issues --state open --repo openclaw/openclaw -L5

# Command actually executed (tokenization bug):
gh search issues --state open2>&1 --repo openclaw/openclaw -L5
# Result: "invalid argument 'open2' for '--state' flag"

---

# Intended:
gh search issues "test" --repo openclaw/openclaw -L5 --json title,state

# Actually executed (gh receives field name "state2"):
gh search issues "test" --repo openclaw/openclaw -L5 --json title,state2>&1
# Result: "Unknown JSON field: 'state2'"

---

# Intended: check if a process is running and capture both stdout and stderr
ps aux 2>&1 | grep someprocess

# Actually executed:
ps aux 2>&1 | grep someprocess
# Result: "ps: 2>&1: command not found" — the entire string "2>&1" is treated as one arg
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug

Impact

Blocks the use of 2>&1 / 2>/dev/null shell redirects with the exec tool, and corrupts --json field lists containing 2>&1 patterns. This affects any workflow that inspects gh command results (and likely other CLI tools) through the OpenClaw exec tool.

Summary

When using the OpenClaw exec tool, arguments containing 2>&1 or 2>/dev/null (shell redirect syntax where 2 and > are separated by whitespace) get their whitespace silently stripped during OpenClaw's argument tokenization, causing them to be passed as a single merged token to the underlying shell/process. This corrupts commands in ways that are hard to diagnose.

Environment

  • OpenClaw version: 2026.5.27 (installed via Homebrew, node_modules path /opt/homebrew/lib/node_modules/openclaw)
  • OS: macOS Darwin 25.5.0 (arm64)
  • Node.js: v26.0.0
  • Shell: zsh (login shell)

Steps to reproduce

Reproduction 1 — gh search issues --state open2>&1:

# Command intended (with stderr redirected):
gh search issues --state open --repo openclaw/openclaw -L5

# Command actually executed (tokenization bug):
gh search issues --state open2>&1 --repo openclaw/openclaw -L5
# Result: "invalid argument 'open2' for '--state' flag"

Reproduction 2 — --json title,state2>&1:

# Intended:
gh search issues "test" --repo openclaw/openclaw -L5 --json title,state

# Actually executed (gh receives field name "state2"):
gh search issues "test" --repo openclaw/openclaw -L5 --json title,state2>&1
# Result: "Unknown JSON field: 'state2'"

Reproduction 3 — Any 2>&1 in command body:

# Intended: check if a process is running and capture both stdout and stderr
ps aux 2>&1 | grep someprocess

# Actually executed:
ps aux 2>&1 | grep someprocess
# Result: "ps: 2>&1: command not found" — the entire string "2>&1" is treated as one arg

Expected behavior

  • Arguments passed to the exec tool should be passed to the underlying shell/process exactly as provided, preserving whitespace in redirect syntax.
  • Commands using 2>&1 / 2>/dev/null redirects should work normally.

Actual behavior

Whitespace between 2 and > in redirect syntax is silently dropped, causing:

  1. open2>&1 is treated as a single malformed argument instead of open + 2>&1
  2. --json title,state2>&1 is parsed as JSON field state2 instead of state + 2>&1
  3. Any command using command 2>&1 gets "command": command not found because 2>&1 is passed as the first argument to the command

Root cause hypothesis

OpenClaw's exec tool argument tokenization splits on whitespace but appears to treat 2>&1 as a special sequence, or concatenates tokens in a way that strips whitespace between 2 and >. The tokenization logic seems to merge what should be two adjacent tokens (2 and >&1 / 2>&1) into a single token.

The bug does not appear when --state open is used without any following redirect — meaning the bug is triggered specifically when 2 and >&1 are separated by whitespace.

Impact assessment

  • Severity: Medium — blocks stderr redirection for any CLI tool invoked through exec
  • Workaround: Use --json without 2>&1, or use curl with GitHub REST API instead of gh CLI
  • Affected commands: Any tool invoked via exec that uses 2>&1 / 2>/dev/null / 1>&2 redirect syntax

Additional context

This bug was discovered while investigating a separate webchat UI issue (GitHub issues #87875, #87649, #87387). While running gh search issues --state open2>&1 to search for related OpenClaw bugs, the command failed with the error shown above.

The workaround is to either:

  1. Omit 2>&1 from the command (works for gh since it outputs to stdout by default)
  2. Use curl with the GitHub REST API + python3 parsing instead of gh CLI

Related issues about the exec tool:

  • #48780: "[Bug]: [Windows] exec() and read() commands corrupted with </arg_value>> suffix" — similar class of argument corruption
  • #53408: "[Bug]: Write/exec tool parameters silently dropped after long conversations"
  • #70033: "Tool calls emit empty arguments {} when content parameter is large (write/exec)"

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

  • Arguments passed to the exec tool should be passed to the underlying shell/process exactly as provided, preserving whitespace in redirect syntax.
  • Commands using 2>&1 / 2>/dev/null redirects should work normally.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix [Bug]: exec tool silently corrupts 2>&1 / 2>/dev/null shell redirect arguments