Skip to content

fix/cursor: inline creds and --env into every Cursor hook - #36

Merged
sibicramesh merged 2 commits into
mainfrom
fix/cursor-inline-hook-flags
Sep 8, 2026
Merged

fix/cursor: inline creds and --env into every Cursor hook#36
sibicramesh merged 2 commits into
mainfrom
fix/cursor-inline-hook-flags

Conversation

@sibicramesh

@sibicramesh sibicramesh commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Why

Cursor hooks other than sessionStart read their credentials from $AGENT_HOOK_ENDOR_* env that endorctl injected through the sessionStart hook's env output. Cursor staff have confirmed two unfixed bugs with that mechanism:

  • env is lost when a conversation is resumed after a Cursor restart or a tab is reopened (forum 157196)
  • env is never inherited by hooks fired inside subagents (forum 155212)

In both cases every later hook ran endorctl with empty flags and Cursor failed open: no audit, no enforcement. The same happened whenever the sessionStart bootstrap exited non-zero.

What

  • render.sh: render the literal --api/--namespace/--api-key/--api-secret flags and the --env behavior settings into every Cursor hook command, as the Codex builder already did. Each hook is now self-contained. Cursor and Codex share the new posix_inline / ps_inline strings.
  • README.md: update the behavior-settings and credential-isolation wording; add a "Self-contained hooks (Cursor)" security note.
  • Regenerate the Cursor examples (macOS and Windows). Only the 11 non-session hooks change; sessionStart is byte-identical.

Verification

  • Rendered every agent and OS with the main script and this one. Claude and Codex output is byte-identical; Cursor differs in exactly 11 lines per target.
  • Decoded the Windows Cursor hooks from base64 to confirm the shape: prelude, $env: lines, inlined endorctl call.
  • Quoting test with a key containing ', a secret containing $ and ", and an --env value with a space and ;. Per-hook command matches the session hook's inline form exactly.
  • Merged origin/main (nonblocking bootstrap, [AI-536] agent-governance: stop the endorctl download from blocking session start #21) and regenerated all 8 examples with the merged generator; tests/run-tests.sh passes 71/71, including the examples-in-sync check.

Follow-ups

  • endorctl's Cursor sessionStart handler can drop its env output once fleets are on this config.
  • ai_governance_demo's build_hooks.py still generates hooks against the old AGENT_HOOK_ENDOR_* contract.

🤖 Generated with Claude Code

Cursor hooks other than sessionStart read their credentials from
$AGENT_HOOK_ENDOR_* env that endorctl injected via the sessionStart
hook's `env` output. Cursor staff have confirmed that env is lost when
a conversation is resumed after a restart and is never inherited by
hooks fired inside subagents, so those sessions ran endorctl with empty
flags and silently failed open (no audit, no enforcement).

Render the literal --api/--namespace/--api-key/--api-secret flags and
the --env behavior settings into every Cursor hook command instead, the
way the Codex builder already does. Each hook is now self-contained.
Both builders share the new posix_inline / ps_inline strings; Codex and
Claude output is byte-identical to before.

Also regenerate examples/codex/requirements.windows.toml, which was
never regenerated after 4a41f77 fixed the missing newline before the
`$in |` line.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Resolve examples/codex/requirements.windows.toml by regenerating all
examples with the merged render.sh; tests/run-tests.sh passes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@sibicramesh
sibicramesh requested a review from dpowley September 8, 2026 20:09
@georgeap70

Copy link
Copy Markdown
Contributor

oh, interesting, did not realize that they had these bugs.
Looks good

@georgeap70 georgeap70 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good

@sibicramesh
sibicramesh merged commit fa71484 into main Sep 8, 2026
9 checks passed
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