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" → returns rtk git log --oneline -5 with exit code 3
- Simulated the plugin's
tryRewrite() in Node.js → execSync threw, catch returned null
- 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)
Summary
The
rtk-rewriteOpenClaw plugin (openclaw/index.ts) silently drops all command rewrites. Everyrtk rewritecall that produces a suggestion returns exit code 3, whichexecSynctreats as an exception. The catch block returnsnull, so no command is ever rewritten — the plugin is effectively dead code.The problem
rtk rewritereturns:The plugin's
tryRewrite()function:execSyncthrows 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:
rtk rewrite "git log --oneline -5"→ returnsrtk git log --oneline -5with exit code 3tryRewrite()in Node.js →execSyncthrew, catch returnednullgit,kubectl,find,cat,grep) — all return exit code 3, all silently droppedThe fix
Check
e.stdoutin the catch handler — exit code 3 with stdout output is a valid rewrite suggestion, not an error:What we verified
Tested the fix against all common shell commands:
All previously returned
null(no rewrite) with the upstream code.Environment
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)