bug: Codex hooks (PreToolUse/PostToolUse) are largely ineffective — 91% skipped, PostToolUse HTTP never reaches daemon
Context
After #206 landed (implemented via #207, #209, #211, #212, #213, #215, #218, #230), I've been running Codex with the hooks enabled for a day. The hooks are well-implemented and fire correctly, but I'm seeing some gaps in how they interact with Codex's actual usage patterns. Wanted to share the observations in case they're useful.
What I observed
~/.gortex/cache/hook-decisions.jsonl (64 entries, all from Bash):
| Decision | Count | % |
|---|---|---|
skipped_non_symbol |
58 | 91% |
probed_miss |
3 | 5% |
probed_hit |
2 | 3% |
timed_out |
1 | 2% |
Meanwhile, query-log.jsonl shows 64 successful MCP tool calls (search_symbols: 15, smart_context: 15, search_text: 34) across 8 sessions. The agent is using graph tools effectively — it's just being guided by AGENTS.md rather than the hooks.
PreToolUse: Bash command classifier doesn't match Codex's search patterns
Codex wraps everything in Bash. The hook parses tool_input.command to detect grep/find/cat, then checks if the pattern looks like a symbol name via classifyGrepPattern. But Codex tends to use multi-keyword |-separated patterns:
grep -rn "ai-redesign|Phase 5|entity_links|world-map" .
grep -rn "place_edges|location_edge|normalize" .
These contain |, multi-word phrases, and non-identifier tokens, so classifyGrepPattern returns NonSymbol and the hook passes through silently. This is by design for Claude Code's dedicated Grep tool (where patterns are typically single identifiers), but Codex's usage pattern is quite different.
I'm not sure what the right fix is here — maybe splitting |-separated patterns and probing each segment? Or falling back to search_text for non-symbol patterns? The current classifyBashCommand → classifyGrepPattern pipeline is solid for its original use case; it just doesn't align well with how Codex uses Bash.
PostToolUse: daemon HTTP endpoint not available by default
posttooluse.go calls queryGortex(port, path) which hits http://localhost:{port}/api/graph/symbol-at etc. But the daemon only listens on a unix socket by default — the HTTP endpoint requires --http-addr. On my setup, port 8765 happens to be occupied by another process, so all PostToolUse graph lookups silently fail.
Looking at the daemon logs, I can see zero HTTP API requests from hooks, which confirms the calls never reach the daemon.
I wonder if it would make sense to have PostToolUse fall back to the unix socket (same as probeViaDaemon in probe.go) when HTTP isn't available, or perhaps add a reachability check before attempting the HTTP calls?
Side note: binary freshness
I noticed the Homebrew-installed v0.58.3 binary was built ~2 hours before #218 merged, so the MCP read PreToolUse matcher (^mcp__gortex__(read_file|get_editing_context)$) isn't in my running binary. Not a code issue — just a packaging timing thing. Thought worth mentioning for context.
Happy to help investigate or test any fixes. The hook infrastructure is solid — the gaps seem to be in Codex-specific pattern matching and daemon connectivity.
Closing temporarily while we discuss the findings internally. Will reopen with a concrete fix plan.
@Maple0517 I'm happy to join the conversation (feel free to invite me if it possible). The issues seem to overlap with an adoption benchmark I ran recently (and it's not related only to the hooks definition, but also to the tools description, intending to convince the coding agent to use the tool without a rely to *.md driven instructions). The repository with the code used for the mentioned benchmark will be published soon (not fully ready)
@zzet Thanks for jumping in! Unfortunately my other forks are overseas and needs VPN to access GitHub, but I'd love to discuss the details here or elsewhere if easier.
A few questions and observations:
1. Benchmark preliminary results?
Curious what you've seen so far — particularly whether there's a measurable difference in tool adoption rates between "AGENTS.md tells the agent to use X" vs "the tool description itself convinces the agent". My gut feeling from the query-log data is that AGENTS.md works well for deliberate sessions but gets forgotten in long-running ones.
2. Tools description alone, or skills packaging?
When you mention improving tool descriptions to drive adoption without *.md reliance — is the idea to just improve the MCP tool's description field, or would packaging as a skill make a difference? I recall that some agents (at least Claude Code and Codex) seem to prioritize injected context skills over MCP tool descriptions at discovery time. If that's the case, a skill entry might have more "convincing power" than a tool description alone. Curious if your benchmark touched on this.
3. Context length / deferred tool forgetting
One pattern I've been seeing with Codex (and I suspect it applies to other harnesses too): when the conversation context gets long, the agent tends to forget about MCP tools — especially deferred ones (tool_search discovery). This makes sense from a attention/position-bias perspective: the MCP tool descriptions live far from the current turn, while Bash is always right there in the tool list.
My current workaround is... not elegant: I inject gortex constraint text explicitly into another harness via a UserPromptSubmit py script, so the reminder lands at the top of each turn. It works but it's definitely not a long-term solution. Would love to hear if you've seen similar patterns or have thoughts on a more principled approach.
@zzet One more thing worth mentioning — another Codex limitation that contributes to this:
Codex GUI doesn't (fully) support workspace/profile switching like other agents does. It's more of a half-baked implementation right now. So as users work across different projects, a growing number of MCP servers and skills accumulate and get injected into every new session.
In this scenario, I've observed that Gortex's tools get buried in the context — forgotten even at the very start of a session, despite having explicit "use Gortex" instructions in both the Codex-level and repo-level AGENTS.md. The agent simply ignores the instructions because the Gortex tools are lost in a sea of other MCP tools and skill entries.
This is actually the original motivation behind #206 — the hooks were an attempt to bring Gortex back to the agent's attention at the point of tool use, not just at session start via AGENTS.md.
@Maple0517
TL;DR;
My gut feeling from the query-log data is that AGENTS.md works well for deliberate sessions but gets forgotten in long-running ones.
That is a very good question. I observed this a lot in the past, and there were multiple iterations on MD files and instruction formulations. As well, every model update brings something new (at some investigation model 'told' it was trained to prefer native tools over any third-party, aiming to provide the user the best experience (it went away after some time). Speaking about a long history, there are many observations: context compaction in different models behaves differently (and it can derive tools), agents archestration (by native coding agents) sometimes inherits a part of context/MD/Tools info, which makes a bad experience (gortex and other tools work in the main flow, while spun agents reset to defaults), and other criteria. It can be 'hacked' by an additional token consumption, which brings up the question of 'when it makes sense and when it makes everything worse)
I recall that some agents (at least Claude Code and Codex) seem to prioritize injected context skills over MCP tool descriptions at discovery time.
The best way is to keep both options (MD and tools description). Below you can see a benchmark result when it is only the tool or the tool + MD. The results kinda assume your assumption is right; however, both impacts heavily to the outcome. However, sometimes agents 'recall' they have a tool, and once an agent sees it as extremely useful, they start prioritising its usage.
when the conversation context gets long, the agent tends to forget about MCP tools — especially deferred ones (tool_search discovery)
So far, I have found only one workable approach to bring the agent back if such happens - hooks. When the cross-validation rate grows, and tools start being penalised, only hooks helped to bring the agent back on track (with hard deny). However, there I found that the tool's response quality helps more than description or MD. Of the tool, the return result - it eventually penalised because the agent always needs to do double work. So, I prioritise now the tools response quality over manipulation with MD or tools description.
Original problem Returning the original problem - hooks usage - I shipped an update for hooks (a few issues addressed, and it should be better than the previous release, but I haven't fully tested it). Please, try the >= v0.59.1 version.
I ran benchmarks, precisely looking at the pain points you mentioned. All runs below are real headless claude -p sessions on the gin corpus (34dac20), model sonnet, gortex v0.58.3-dirty (pre-v0.59.0), each condition mounting the identical graph server, so the only thing that varies is the channel under test. Small-n and single-harness caveats are listed at the end.
- AGENTS.md instructions vs the tool description's
To answer that precisely - I isolated the two channels by mounting gortex through a proxy that rewrites every tool description to a terse one-liner ("Search symbols.", "Find usages.") while keeping the schemas byte-identical, crossed with no-MD vs the directed CLAUDE.md — four arms, 10 navigation tasks:
| descriptions | CLAUDE.md | adoption | first-tool-is-graph | cross-check (distrust) |
|---|---|---|---|---|
| rich | none | 100% | 100% | 10% |
| terse | none | 100% | 100% | 30% |
| rich | directed | 100% | 100% | 0% |
| terse | directed | 100% | 100% | 11% |
On code-related tasks, adoption saturates through every channel — model reaches for the graph first, even with bland one-line descriptions and no MD. In any benchmark, in the first touch, neither description nor MD is the bottleneck on a modern model. For a relatively mid session, I haven't observed degradation, while an additional validation is required to address your concern - I haven't run a very long benchmark session (purely due to cost $$$). I made such measurements based on the session files, and I don't have confidence to confirm degradation yet.
What the channels actually buy is trust, not first touch. The tools description/AGENTS.md can be filled perfectly; however, it can return awful results and following cross-check. And the cross-check rate is crucial, because the model learns fast if it can rely on the tool or if it will always need to double-check results - means the tool eventually penalises. Cross-check rate (the agent re-verifying a graph answer with native grep/read):
- rich descriptions 10% vs terse 30% with no MD — stripping the descriptions tripled second-guessing.
- Adding the directed MD on top of terse descriptions pulls it back to 11%, and rich+MD reaches 0%.
The two channels are partially redundant: each suppresses distrust, and the description alone gets most of the way there.
Note: On skills packaging specifically, I did not measure it cleanly. Headless
claude -pdoes not load user skills (I actively disable them to keep the operator's ambient guidance out of the sandbox), so a skill-vs-description comparison isn't observable in this harness. That one is a real gap that wasn't measured, and it can be measured later. Some harnesses (in theory) can prioritize injected skills over MCP descriptions, which is plausible — for the moment, I just can't put a number on it from headless mode. Overall, it's the point for improvement in the benchmark.
2. Long-context / deferred-tool forgetting
I ran a few conversations with 8 sequential navigation tasks delivered turn-by-turn (--session-id then --resume), in a plain variant and a padded variant that injects a context-inflating filler turn between tasks, under bare-mcp and vendor-default. Per-turn first-tool-is-graph (early half vs late half of the session):
| variant | condition | early-half first-graph | late-half first-graph |
|---|---|---|---|
| padded | bare-mcp | 100% | 100% |
| padded | vendor-default | 100% | 100% |
| plain | bare-mcp | 100% | 100% |
| plain | vendor-default | 100% | 100% |
I measured no decay at this depth. Every task turn in every session opened with a graph tool — flat 100% through turn 8, including padded sessions that opened their final task with ~130k tokens of accumulated conversation context.
Caveat: this bounds the effect; it doesn't refute your observation — your Codex sessions run longer still, carry many more MCP servers' schemas, and a different harness may order/compact context differently. What we can say with numbers: on this harness, conversation length alone (up to ~130k tokens) did not displace the MCP tools from the model's tool choice. I haven't run a longer test with more context explosion. The current observation may be misleading; I need longer sessions to analyse.
@Maple0517 I'd be happy to get your feedback once you've tried the updated hooks
I'd love to discuss the details here or elsewhere if easier.
Let me know if you can join the Discord channel https://discord.gg/ysC2prTGD (I'm periodically available there for real-time conversation).
p.s. I left the issue open until confirmation that the problem was solved.
Adding one more concrete hook-related failure mode I hit, which seems related to the same adapter/guidance surface.
In a Claude Code task, after hook/interception guidance kicked in, the agent ended up running shell commands shaped like:
gortex read_file frontend/src/components/reader/V4IdentityPanel.vue 2>&1
gortex read_file frontend/src/components/reader/V4IdentityPanel.test.ts 2>&1
gortex read_file frontend/src/composables/useV4PanelState.ts 2>&1
All fail with:
Error: unknown command "read_file" for "gortex"
Run 'gortex --help' for usage.
What I verified locally:
gortex --helpdoes not exposeread_fileas a top-level CLI subcommand.CLAUDE.mdexplicitly says the generic CLI escape hatch isgortex call <tool>.- This works:
gortex call read_file --arg path=reader/frontend/src/components/reader/V4IdentityPanel.vue --format text
So the underlying read_file capability is fine; the problem seems to be that a hook / adapter guidance path can effectively steer the agent into treating an MCP tool name as a bare CLI verb.
That makes this feel adjacent to the broader hook-effectiveness issue here: even when the hook is involved, the resulting guidance can still land the agent on an invalid CLI shape instead of either:
- keeping the action in MCP-tool terms, or
- rendering the shell fallback as
gortex call read_file ...
A bit more concrete environment context for this case:
- Claude Code:
2.1.201 - Gortex:
v0.59.1+00aec84 - Gortex build time:
2026-07-05T10:50:48Z - Go:
go1.26.4 - OS / arch:
macOS 26.5.1 (25F80),arm64
Daemon state at the time of verification:
- daemon running normally
- tracked repos included both
gortexand the target reporeader gortex statusshowed thereaderrepo indexed/tracked, so this did not look like a missing-daemon or missing-repo case
That matters because the following succeeded under the same local setup:
gortex call read_file --arg path=reader/frontend/src/components/reader/V4IdentityPanel.vue --format text
So in this environment the failure is specifically the command shape gortex read_file ..., not a general inability to resolve the target file or reach the daemon.
I opened #259 with the narrower reproduction, but this may belong under the umbrella of this issue.
@zzet Thanks — agreed, this sounds like a dedicated issue.
@Maple0517 in the new release (v0.61.0) the issue should be fixed. Please, run gortex install and update hooks.