COR-5419 Populate Cwd from workspace_roots[0] for Cursor handlers#10
Merged
Conversation
Cursor launches hook binaries from its config directory (~/.cursor) rather than the project root, so handlers that fall back to os.Getwd() report a misleading path. Every Cursor hook payload includes a workspace_roots array with the actual project directories, so use that to populate ctx.Cwd for stop, before-shell (as a fallback), before-mcp, after-file-edit, and prompt-submit handlers. Adds a Cwd field to PromptContext so the Cursor prompt path can carry the workspace root the same way the other unified contexts already do. This unblocks the hookshot consumer in CorridorSecurity/corridor PR #4216, which can now drop the os.Getwd() fallback once it picks up this hookshot version. Made-with: Cursor
There was a problem hiding this comment.
Summary: This PR propagates accurate working directory (Cwd) values from Cursor's workspace_roots into multiple contexts and adds a helper; it introduces no command execution, file I/O, or network calls.
Risk: Low risk. The changes only pass contextual strings to handlers and improve the basis for path validation, with no new attack surface or exploitable paths identified.
Recommendations:
- When handlers use ctx.Cwd for path checks, normalize and bound paths with filepath.Clean and filepath.Rel to the intended project root, treating Cwd as untrusted input.
jake-corridor
approved these changes
Apr 27, 2026
tanuj-corridor
approved these changes
Apr 27, 2026
Covers the cursorWorkspaceRoot helper (nil/empty/single/multiple) and each unified Cursor handler that now populates ctx.Cwd from workspace_roots[0]: stop, before-shell (input.Cwd preferred when set, fallback otherwise), before-mcp, after-file-edit, and before-submit-prompt. Also pins behavior when workspace_roots is empty. Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Populate
ctx.Cwdfor every unified Cursor handler frominput.WorkspaceRoots[0], and add aCwdfield toPromptContextso the Cursor prompt path can carry the workspace root the same way the other unified contexts already do.Cursor launches hook binaries from its config directory (
~/.cursor) rather than the project root, so consumers that fall back toos.Getwd()end up reporting a misleading path. Every Cursor hook payload already includes aworkspace_rootsarray with the actual project directories, so we just thread it through.Changes in
unified.go:StopContext—cursor-stopnow setsCwdfromworkspace_roots[0].OnBeforeExecution—cursor-before-shellfalls back toworkspace_roots[0]wheninput.Cwdis empty;cursor-before-mcppopulatesCwdfromworkspace_roots[0].OnAfterFileEdit—cursor-after-file-editpopulatesCwdfromworkspace_roots[0].PromptContextgains aCwdfield;cursor-before-submit-promptpopulates it fromworkspace_roots[0].cursorWorkspaceRoot([]string) stringhelper.Motivation
Unblocks the consumer-side fix in
CorridorSecurity/corridor#4216, which lands a workaround that readsRawCursor.WorkspaceRootsdirectly. Once this hookshot version is picked up, the consumer can drop that workaround and rely onctx.Cwdend-to-end on every Cursor handler.Test plan
go build ./...cleango vet ./...cleango test ./...— all existing tests passcorridorand verify Directory Matches dashboard no longer shows~/.cursorrowsMade with Cursor