Hooks: adjust output to work for codex, extended docs

This commit is contained in:
Michael Panchenko committed 2026-05-04 17:51:21 +02:00
1 parent 4b0865c33b
commit 6eb3587dcc
3 files changed
+260 -62

No files matched your search

+61 -3
View File
@@ -318,9 +318,67 @@ The Codex app does not start a session in the project's directory, so when using
asking Codex to "Activate the current dir as project using serena" at the start of each session (though Codex might
do this automatically).
**Hooks.** The Codex hook system is less refined than of VSCode or Claude Code, but Codex also displays less drift
and is better in using Serena's tools out of the box. If you use the Codex app, you can consider setting up the
SessionStart hook (see above) to remind the agent to activate the project directory.
**Hooks.**
Codex supports lifecycle hooks; see the
[Codex hooks documentation](https://developers.openai.com/codex/hooks) for details. To enable
Serena's hooks for Codex, add this feature flag to `~/.codex/config.toml`:
```toml
[features]
codex_hooks = true
```
Then create `~/.codex/hooks.json` with the following content:
```json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "serena-hooks remind --client=codex"
}
]
}
],
"SessionStart": [
{
"matcher": "startup|resume",
"hooks": [
{
"type": "command",
"command": "serena-hooks activate --client=codex"
}
]
}
],
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "serena-hooks cleanup --client=codex"
}
]
}
]
}
}
```
The hooks will:
- **`activate`**: Prompt the agent to activate the current project and read Serena's instructions
when a Codex session starts or resumes.
- **`remind`**: Nudge the agent to use Serena's symbolic tools when it makes too many consecutive
code-search or code-file-read calls without using Serena tools in between.
- **`cleanup`**: Clean up hook session data when the session ends.
The `PreToolUse` matcher is intentionally restricted to `Bash`. The Serena reminder hook for Codex
tracks shell-based grep and code-file reads, so running it for every tool call is unnecessary.
## Claude Desktop