Skip to content

feat(codex): install SessionStart graph orientation hook#207

Merged
zzet merged 2 commits into
zzet:mainfrom
blankanswer:feat/codex-sessionstart-hook
Jun 30, 2026
Merged

feat(codex): install SessionStart graph orientation hook#207
zzet merged 2 commits into
zzet:mainfrom
blankanswer:feat/codex-sessionstart-hook

Conversation

@blankanswer

@blankanswer blankanswer commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds minimal Codex hook support by installing a SessionStart orientation hook into ~/.codex/config.toml.

When Codex starts or resumes a session, the hook prints a short reminder to prefer Gortex graph tools before large direct file reads. This mirrors the existing agent onboarding intent without changing MCP
behavior or adding tool interception.

This intentionally keeps the first Codex hook PR small: it only covers SessionStart, not PreToolUse / PostToolUse.

Changes

  • Install an idempotent Codex SessionStart hook when hooks are enabled
  • Match Codex start sources with startup|resume|clear|compact
  • Preserve existing Codex hooks and existing mcp_servers.gortex config
  • Respect --no-hooks / InstallHooks=false for Codex hook installation
  • Add POSIX and Windows hook commands
  • Update install/init copy and docs for supported agent hooks
  • Add focused tests for fresh install, repeated install, existing config merge, and no-hooks behavior

Out of scope:

  • Codex PreToolUse / PostToolUse hooks
  • Dynamic hook handling or context injection
  • Changes to Claude Code hook behavior
  • Changes to MCP tools, indexing, daemon, LSP, resolver, or graph storage
  • Expanding --hooks-only beyond its current Claude Code behavior

Testing

  • go test ./internal/agents/...
  • go test ./cmd/gortex/...
  • go test -race ./internal/agents/codex ./internal/agents
  • git diff --check
  • go test -run '^$' -bench . ./internal/agents/...
  • New tests added for new functionality
  • All tests pass (go test -race ./...)
  • Benchmarks run if performance-relevant

Benchmarks are not performance-relevant for this config-writing change; the scoped benchmark build passed and there are no benchmark cases in the changed agent packages.

Checklist

  • Code follows existing patterns in the codebase
  • No unnecessary abstractions added
  • Language extractor includes Meta["methods"] for interfaces (if applicable)
  • Methods have EdgeMemberOf edges to their containing type (if applicable)

Related to #206

Add an idempotent Codex SessionStart hook upsert for ~/.codex/config.toml while preserving existing hooks and MCP config.

Respect no-hooks for Codex hook installation, document the supported hook behavior, and cover fresh install, repeated install, merge, and no-hooks cases with focused tests.
Comment thread internal/agents/codex/adapter.go Outdated
const DocsURL = "https://developers.openai.com/codex/mcp"

const codexSessionStartMatcher = "startup|resume|clear|compact"
const codexSessionStartMessage = "[Gortex] Prefer Gortex graph tools (search_symbols, get_callers, get_file_summary) before Read/Grep/Glob over large files."

@zzet zzet Jun 30, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to get feedback from Codex users, but intuitively:

  1. I see zero value for duplication Gortex with [Gortex]
  2. I don't thinkbefore Read/Grep/Glob over large files. will be a clear instruction:
  • Why before?
  • Why only large files?
Suggested change
const codexSessionStartMessage = "[Gortex] Prefer Gortex graph tools (search_symbols, get_callers, get_file_summary) before Read/Grep/Glob over large files."
const codexSessionStartMessage = "IMPORTANT: Prefer Gortex graph tools (search_symbols, get_callers, get_file_summary) over Read/Grep/Glob."

One more point: tools like edit_file can be very useful to mention, too. Overall, the initial message makes sense to test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good point. I agree the original wording was too fuzzy: “before” made it sound like an ordering rule, and “large files” narrowed the guidance unnecessarily; I updated the message to remove the duplicate label, use “over” instead of “before”, drop the large-file qualifier, and mention edit_file as well: IMPORTANT: Prefer Gortex MCP tools (search_symbols, get_callers, get_file_summary, edit_file) over Read/Grep/Glob/Edit. This keeps the PR scoped to the lightweight SessionStart orientation hook; PreToolUse/PostToolUse behavior remains out of scope for a follow-up PR~

@zzet zzet merged commit 0aa36d3 into zzet:main Jun 30, 2026
11 checks passed
@zzet

zzet commented Jun 30, 2026

Copy link
Copy Markdown
Owner

@blankanswer merged. Thank you for contribution. Follow up question if you're planning to cover other hooks, are you?

@blankanswer

Copy link
Copy Markdown
Contributor Author

@blankanswer merged. Thank you for contribution. Follow up question if you're planning to cover other hooks, are you?已合并。感谢您的贡献。如果您打算涵盖其他钩子函数,请告知我们。

Yep, I’m happy to continue working on the remaining Codex hook surface, but I’d prefer to split it into small follow-up PRs rather than trying to reach full Claude Code parity in one large change.

My next step will be to validate the Codex PreToolUse and PostToolUse input/output contract against the current Codex CLI behavior. After that, I plan to open a lightweight PR for PreToolUse only, focused on soft nudging / additional context rather than deny or enforcement behavior. I’ll keep PostToolUse enrichment, PreCompact/Stop-style lifecycle handling if Codex supports equivalent events, and any broader hook dispatcher work as separate follow-up PRs~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants