claude-code - 💡(How to fix) Fix File preview links break when session runs inside a worktree [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56425Fetched 2026-05-06 06:28:23
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
labeled ×3closed ×1commented ×1

When Claude Code starts a session in a worktree (e.g. .claude/worktrees/<name>), markdown file links in responses resolve relative to the worktree root — not the main repo. If Claude writes files to the main repo using absolute paths (which it does by default), clicking those links in the preview panel fails with:

"The file could not be read. It may have been deleted or moved."

The files exist and are accessible via the file tree, but one-click preview from a response link does not work.

Root Cause

When Claude Code starts a session in a worktree (e.g. .claude/worktrees/<name>), markdown file links in responses resolve relative to the worktree root — not the main repo. If Claude writes files to the main repo using absolute paths (which it does by default), clicking those links in the preview panel fails with:

"The file could not be read. It may have been deleted or moved."

The files exist and are accessible via the file tree, but one-click preview from a response link does not work.

Fix Action

Fix / Workaround

Workarounds

RAW_BUFFERClick to expand / collapse

Summary

When Claude Code starts a session in a worktree (e.g. .claude/worktrees/<name>), markdown file links in responses resolve relative to the worktree root — not the main repo. If Claude writes files to the main repo using absolute paths (which it does by default), clicking those links in the preview panel fails with:

"The file could not be read. It may have been deleted or moved."

The files exist and are accessible via the file tree, but one-click preview from a response link does not work.

Steps to Reproduce

  1. Claude Code starts a session inside a worktree (e.g. auto-created by a previous session)
  2. Claude writes files to the main repo using absolute paths
  3. Claude includes a relative markdown link to that file in its response
  4. User clicks the link in the preview panel → fails

Expected Behavior

File links in Claude responses should resolve correctly regardless of whether the session is running in a worktree — or the preview panel should detect that the file is outside the worktree and offer to open it from its absolute path.

Workarounds

  • Navigate to the file manually via the file tree
  • Run the session from the main repo instead of a worktree
  • Remove stale worktrees so the session returns to the main repo root

Context

This is particularly disruptive for knowledge-management or document-heavy workflows where Claude frequently links to files it has written or updated. The user has no obvious signal that the session is running in a worktree, making the broken links confusing.

extent analysis

TL;DR

The issue can be mitigated by running the session from the main repo instead of a worktree or by using absolute paths in markdown links.

Guidance

  • Verify that the session is indeed running in a worktree by checking the current working directory.
  • Consider modifying Claude Code to use relative paths based on the main repo root when generating markdown links.
  • If possible, update the preview panel to detect when a file is outside the worktree and offer to open it from its absolute path.
  • Remove stale worktrees to ensure the session returns to the main repo root.

Example

No code snippet is provided as the issue does not specify the programming language or implementation details.

Notes

The provided workarounds may not be feasible in all scenarios, especially for knowledge-management or document-heavy workflows. A more robust solution would require modifications to Claude Code or the preview panel.

Recommendation

Apply workaround: Run the session from the main repo instead of a worktree. This is a simple and effective way to avoid the issue, although it may not be suitable for all use cases.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix File preview links break when session runs inside a worktree [1 comments, 2 participants]