π Prerequisites
π Feature Summary
Support hooks similar to claude code / opencode / etc
β Problem Statement / Motivation
A hooks system can give a lot of power to the agent developer/operator to add capabilities without having to modify the core product, for example:
- memory systems
- PII/abuse redaction
- tool policy to support approve/block/ask based on tool content rather than just the name (or even use an LLM to analyze the tool call and recommend)
- keyword based prompt injection
- running built/lint automatically after a code change
- notifications to the user about bot prompts/activities (e.g. to slack or another messenger)
Basically it allows for kagent to be a better platform to build on top of without having to provide everything built-in.
See also
π‘ Proposed Solution
I think an OK initial implementation would be to support the same protocol as claude code and install it using containers, similar to how skills are done currently but for hooks.
You would list hooks in the agent spec in a similar manner as this:
- hooks:
- ref: repo/img:version # docker container to load
event: PreToolUse # hook called before running a tool, to return approve/deny/ask for that tool call
type: claude-command # Having a hook type allows for additional hook modes to be added in the future with a different protocol
matcher: "bash|shell_exec" # Only run if the tool matches the pattern
command: 'check-tool-use.sh' # Hook implementation
- ref: repo/img:version # docker container to load
event: SessionStart # Runs before the first user message in a session
type: claude-command
command: 'inject-session-metadata-message.py'
If the same container ref is used by multiple hooks it should be mounted only once.
The hooks are a command that reads a single JSON object as input and writes a single JSON object as output, or writes a message to stderr and exits with code 2.
See claude code docs for more details: https://code.claude.com/docs/en/hooks
π Alternatives Considered
Up until now I have been keeping a fork of kagent that has some added features that I need. The hook would allow me to move some of that stuff into hooks.
π― Affected Service(s)
App Service
π Additional Context
No response
π Are you willing to contribute?
π Prerequisites
π Feature Summary
Support hooks similar to claude code / opencode / etc
β Problem Statement / Motivation
A hooks system can give a lot of power to the agent developer/operator to add capabilities without having to modify the core product, for example:
Basically it allows for kagent to be a better platform to build on top of without having to provide everything built-in.
See also
π‘ Proposed Solution
I think an OK initial implementation would be to support the same protocol as claude code and install it using containers, similar to how skills are done currently but for hooks.
You would list hooks in the agent spec in a similar manner as this:
If the same container ref is used by multiple hooks it should be mounted only once.
The hooks are a command that reads a single JSON object as input and writes a single JSON object as output, or writes a message to stderr and exits with code 2.
See claude code docs for more details: https://code.claude.com/docs/en/hooks
π Alternatives Considered
Up until now I have been keeping a fork of kagent that has some added features that I need. The hook would allow me to move some of that stuff into hooks.
π― Affected Service(s)
App Service
π Additional Context
No response
π Are you willing to contribute?