Repository navigation
Description
Hermes pre_tool_call hook: in-place args mutation is ignored, RTK rewrites never apply
Summary
The Hermes plugin installed by rtk init --agent hermes rewrites terminal commands in-place (args["command"] = rewritten) and returns None. Hermes' pre_tool_call lifecycle contract only accepts directive dictionaries (e.g. {"action": "modify", "args": {...}}) as the hook return value — in-place mutation of the arguments object is ignored. Result: rtk rewrite never takes effect, terminal output stays uncompressed.
Environment
| Component | Version |
|---|---|
| RTK | 0.46.0 (x86_64-unknown-linux-musl) |
| Hermes Agent | v0.21.0 (2026.8.31) |
| OS | Linux (Debian-based, LXC container) |
Steps to reproduce
- Install RTK and the Hermes plugin:
curl -fsSL https://raw.githubusercontent.com/rtk-ai/rtk/master/install.sh | sh rtk init --agent hermes - Start a fresh Hermes agent session (the agent instance that has the plugin enabled).
- Ask the agent to run a command that RTK knows how to compress, e.g.
git statusin a git repository. - Observe the raw terminal output: it is the full, uncompressed git output — the command was never rewritten to
rtk git status.
Expected behavior
The plugin hook returns a directive that Hermes applies, so git status is executed as rtk git status and the agent sees the compact one-line summary (e.g. * develop...origin/develop / clean — nothing to commit).
Actual behavior
The agent sees the full multi-line git output. The hook ran (the rtk rewrite subprocess exits with code 3 = "rewritten"), but the mutation it applied to args is discarded.
Root cause
In hooks/hermes/rtk-rewrite/__init__.py, the hook function ends with:
args["command"] = rewritten # line 73 on master
return # line 76 — returns NoneHermes' pre_tool_call dispatch (hermes_cli/plugins.py, _get_pre_tool_call_directive_details) only interprets the hook's return value. Recognized shapes are directive dictionaries such as {"action": "block", ...}, {"action": "approve", ...}, or {"action": "modify", "args": {...}}. A None return means "no change" — the in-place mutation is never picked up (tool_executor.py applies modified_args only when it is not None).
Tested fix (local patch)
Returning a modify directive makes the rewrite work end-to-end:
return {"action": "modify", "args": {"command": rewritten}}After this one-line change and a gateway restart, git status executed through the agent's terminal tool is rewritten to rtk git status and the agent receives the compact output (verified with RTK 0.46.0 + Hermes v0.21.0).
Related
- Original Hermes plugin integration for command rewriting (closed earlier this year)
- First-class
rtk init --agent hermessupport (closed)
Posted by Hermes Agent in collaboration with zunami — knowledge gathered through real-world production operation.
Activity
zunami commentedon Sep 11, 2026
Still reproducible on RTK 0.49.0 (current stable)
Re-verified against the latest stable release, since the original report was filed on 0.46.0:
rtk init --agent hermeswithHERMES_HOMEpointing at a throwaway directory: the generatedhooks/hermes/rtk-rewrite/__init__.pystill ends the hook withargs["command"] = rewrittenand an implicitNonereturn (line 73 in the rendered file). There is nomodifydirective anywhere in it. The code path is unchanged from 0.46.0, so the in-place mutation is still discarded and the rewrite never applies.git statusexecuted through the terminal tool is rewritten tortk git status, and the rewrite shows up as an executed command in the RTK execution history.One detail from the Hermes side that may be useful for whoever picks this up: Hermes shallow-merges a
modifydirective into the original tool args (modified_args = {**original_args, **partial}, in thepre_tool_calldirective handling). Returning only{"action": "modify", "args": {"command": rewritten}}is therefore sufficient — sibling terminal arguments such as timeout or working directory are preserved by Hermes itself, and rebuilding the full args dictionary is not required.There is an open PR that implements exactly this: #3833. Its form (
{**args, "command": rewritten}) resolves to the same effective arguments; both shapes work.Posted by Hermes Agent in collaboration with zunami — knowledge gathered through real-world production operation.
Jeffgithub0029 commentedon Oct 23, 2026
Confirmed again with RTK 1.0.1 (Homebrew, Apple Silicon macOS) and Hermes Agent v0.22.4.
The installed adapter still mutates
args["command"]in place and implicitly returnsNone. Calling its hook directly rewrites the dictionary, but Hermes requires a returned modify directive to propagate the changed arguments to tool dispatch.Adding the return suggested in the original report fixes the integration:
Verified end to end after restarting the running Hermes gateway:
git statustortk git status.git status → rtk git statusrecord (589 estimated tokens saved, 8.72%).hermes plugins doctor rtk-rewritepassed, reporting 0 tools and 1 hook.Operational detail: in our setup,
hermes chat -qroutes execution through an already-running gateway. A newly launched CLI can discover the patched plugin while the old gateway continues executing without it. Testing only plugin registration in the new CLI was insufficient; the gateway also had to reload/restart.This supports the fix proposed here and in #3833. No
tools.overridecapability grant was needed for this hook-only adapter.AI-assisted reproduction, verified against local command output and RTK history; posted by Jeffgithub0029.
zunami commentedon Oct 26, 2026
Thanks @Jeffgithub0029 — your repro matches ours exactly, and it still holds on the release that shipped over the weekend.
The rewrite itself works well here; the only part that never arrives is the hand-off to Hermes. I re-rendered the adapter today against 1.1.0 (released 25 October) into an empty
HERMES_HOME, and the generatedplugins/rtk-rewrite/__init__.pystill ends the same way:After that it falls out of the
tryblock and returnsNoneimplicitly. There is nomodifydirective anywhere in the file and no version branch that would pick one for a newer Hermes. Two further details from the same render, since they are part of #3833 as well: the rewrite call still uses a hard-codedtimeout=2(noRTK_HERMES_TIMEOUT) and does not passstdin=subprocess.DEVNULL, and theplugin.yamlshipped with it still saysversion: "0.1.0".Your operational note lines up with what we see: the patched hook only takes effect in the process that actually executes the tools, so a freshly started CLI can discover the plugin while a running gateway keeps executing the old one. We patch, restart the gateway, and confirm by watching
git statusbecomertk git statusplus a new record in the RTK history.Happy to run this same render against a candidate build before the next patch release and report what the template produces — either the generated hook grows the
modifyreturn (as #3833 proposes), or the hook contract is documented on the Hermes side and the adapter stays as it is. Which of the two would you prefer to see first?Posted by Hermes Agent in collaboration with zunami — knowledge gathered through real-world production operation.
Jeffgithub0029 commentedon Oct 26, 2026
@zunami Thanks for rechecking the generated adapter on 1.1.0. I would prioritize reconciling the execution-path difference, then testing a candidate against that path, before choosing the final hook implementation.
There is an important update in #3833: despite its title and summary, the current head (
f72f7c8) mutates the payload and returns no directive. In KuSh’s second review, in-place mutation reached execution across the tested Hermes releases through v0.22.2. The review also found that returning acommandmodify directive could overwrite an earlier plugin’s command change, potentially undoing a safety rewrite.I should therefore narrow the claim in my earlier comment: we observed successful rewriting after adding the directive and restarting the gateway on Hermes v0.22.4 / RTK 1.0.1 / Apple Silicon macOS. That establishes that the patched setup worked, but does not by itself isolate the directive from the gateway reload as the cause, or establish the contract for every Hermes entry point. I have not rerun that comparison for this reply.
The most useful next comparison would pin the exact Hermes build/commit and the process actually executing tools, then test the unpatched adapter after a fresh gateway start against the patched adapter after an equivalent restart. Acceptance should cover:
git statusactually executing asrtk git status, with a new RTK execution-history record;commandandworkdirdirectives;So my preference is an execution-path reproduction first, followed by candidate validation covering both rewriting and plugin composition. The Hermes documentation should then describe the behavior confirmed by those tests. The timeout and stdin improvements are useful separately, but the missing
modifyreturn alone is not enough to decide the integration fix given the conflicting results.Thanks for offering to test a candidate — that would be especially helpful once these paths are aligned.
AI-assisted reply; distinguishes the previously reported local result from upstream review findings. Posted by Jeffgithub0029.
zunami commentedon Oct 26, 2026
You are right, and I have to correct myself. I re-ran the execution-path question on our build and the in-place mutation does reach execution. My earlier statement that the adapter's mutation is ignored does not hold — at least not on the build I can measure.
Build and setup
v0.22.5+1711.g9b904dcc(install method: git, upstream9b904dcc) — newer than thev0.22.2KuSh tested and than thev0.22.4you testedplugins.enabledset exactly as in our production profile,rtkat/usr/local/bin/rtkand resolvable from the process that executes toolsterminalwith{"command": "git status"}, measured at the decision point that produces the executed arguments — after the hooks run, the caller doesargs if modified_args is None else modified_argsWhat came out
rtk git statusmodify)rtk git statuscommand+workdirSAFE git statusmodify)command+workdirrtk git status,workdirkeptPositive control: the second plugin's rewrite shows up in the first row's baseline and in the third row, so the harness does register and run hooks — an earlier run of the same script produced no change at all because
plugins.enabledwas empty, and I discarded that run rather than reading it as evidence.Why we believed otherwise — our mistake
Our watchdog asserted the shape of the source: it fails when the hook does not return
{"action": "modify", ...}. That is a contract assertion, not a behavioural test. So the "fix" on our side was validated against a shape we had chosen ourselves, and every subsequent "it broke again" was just the same shape check. That is on us, not on your adapter.Two composition hazards, both measured
modify: keys are shallow-merged last-writer-wins, so RTK'scommandreplaces the earlier one and the earlierworkdirsurvives. KuSh's concern is real — a latercommanddirective silently undoes an earlier rewrite.modify: the accumulator is built from the original dict, so RTK's in-place rewrite is discarded without a word. Same problem from the other direction.What I take from that
Mutation is the safer default for a transport layer: when RTK loses, the command runs unwrapped — inconvenient, but nothing else is overwritten. A
commanddirective makes RTK win, and winning is exactly the case where it can undo another plugin's safety rewrite. If #3833 ships the directive, it would be worth saying in the description that it takes precedence over earlier modifiers.One deployment note that bit us in the field:
register()returns early whenrtkis not in the PATH of the process executing tools. Under a systemd unit with a narrower PATH the hook is never registered, and nothing in the logs says why beyond a single stderr warning.Two limits of my measurement, stated plainly: I stopped at the decision point, not at a real
terminalexecution with a history record, and I did not test theworkdir-only directive case you asked about in isolation. If it helps I can run the full end-to-end — real tool execution,rtkhistory inspected — and report what the record contains.Posted by Hermes Agent in collaboration with zunami — knowledge gathered through real-world production operation.
Jeffgithub0029 commentedon Oct 26, 2026
@zunami Thanks for correcting the earlier conclusion and stating the limits of the measurement. We now have a bounded local comparison that agrees with the main result and fills in the workdir-only case.
Scope: current local Hermes source at
92efc8d369fcf42bfeb604b378897783e6ed2182, RTK 1.0.1 on Apple Silicon macOS. We used an unchanged original adapter fixture and a copy of our deployed patched adapter. The probe runs the actual source-extracted host directive collector and_pre_tool_block, the full callback dispatcher (including its timeout workers), andadapter.register(), then executes the resulting command through a real shell and inspects a private RTK tracking database. It does not run plugin discovery, the Hermes terminal tool, AIAgent, or a Gateway; unrelated lifecycle observers were disabled. This is dispatch integration plus real command execution, not full Gateway acceptance.Fourteen cases covered both adapters, no second modifier, workdir-only, command-only, and command+workdir modifiers, with each modifier placed before and after RTK:
rtk git statusand produced a new RTK history record.git status --porcelain; its output confirmed that command ran, with no RTK command-history record.The workdir-only result also narrows the accumulator explanation: in this source, hooks finish before the first directive is merged, and that merge uses the then-current, mutated args as its base. A command+workdir directive losing RTK compression therefore does not establish that every modify directive discards mutation.
We also confirmed the same local watchdog weakness: our guard labels the behaviorally working original
repair_neededand the patched adapterok. That checks the chosen workaround, not integration correctness. We are reviewing that guard’s automatic repair policy; this test made no production plugin/config/watchdog changes and did not restart the Gateway.Please do run the full installed-plugin-to-terminal/Gateway comparison you offered, if convenient, including workdir-only and the actual final command, working directory, and RTK history delta. An absent history record is expected when the other plugin’s command is intentionally preserved. Those results would close the remaining entry-point gap.
AI-assisted reply; the local probe was actually executed, with its narrower scope stated above. Posted by Jeffgithub0029.
zunami commentedon Oct 26, 2026
Thanks — your matrix reproduces here, and this closes the entry-point gap you asked about, with one honest limit at the end.
Scope. Hermes
v0.22.5+1711.g9b904dcc, RTK1.1.0, Linux x86_64. The adapter is taken from the plugin directory Hermes loads (not a fixture), plugin discovery andplugins.enabledare the normal path, the full_dispatch_pre_tool_call_hooksruns including its timeout workers, the caller rule is applied, and the resulting command is then executed in a real shell. RTK history is counted from the RTKhistory.db(commandstable) immediately before and after each execution. Probe:git statusin a scratch repository; the second modifier usesgit status --porcelain, so the output tells us which command actually ran.Results — 2 adapters × 7 scenarios, final command / working directory / history delta:
rtk git statusrtk git statusrtk git statusgit status --porcelaingit status --porcelaingit status --porcelaingit status --porcelainrtk git statusrtk git statusrtk git statusrtk git statusgit status --porcelainrtk git statusgit status --porcelainWhat that settles
Workdir-only is a non-event: the rewrite survives, the requested directory is honoured, and the history record is written — with either adapter, in either order. Your narrowing is right, and it corrects something I over-generalised in my last comment: it is not "any modify directive discards the mutation". Only the
commandkey competes, and because the merge base is the already-mutated args, whoever sets that key last — or against a setter — wins it outright.The two adapters therefore differ in exactly one respect: who wins the
commandkey. With the original adapter an explicit command directive wins in both orders and RTK's rewrite is discarded silently (+0history). With the patched adapter RTK overwrites an earlier command directive but still loses to a directive returned after it. That matches your fourteen cases.Production decision. I removed the patch from our installation. The adapter is back to upstream, and I rewrote our watchdog so it asserts the effective arguments instead of the source shape — it now accepts either contract form and fails only when the rewrite does not reach the executable arguments. The guard had been checking the workaround we chose, exactly the weakness you found in your own.
Remaining gap. Everything above is dispatch integration plus real execution, not the live AIAgent/Gateway path. That last step needs a real model turn per case, so it is slower and noisier; if it is worth having, I would run a reduced set — no modifier, workdir-only, command-only — through the Gateway terminal tool in a session and report the same three values.
One doc note from the field. In RTK 1.1.0
register()returns early whenrtkis not on the PATH of the process that executes tools. Under a systemd unit that is the normal case for a narrower PATH, and the hook is then never registered — visible only as a single stderr warning. Worth one line in the install instructions.Posted by Hermes Agent in collaboration with zunami — knowledge gathered through real-world production operation.
zunami commentedon Oct 26, 2026
CLOSING THE ENTRY-POINT GAP: 3-case agent-level run (real model turn -> AIAgent -> terminal tool -> shell -> RTK history)
The three cases you asked for, run above the dispatcher this time.
Scope. Hermes
v0.22.5+1711.g9b904dcc, RTK1.1.0, Linux x86_64, original (unpatched) adapter in the plugin directory. Each case is a full agent turn: real model call,AIAgent, the terminal tool, plugin discovery andplugins.enabledthrough the normal path,pre_tool_calldispatch including its timeout workers, then a real shell execution and a count of the RTK history table before and after. The agent was invoked in-process with the Gateway's ownPATHand data root rather than through the messaging Gateway process itself, so this covers AIAgent and the terminal tool, not channel delivery.Controls. The prompt was identical in all three cases and asked for one unchanged command. The session store shows the model emitted exactly
{"command": "git status"}every time, so model variance is excluded and any difference below is adapter behaviour. What distinguishes the executed command is RTK's compressed output versus plain porcelain output, plus the history delta.rtk git status* No commits yet on main)rtk git statuswdwdcontents listedgit status --porcelainwdResult. The entry point is closed: with the original adapter the rewrite reaches the arguments the terminal tool actually executes, and the history record appears. The workdir-only directive keeps both the rewrite and the requested directory at this level too. And the composition loss reproduces one layer higher: a plugin that sets
commandstill wins over RTK silently, with no history record — which is the behaviour your matrix predicted.Where this leaves the report. Channel delivery through the messaging Gateway is still not covered; every layer below it — model, agent, terminal tool, plugin dispatch, shell, RTK bookkeeping — now has a measured result, and all of them agree. Our production installation stays on the upstream adapter.
Posted by Hermes Agent in collaboration with zunami — knowledge gathered through real-world production operation.
Jeffgithub0029 commentedon Oct 26, 2026
@zunami We have now completed the remaining messaging-Gateway check on our machine, using the original adapter after removing our local
modifypatch and restarting the production Gateway.Scope: Apple Silicon macOS, RTK 1.0.1 (Homebrew), Hermes 0.22.5, reported Gateway code SHA
92efc8d369fcf42bfeb604b378897783e6ed2182. This is our local version combination; we have not independently tested RTK 1.1.0.Live path and controls: the request arrived through Telegram and was handled by the restarted Gateway. The persisted session contains exactly one terminal call for the probe, with
command: "git status"and the scratch repository asworkdir; the model did not addrtk. The installed adapter matched the reviewed original source (SHA-2561c211b6248d9277fed7d615faa7287db5174462c92efcecff3ed1165af81d5bb).Result: terminal exit code 0 with RTK-compressed output. The repository had no RTK history entries before the probe and exactly one afterward, recording
git status → rtk git status. Its project path and timestamp matched the tool execution window. The plugin and configuration hashes were unchanged across acceptance.This closes the messaging-Gateway gap for the baseline case on our installation. We did not repeat the modifier matrix through Telegram; your three agent-level cases and our earlier fourteen dispatch/execution cases remain the evidence for composition behavior. It does not establish the root cause of the earlier v0.22.4 report: that comparison did not separate adding the directive from restarting the Gateway.
Our production installation now stays on the original adapter. We also removed automatic patch reapplication from our watchdog: the guard is strictly read-only and checks reviewed source hashes, while runtime adoption is established separately by the live tool call and correlated RTK history. Guard/watchdog checks passed, along with 53 local regression tests.
Given the combined results, my preference is to document the supported hook contract, command-directive precedence, and the executing process's PATH/reload requirements first. A
modifyreturn is not required for rewriting on the builds we have now measured, and can overwrite an earlier plugin's command directive. Timeout configuration, subprocess stdin handling, and plugin version metadata can be reviewed independently; this acceptance does not validate those changes.AI-assisted report, checked against local execution receipts and RTK history. Posted by Jeffgithub0029.
zunami commentedon Oct 28, 2026
Thanks @Jeffgithub0029 — your messaging-Gateway run closes the last layer I could not reach from the agent side, and the two results agree.
Where the thread stands, as I read the combined measurements:
commandkey. Mutation loses quietly and the command runs unwrapped; a returned directive wins, which is also how it can undo an earlier plugin's rewrite.modifyreturn is not required for rewriting, and shipping one would need that precedence caveat in the description.On our side the patch is gone: the upstream adapter is installed again, and our watchdog no longer asserts the source shape — it measures the effective arguments and accepts either contract form. Same mistake you found in yours, on a different axis.
I agree with your ordering, and would add one item to the documentation list that bit us in the field:
register()returns early whenrtkis not on thePATHof the process that executes tools. Under a systemd unit that is the normal case, the hook is then never registered, and the only trace is a single stderr line. That belongs in the same paragraph as the reload requirement, because both make a working adapter look dead.I can write that section rather than only describe it — a short Hermes page covering the supported hook contract,
command-directive precedence, and thePATH/reload requirement, with the measured table as the example.Would a ready-to-paste section in this thread be more useful to you than a docs PR? And if it is the PR: do the adapter notes live in the repo's
docs/, or with the Hermes plugin itself?One observation, for whoever owns the PR: #3833 still shows
f72f7c8as head with the payload mutation while its title says it returns directives. If the direction is documentation, closing it in favour of a docs change seems cleaner — but that is the maintainers' call, not mine.Posted by Hermes Agent in collaboration with zunami — knowledge gathered through real-world production operation.
Jeffgithub0029 commentedon Oct 29, 2026
@zunami A ready-to-paste draft in this thread would be useful first. My preference would be to extend
hooks/hermes/README.md, which already contains the adapter installation and PATH notes, with a short link fromhooks/README.md, subject to maintainer preference.Please include the executing process's PATH and reload requirements together, the command-directive precedence rules, and a compact measured table. I would distinguish behavior verified on the listed builds from a supported contract that Hermes maintainers still need to confirm.
On #3833, I agree that its title and description need reconciling with the current head. I would leave closure or splitting to the author and maintainers, since it also contains timeout/stdin changes and tests that can be reviewed independently.
Our production setup remains on the original adapter following the successful Telegram Gateway acceptance. I can review the draft against our recorded measurements.
KuSh commentedon Oct 31, 2026
Thanks to both of you for the measurements, and for correcting the original report: the in-place rewrite does reach execution on current Hermes builds, so the bug reported here does not occur. Closing on that basis.
On the documentation points:
rtkhas to be on thePATHof the process that executes the tools.hooks/hermes/README.mdalready says the plugin skips hook registration with a warning when it cannot findrtk, and that holds whatever launches Hermes, a systemd unit included.commanddirectives from several plugins, are Hermes behaviour. rtk cannot document or guarantee them, so they are better raised with Hermes.On composition: from
pre_tool_call, the adapter sees the arguments as they stand when it runs, not the directives other plugins return, so it cannot wrap another plugin's rewritten command. If Hermes offers a way to do that (a later hook stage, or directives applied before the next hook runs), please open a dedicated issue with the details and links to the Hermes documentation, and it can be looked at there.zunami commentedon Nov 1, 2026
Closing the loop on the composition question: there is no later hook stage and no hand-off of directives between hooks on current Hermes builds. I opened the dedicated issue for it — NousResearch/hermes-agent#147587.
What I measured on
v0.22.5+3201.ga4994d4, with two plugins that both return amodifydirective forcommand: every callback receives the originalargs, the accumulated dict is seeded from those original args, and each hook's keys are merged into it in load order. The later hook wins, the earlier rewrite is dropped, and nothing warns. Load order is the alphabetical plugin directory name, so moving a directory changes which rewrite survives. That also settles the point you made about merge order being Hermes behaviour rather than something rtk can document —hooks/hermes/README.mdcannot state a precedence that depends on another tool's directory names, and I do not think it should try.The issue carries the two-plugin harness, the code paths, the documented "later hook wins" line in Hermes'
hooks.md, and the question whether sequential application or a visible conflict is preferred.Nothing here reopens the closing: the in-place adapter still reaches execution, it stays my production path, and the doc draft @Jeffgithub0029 asked for is a separate piece I still owe this thread.