Skip to content

fix(hooks): pass additionalContextLimit through for Codex CLI - #2576

Merged
dyoshikawa merged 3 commits into
mainfrom
resolve-issue-2496-slices
Aug 4, 2026
Merged

fix(hooks): pass additionalContextLimit through for Codex CLI#2576
dyoshikawa merged 3 commits into
mainfrom
resolve-issue-2496-slices

Conversation

@dyoshikawa

Copy link
Copy Markdown
Owner

Background

Part of #2496 — two judgment-free slices from that issue. The rest of #2496 stays open: it turns on design decisions (gateway ownership for [agents] / [[skills.config]] / project_doc_* / mcp_oauth_callback_*, and the Codex plugin bundle target).

Slice A — stale comment on the codexcli permissions override

The doc comment on CodexcliPermissionsOverrideSchema (src/types/permissions.ts) said the override is "looseObject (verbatim passthrough) so future top-level Codex config keys can be authored without Rulesync modeling each one". That has not been true since the override gained an allowlist: computeCodexcliOverridePatch (src/features/permissions/codexcli-permissions.ts) emits only the five keys in CODEXCLI_OVERRIDE_KEYS (src/constants/codexcli-paths.ts) and skips anything else with a warning. A reader following the old comment would author a new top-level Codex key and find it silently dropped.

The comment now describes the allowlist, names the five keys and where they live, and explains what looseObject actually buys (an unmodeled key parses and is then reported, rather than failing validation outright) and how to add a key. No behavior change.

Slice B — additionalContextLimit passthrough for Codex CLI

Codex CLI documents a per-handler additionalContextLimit on .codex/hooks.json hooks: the token threshold above which Codex writes the hook's additional context to a file and passes that path instead of the text, defaulting to 2500 (https://learn.chatgpt.com/docs/hooks). Rulesync had no way to express it, so authoring it was impossible and an existing config carrying it lost the field on import.

The shared hooks converter had boolean, string, string-array and group passthrough kinds but no number kind, so this adds numberPassthroughFields mirroring booleanPassthroughFields:

  • src/features/hooks/tool-hooks-converter.ts — the config field plus emitNumberPassthroughFields / importNumberPassthroughFields. The guard is Number.isFinite, so NaN / Infinity (which JSON cannot represent) and a numeric string are both ignored in either direction rather than leaking into a config Codex would reject.
  • src/types/hooks.ts — canonical additionalContextLimit: z.optional(z.number()).
  • src/features/hooks/codexcli-hooks.ts — registered in CODEXCLI_CONVERTER_CONFIG under the same name on both sides.
  • docs/reference/file-formats.md — documented alongside the other per-hook fields.

No hooks JSON schema regeneration was needed: pnpm run generate:schema emits config / mcp / permissions schemas only, and hooks.jsonc has no published schema. Running it produced no diff.

Testing

  • Added Codex CLI hook tests for the export and import directions, including a non-numeric additionalContextLimit being ignored on import.
  • npx vitest run --config vitest.e2e.config.ts src/e2e/e2e-hooks.spec.ts — 75 passed.
  • pnpm cicheck — all green.

🤖 Generated with Claude Code

@dyoshikawa
dyoshikawa merged commit ccdca56 into main Aug 4, 2026
9 checks passed
@dyoshikawa
dyoshikawa deleted the resolve-issue-2496-slices branch August 4, 2026 05:31
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