Skip to content

Commit f9e1122

Browse files
added hooks plugins
1 parent f1d2d56 commit f9e1122

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

docs/cli/configuration/plugins.mdx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Plugins are directories containing a manifest file (`.factory-plugin/plugin.json
1717
| **Skills** | Reusable capabilities with instructions and tools | Model-invoked automatically based on task |
1818
| **Commands** | Slash commands for specific workflows | User-invoked via `/command-name` |
1919
| **Agents** | Specialized subagent definitions | Called via Task tool |
20+
| **Hooks** | Lifecycle event handlers | Automatic on matching events |
2021
| **MCP Servers** | External tool integrations | Available as tools when plugin is active |
2122

2223
## When to use plugins vs standalone configuration
@@ -91,9 +92,43 @@ my-plugin/
9192
```
9293

9394
<Warning>
94-
Don't put `commands/`, `skills/`, or `droids/` inside the `.factory-plugin/` directory. Only `plugin.json` goes inside `.factory-plugin/`. All other directories must be at the plugin root level.
95+
Don't put `commands/`, `skills/`, `droids/`, or `hooks/` inside the `.factory-plugin/` directory. Only `plugin.json` goes inside `.factory-plugin/`. All other directories must be at the plugin root level.
9596
</Warning>
9697

98+
### Plugin hooks
99+
100+
Plugins can include hooks that execute at specific lifecycle events. Add a `hooks/` directory with a `hooks.json` file:
101+
102+
```
103+
my-plugin/
104+
├── .factory-plugin/
105+
│ └── plugin.json
106+
├── hooks/
107+
│ ├── hooks.json # Hook configuration
108+
│ └── my-script.sh # Hook scripts
109+
└── ...
110+
```
111+
112+
**hooks/hooks.json example:**
113+
114+
```json
115+
{
116+
"PostToolUse": [
117+
{
118+
"matcher": "Write|Edit",
119+
"hooks": [
120+
{
121+
"type": "command",
122+
"command": "${DROID_PLUGIN_ROOT}/hooks/format.sh"
123+
}
124+
]
125+
}
126+
]
127+
}
128+
```
129+
130+
Use `${DROID_PLUGIN_ROOT}` to reference files within your plugin directory. This variable is expanded to the actual plugin path when the hook runs. See [Hooks reference](/reference/hooks-reference#plugin-hooks) for details.
131+
97132
### Plugin manifest
98133

99134
The manifest at `.factory-plugin/plugin.json` defines your plugin's identity:

docs/guides/building/building-plugins.mdx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,47 @@ Report findings with severity levels and remediation steps.
197197

198198
See [Custom Droids](/cli/configuration/custom-droids) for full agent configuration options.
199199

200+
## Adding hooks
201+
202+
Define lifecycle hooks in `hooks/hooks.json`:
203+
204+
```
205+
my-plugin/
206+
└── hooks/
207+
├── hooks.json
208+
└── format-check.sh
209+
```
210+
211+
### Hook configuration
212+
213+
```json
214+
{
215+
"PostToolUse": [
216+
{
217+
"matcher": "Write|Edit",
218+
"hooks": [
219+
{
220+
"type": "command",
221+
"command": "${DROID_PLUGIN_ROOT}/hooks/format-check.sh",
222+
"timeout": 30
223+
}
224+
]
225+
}
226+
]
227+
}
228+
```
229+
230+
### Environment variables
231+
232+
| Variable | Description |
233+
|----------|-------------|
234+
| `${DROID_PLUGIN_ROOT}` | Absolute path to your plugin directory |
235+
| `${CLAUDE_PLUGIN_ROOT}` | Alias for `${DROID_PLUGIN_ROOT}` (Claude Code compatibility) |
236+
237+
<Note>
238+
Plugin hooks cannot be imported via `/hooks import`. They only function within installed plugins where the plugin root path can be resolved.
239+
</Note>
240+
200241
## Adding MCP servers
201242

202243
Configure MCP servers in `mcp.json` at the plugin root:

0 commit comments

Comments
 (0)