Shell commands cost 60-90% fewer tokens — just install one file, restart MiMoCode.
Your AI agent runs git status → 200 lines of output → $0.002 per call. This hook rewrites it to rtk git status → 5 lines → $0.0001. Same information, 97% cheaper. Works automatically — no rtk prefix needed.
MiMoCode has a file hooks system that loads TypeScript/JavaScript files from ~/.config/mimocode/hooks/. This hook uses the tool.execute.before hook to intercept shell commands and rewrite them through RTK before execution.
Agent calls: ls /tmp
↓ hook intercepts
Rewritten: rtk ls /tmp
↓ shell executes
Output: compact tree format (60-90% smaller)
- RTK >= 0.43.0 installed and in PATH
- MiMoCode >= 0.38.0
# Install RTK
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/refs/heads/master/install.sh | sh
# Verify
rtk --version# Clone the repo
git clone https://github.com/Cipher208/mimocode-rtk-hook.git /tmp/mimocode-rtk-hook
# Copy the hook file
mkdir -p ~/.config/mimocode/hooks
cp /tmp/mimocode-rtk-hook/hooks/rtk.ts ~/.config/mimocode/hooks/
# Restart MiMoCodeOr one-liner:
mkdir -p ~/.config/mimocode/hooks && curl -fsSL https://raw.githubusercontent.com/Cipher208/mimocode-rtk-hook/master/hooks/rtk.ts -o ~/.config/mimocode/hooks/rtk.tsNo config changes needed — MiMoCode auto-discovers files in hooks/.
After restarting MiMoCode, run a command:
ls /tmpCheck that it executes as rtk ls /tmp by looking at the output format (tree vs list).
Set the RTK_HOOK_LOG environment variable to log rewrite activity:
export RTK_HOOK_LOG=/tmp/rtk-hook.logThen check the log:
tail -f /tmp/rtk-hook.log| Command | Rewritten to |
|---|---|
ls |
rtk ls |
cat |
rtk read |
grep |
rtk grep |
find |
rtk find |
tree |
rtk tree |
git status/diff/log/add/commit/push/pull/branch/fetch/stash/show |
rtk git ... |
gh pr/issue/run/api/release |
rtk gh ... |
docker ps/images/logs |
rtk docker ... |
kubectl get/logs/describe |
rtk kubectl ... |
Commands already prefixed with rtk are passed through unchanged.
Multi-line scripts are processed line-by-line — each command in a script is independently rewritten.
MiMoCode scans hook/ and hooks/ directories in the config path for *.ts and *.js files. Each file must export default a Hooks object (from @mimo-ai/plugin).
File hooks are:
- Compiled with Bun.build on load (TypeScript works)
- Hot-reloaded when the file changes on disk
- Circuit-breakered — skipped after 3 consecutive failures
Available hooks: tool.execute.before, tool.execute.after, shell.env, event, chat.message, session.pre, session.post, and more. See the MiMoCode plugin SDK for the full Hooks interface.
Block dangerous commands:
// ~/.config/mimocode/hooks/safety.ts
export default {
"tool.execute.before": async (input, output) => {
if (input.tool !== "bash") return
const cmd = output.args?.command ?? ""
if (/rm\s+-rf\s+\//.test(cmd)) {
output.cancel = true
output.cancelReason = "Blocked: dangerous rm -rf on root"
}
},
}// ~/.config/mimocode/hooks/env.ts
export default {
"shell.env": async (input, output) => {
output.env.NODE_ENV = "development"
output.env.DEBUG = "true"
},
}// ~/.config/mimocode/hooks/auto-read.ts
export default {
"permission.ask": async (input, output) => {
if (["read", "glob", "grep"].includes(input.permission)) {
output.status = "allow"
}
},
}MiMoCode's external plugin system ("plugin": ["..."] in config) discovers plugin files but does not execute their module code. File hooks (hooks/*.ts) are the only working mechanism for custom hook logic.
| Mechanism | Status | Works? |
|---|---|---|
External plugins ("plugin": [...]) |
Module code never executed | No |
File hooks (hooks/*.ts) |
Compiled and executed | Yes |
| Internal plugins (compiled into binary) | Always work | Yes |
MIT