feat: shell hooks — wire shell scripts as Hermes hook callbacks (PR #13143)#13296
Merged
Conversation
Users can declare shell scripts in config.yaml under a hooks: block that fire on plugin-hook events (pre_tool_call, post_tool_call, pre_llm_call, subagent_stop, etc). Scripts receive JSON on stdin, can return JSON on stdout to block tool calls or inject context pre-LLM. Key design: - Registers closures on existing PluginManager._hooks dict — zero changes to invoke_hook() call sites - subprocess.run(shell=False) via shlex.split — no shell injection - First-use consent per (event, command) pair, persisted to allowlist JSON - Bypass via --accept-hooks, HERMES_ACCEPT_HOOKS=1, or hooks_auto_accept - hermes hooks list/test/revoke/doctor CLI subcommands - Adds subagent_stop hook event fired after delegate_task children exit - Claude Code compatible response shapes accepted Cherry-picked from PR #13143 by @pefontana.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Shell hooks let users declare shell scripts in config.yaml that fire on plugin-hook events. Scripts receive JSON on stdin and can block tool calls or inject context.
Cherry-picked from PR #13143 by @pefontana onto current main.
Changes
agent/shell_hooks.py(831 lines): Core engine — config parsing, consent model, subprocess execution, PluginManager integrationhermes_cli/hooks.py(385 lines): CLI subcommands — list/test/revoke/doctorhermes_cli/main.py: --accept-hooks flag propagation, agent-command gating for hook registrationgateway/run.py: +33 lines — defensive hook registration at gateway startuphermes_cli/plugins.py: +1 line — adds subagent_stop to VALID_HOOKStools/delegate_tool.py: +45 lines — fires subagent_stop hook after children completehermes_cli/config.py: hooks: {} and hooks_auto_accept: false defaultscli-config.yaml.example: Documented hooks config blockwebsite/docs/user-guide/features/hooks.md: Full documentation with wire protocol, examples, comparison tableValidation