Add --hook-* CLI flags to override agent hooks from the command line#2135
Add --hook-* CLI flags to override agent hooks from the command line#2135dgageot wants to merge 1 commit intodocker:mainfrom
Conversation
Add five new repeatable flags (--hook-pre-tool-use, --hook-post-tool-use, --hook-session-start, --hook-session-end, --hook-on-user-input) that let users attach lifecycle hooks to any agent without modifying its YAML config. CLI hooks are merged (appended) with any hooks already defined in the agent configuration. Empty/whitespace-only commands are silently skipped. - Add hook string-slice fields to RuntimeConfig and CLI flag registration - Add HooksFromCLI, MergeHooks helpers with comprehensive tests - Hoist CLIHooks() computation before the agent loop in teamloader - Document new flags in CLI reference and hooks configuration pages Assisted-By: docker-agent
There was a problem hiding this comment.
Review Summary
Assessment: 🟢 APPROVE
This PR cleanly implements CLI flags for attaching lifecycle hooks to agents without modifying YAML config. The implementation is well-structured with proper testing and documentation.
Code Quality
✅ Hook merging logic — Correctly appends CLI hooks to config hooks without mutation
✅ Empty command filtering — Properly skips whitespace-only commands
✅ Clone implementation — New hook fields properly cloned with slices.Clone()
✅ Integration point — CLI hooks merged at the right place in teamloader
✅ Test coverage — Comprehensive tests for all edge cases (empty commands, merging, isolation)
✅ Documentation — Both CLI reference and hooks docs updated with examples
Findings
No issues found in the changed code. The implementation follows Go best practices and handles edge cases correctly.
Note: During review, a pre-existing nil pointer dereference was identified in pkg/config/runtime.go line 40 (DefaultModel.Clone() when DefaultModel is nil). This is outside the scope of this PR but may warrant a separate fix.
Review completed by docker-agent PR reviewer
Summary
Add five new repeatable CLI flags that let users attach lifecycle hooks to any agent without modifying its YAML config:
--hook-pre-tool-use <cmd>— runs before every tool call--hook-post-tool-use <cmd>— runs after every tool call--hook-session-start <cmd>— runs when a session starts--hook-session-end <cmd>— runs when a session ends--hook-on-user-input <cmd>— runs when waiting for user inputExample
Details
matcher: "*")Changes
pkg/config/runtime.go— Add hook string-slice fields toConfig; updateClone()pkg/config/hooks.go(new) —HooksFromCLI(),MergeHooks(), andCLIHooks()helperspkg/config/hooks_test.go(new) — Comprehensive tests including empty-command filtering, merge semantics, clone isolationcmd/root/flags.go— Register the five--hook-*flagspkg/teamloader/teamloader.go— Merge CLI hooks into agent config at load time (hoisted before loop)docs/features/cli/index.md— Document new flags in CLI referencedocs/configuration/hooks/index.md— Add CLI Flags section to hooks docs