Repository navigation
fix(plan): open docs linked beside the plan file - #1620
Merged
Merged
Conversation
Claude Code's ExitPlanMode input carries planFilePath under ~/.claude/plans/, outside the review root, so a relative link to a sibling document returned 404. The plan server now trusts that path when the file holds the plan under review, and /api/doc serves the documents the plan names from its directory. The rest of the directory stays unreachable. Closes backnotprop#1443
planNamesPath matched the requested path as a substring of the plan text, so a link to evidence.md unlocked e.md and [[notes-extended]] unlocked notes.md, reaching other files in ~/.claude/plans/. The plan directory now serves only paths equal to one of the plan's link targets (markdown links, wiki links, HTML href), normalized the same way on both sides (no fragment or query, percent-decoded, ./ collapsed).
…irectory The client sends the plan directory as base on every open. When that directory sits inside the project it was trusted for root resolution, so HTML links resolved only against it and lost the project-root fallback. The plan-directory base now feeds only the plan-linked lookup; root resolution runs without a base, as before. Documents that a linked file beside the plan shadows a project doc of the same name.
resolvePlanLinkedDoc matched the normalized key but joined the raw request onto the plan directory, so a ?/.. or #/.. suffix after a linked name (linked.md?/../other-plan.md) collapsed to a sibling the plan never linked. Every check and the path join now read the normalized key, which also makes a percent-encoded link (my%20doc.md) open the decoded file. Links written inside fenced code or code spans no longer count as targets.
The fence-stripping regex backtracked quadratically on a long run of backticks or tildes (50k chars took ~0.9s), as did the wiki-link pattern on a run of [[ openers, and targets were recomputed on every plan-directory /api/doc request, blocking the event loop. Code is now stripped by a line scan, the wiki and href patterns stop at a newline or the next opener, and readPlanFile stores the targets on PlanFile.
Owner
|
Thanks @bendrucker, this was a good fix and a real gap for Claude Code users, whose plans live in ~/.claude/plans. We pushed a few commits on top before merging:
It'll go out in the next release. |
1 task
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.
A plan that links a document beside it, like
[evidence](foo-evidence.md), returned 404 when clicked in plan review. The link resolved against the working directory, but Claude Code writes the plan under~/.claude/plans/. Closes #1443Implementation
The hook now forwards
planFilePathfrom Claude Code'sExitPlanModeinput. The plan server trusts it only when the file's contents match the plan under review, because the path is model-generated tool input./api/planthen advertises the plan's directory, and the client uses it as the base for linked-doc opens./api/docserves a document from that directory only when the plan's text names the requested relative path, and only when the file stays inside the directory after symlink resolution. The directory never becomes an allowed root, so other plans in~/.claude/plans/stay unreachable. A name that doesn't resolve there falls through to the existing root resolution, so plans that link project docs relative to the working directory behave as before. Wikilinks count as namingname.md.The name check is a substring match on the plan text, so a plain mention of a sibling filename counts the same as a link. That doesn't grant anything extra. A plan that can mention a file can also link it, and the human sees either one in the plan under review.
Only the Claude Code hook passes a plan path. Pi's plan file sits under the project root, where links already resolve. OpenCode's backing file is an internal copy in the data directory, so it has no siblings to link.
Testing
Added tests covering:
../escapes, and symlink escapesVerified end to end by piping a
PermissionRequestevent withplanFilePathinto the hook and clicking each link in a browser:The recording shows the three clicks:
plan-linked-docs.mp4
Follow Up
Linked documents could be shown in the sidebar as well. I was going to try to tackle that as a follow-up pull request, but I'm happy to work on incorporating it here too.