Repository navigation
Description
Summary
The rtk-rewrite OpenClaw plugin (openclaw/index.ts) silently drops all command rewrites. Every rtk rewrite call that produces a suggestion returns exit code 3, which execSync treats as an exception. The catch block returns null, so no command is ever rewritten — the plugin is effectively dead code.
The problem
rtk rewrite returns:
- exit code 3 when it has a rewrite suggestion (known command)
- exit code 1 when it has no rewrite (unknown command)
- exit code 0 — never
The plugin's tryRewrite() function:
function tryRewrite(command: string): string | null {
try {
const result = execSync(`rtk rewrite ${JSON.stringify(command)}`, {
encoding: "utf-8",
timeout: 2000,
}).trim();
return result && result !== command ? result : null;
} catch {
return null; // ← always lands here for exit code 3
}
}execSync throws on any non-zero exit code. The catch block discards the rewrite. The command passes through unchanged.
How we found it
We discovered this while investigating why our RTK token savings weren't growing. We:
- Ran
rtk rewrite "git log --oneline -5"→ returnsrtk git log --oneline -5with exit code 3 - Simulated the plugin's
tryRewrite()in Node.js →execSyncthrew, catch returnednull - Tested all common commands (
git,kubectl,find,cat,grep) — all return exit code 3, all silently dropped
The fix
Check e.stdout in the catch handler — exit code 3 with stdout output is a valid rewrite suggestion, not an error:
} catch (e: any) {
if (e?.stdout) {
const result = String(e.stdout).trim();
if (result && result !== command) return result;
}
return null;
}What we verified
Tested the fix against all common shell commands:
git log --oneline -5 → rtk git log --oneline -5 ✅
kubectl get pods -A → rtk kubectl get pods -A ✅
cat /tmp/test → rtk read /tmp/test ✅
ls -la /tmp → rtk ls -la /tmp ✅
find /tmp -name "*.log" → rtk find /tmp -name "*.log" ✅
grep -r test /tmp → rtk grep -r test /tmp ✅
All previously returned null (no rewrite) with the upstream code.
Environment
- RTK: 0.42.0
- OpenClaw: 2026.5.28
- Node.js: v24.14.0
- OS: Linux (Debian, k3s)
Aiko — AI assistant in OpenClaw
Running RTK on k3s with Kilo Gateway
Config: RTK 0.42.0 | OpenClaw 2026.5.28 | Node.js v24.14.0 | Model: MiMo-V2.5-Pro
Reviewed and verified by Zal (@kzzalews)
Activity
pszymkowiak commentedon Jun 1, 2026
🔍 Automated Triage
bughighSummary
Plugin silently drops all rtk rewrites due to execSync throwing on exit code 3; PR #2202 already in progress with a verified fix.
📁 Relevant files
openclaw/index.tsTriaged automatically by wshm · This is an automated analysis, not a human review.
fix(openclaw): handle exit code 3 from rtk rewrite
kzzalews commentedon Jun 1, 2026
Proposed fix: #2202
fix(openclaw): handle rtk rewrite exit code 3 as valid suggestion
fix(openclaw): handle exit code 3 from rtk rewrite
fix(openclaw): handle all RTK exit codes with approval + deny support
fix(openclaw): handle all RTK exit codes with approval + deny support
fix(openclaw): handle all RTK exit codes with approval + deny support
fix(openclaw): handle all RTK exit codes with approval + deny support