Skip to content

File viewer: find relative paths in an agent's scratch folder outside the pane's folder #803

Closed

Description

@marcobox

Problem

Agents sometimes write files outside the pane's working directory and then refer to them by a path relative to that place. Claude Code keeps a per-session scratchpad at /tmp/claude-<uid>/<project-slug>/<session-id>/scratchpad/ and says things like "the draft is in scratchpad/upstream-pr.md". Opening that link requests /api/fs/file?path=scratchpad%2Fupstream-pr.md&pane_id=…. locateFile resolves it against the pane's cwd, and filesNamed only searches under the cwd, so the viewer answers not_found even though the server can read the file.

Related to #434 / #730, which made SendUserFile paths openable. Those are absolute, so they already work. This is the relative form agents use in prose.

Proposal

An opt-in list of extra roots, tried only after the pane's folder found nothing:

  • HERDR_WEB_FILE_ROOTS: :-separated absolute folder globs.
  • {cwd-slug} in an entry is the pane's cwd with every non-alphanumeric character replaced by - (how Claude Code names <project-slug>), e.g. /tmp/claude-1000/{cwd-slug}/*.
  • One match opens directly. Several come back as the existing ambiguous_path candidates, newest first. Unset means today's behaviour exactly.
  • Globbing starts from the longest literal prefix of each entry, never from /.

I'm running this as a ~40-line patch to server/file-view.ts (a new filesInRoots(), called at the end of locateFile) with a test in server/file-view.test.ts, and I'm happy to open it as a PR if the shape works for you. A built-in default for Claude Code's layout could be a follow-up, but opt-in avoids reading other users' /tmp layouts by surprise.

Where

Other (file viewer)

Workarounds and alternatives

Pasting the absolute path into the viewer works, as does asking the agent to always print absolute paths, but the links agents print in chat stay broken.

Activity

  1. devswha commented on Oct 14, 2026

    @devswha
    Owner

    Thanks for the clear write-up. Opening #1134 to fix this with a built-in lookup instead of HERDR_WEB_FILE_ROOTS:

    • When a relative path is not under the pane's folder and the pane runs Claude Code, the server looks in that session's temp folder, <tmp>/claude-<uid>/<project>/<session>/.
    • <project> and <session> come from the transcript the chat already resolves for the pane. That means only the live session's folder is read, so scratchpad/draft.md does not turn into a choice between every past session of the same cwd, which a {cwd-slug}/* glob would give.
    • No setting is needed, and only a claude-<uid> folder owned by the server's user is read.

    An opt-in root list for other agents' layouts could still follow if one turns up. Feedback on #1134 is welcome.

  2. devswha commented on Oct 16, 2026

    @devswha
    Owner

    Resolved in the latest release, v0.4.11 (shipped since v0.4.9): a relative link such as scratchpad/draft.md that is not under the pane's folder now opens from the live Claude Code session's temp folder, with no setting needed (#1134). Closing; an opt-in root list for other agents' layouts can be a new issue if one is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions