MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / AgentHook

Interface AgentHook

atomic-agent/src/hooks/mod.rs:132–262  ·  view source on GitHub ↗

Trait for agent hook adapters. Each AI coding agent (Claude Code, Gemini CLI, Codex, OpenCode) implements this trait to: 1. **Parse** agent-specific JSON from stdin into a common [`TurnEvent`] 2. **Install** hooks into the agent's configuration file 3. **Uninstall** hooks from the agent's configuration file 4. **Detect** whether hooks are currently installed Implementations must be `Send + Sync

Source from the content-addressed store, hash-verified

130/// can return `Ok(0)` / `Ok(())` for agents that don't support hook
131/// installation (e.g., agents detected via file watching instead).
132pub trait AgentHook: Send + Sync + fmt::Debug {
133 /// Returns the registry key for this agent.
134 ///
135 /// This is the string used in CLI commands:
136 /// `atomic agent enable --agent <name>`
137 /// `atomic agent hooks <name> <verb>`
138 ///
139 /// Convention: lowercase with hyphens (e.g., "claude-code", "gemini-cli").
140 fn name(&self) -> &str;
141
142 /// Returns a human-readable display name.
143 ///
144 /// Used in UI output and log messages (e.g., "Claude Code", "Gemini CLI").
145 fn display_name(&self) -> &str;
146
147 /// Parse hook input from an agent callback into a normalized [`TurnEvent`].
148 ///
149 /// The `input` parameter is the raw bytes read from stdin when the agent
150 /// invokes the hook. Each agent sends a different JSON format.
151 ///
152 /// # Arguments
153 ///
154 /// * `hook_type` - The type of lifecycle event (from the CLI verb)
155 /// * `input` - Raw bytes from stdin (typically JSON)
156 ///
157 /// # Errors
158 ///
159 /// Returns [`AgentError::HookParseFailed`] if the input cannot be parsed,
160 /// or [`AgentError::HookInputEmpty`] if `input` is empty.
161 fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent>;
162
163 /// Install hooks into the agent's configuration file.
164 ///
165 /// This writes entries into the agent's settings file (e.g.,
166 /// `.claude/settings.json`) that call back to `atomic agent hooks`.
167 ///
168 /// # Arguments
169 ///
170 /// * `repo_root` - The repository root directory (where `.atomic/` lives)
171 ///
172 /// # Returns
173 ///
174 /// The number of hooks that were installed. Returns 0 if all hooks
175 /// were already present.
176 ///
177 /// # Errors
178 ///
179 /// Returns [`AgentError::ConfigError`] if the config file cannot be
180 /// read or written.
181 fn install(&self, repo_root: &Path) -> AgentResult<usize>;
182
183 /// Remove hooks from the agent's configuration file.
184 ///
185 /// Removes only hooks with the `atomic agent hooks` prefix — other
186 /// hooks in the agent's config are preserved.
187 ///
188 /// # Arguments
189 ///

Callers

nothing calls this directly

Implementers 15

gemini_cli.rsatomic-agent/src/hooks/gemini_cli.rs
mod.rsatomic-agent/src/hooks/mod.rs
copilot.rsatomic-agent/src/hooks/copilot.rs
cline.rsatomic-agent/src/hooks/cline.rs
hermes.rsatomic-agent/src/hooks/hermes.rs
codex.rsatomic-agent/src/hooks/codex.rs
pi.rsatomic-agent/src/hooks/pi.rs
agy.rsatomic-agent/src/hooks/agy.rs
kiro.rsatomic-agent/src/hooks/kiro.rs
kilo.rsatomic-agent/src/hooks/kilo.rs
opencode.rsatomic-agent/src/hooks/opencode.rs
grok.rsatomic-agent/src/hooks/grok.rs

Calls

no outgoing calls

Tested by

no test coverage detected