Skip to content

Bug: untracked files missing from code review when agent CWD is a subdirectory #449

Closed

Description

@blimmer

Description

When running /plannotator-review, untracked (new) files are missing from the file tree. Only untracked files that happen to be inside the agent's current working directory are shown, and with incorrect relative paths. Tracked/modified files display correctly.

Steps to reproduce

  1. In a monorepo, have the agent cd into a subdirectory (e.g., packages/foo/)
  2. Create untracked files both inside and outside that subdirectory
  3. Modify some tracked files
  4. Run /plannotator-review

Expected: All untracked files appear in the review with repository-root-relative paths.
Actual: Only untracked files under the agent's CWD appear, with CWD-relative paths (e.g., lib/Bar.ts instead of packages/foo/lib/Bar.ts). Untracked files in other directories are missing entirely.

Workaround

Prompt the agent to change back to the repository root before running the review:

Change your cwd back to the root of the git repo.

Root cause

In packages/shared/review-core.ts, getUntrackedFileDiffs() passes the process CWD through to git ls-files --others --exclude-standard. Unlike git diff HEAD (which always covers the full repo with root-relative paths regardless of CWD), git ls-files scopes to the CWD subtree and returns CWD-relative paths.

When the hook process inherits a CWD that is a subdirectory of the repo, git ls-files only discovers untracked files in that subtree, and the resulting diff headers use short CWD-relative paths that don't match the root-relative paths from the tracked diff.

Suggested fix

Resolve the repo root before running git ls-files and the per-file git diff --no-index commands:

async function getUntrackedFileDiffs(runtime, srcPrefix, dstPrefix, cwd) {
  // Resolve repo root so ls-files covers the entire repo
  const toplevel = await runtime.runGit(["rev-parse", "--show-toplevel"], { cwd });
  const rootCwd = toplevel.exitCode === 0 ? toplevel.stdout.trim() : cwd;

  const lsResult = await runtime.runGit(
    ["ls-files", "--others", "--exclude-standard"],
    { cwd: rootCwd },  // was { cwd }
  );

  // ... same file filtering logic ...

  const diffs = await Promise.all(
    files.map(file =>
      runtime.runGit(
        ["diff", "--no-ext-diff", "--no-index", ...prefixes, "/dev/null", file],
        { cwd: rootCwd },  // was { cwd }
      ).then(r => r.stdout)
    ),
  );

  return diffs.join("");
}

Environment

  • Plannotator v0.16.2
  • macOS, Claude Code plugin
  • Reproducible whenever the agent changes its working directory to a subdirectory before review is invoked

Activity

  1. added a commit that references this issue on Mar 31, 2026
    14179d6
  2. added 2 commits that reference this issue on Mar 31, 2026
    cce877d
    1b5a251
  3. backnotprop commented on Apr 1, 2026

    @backnotprop
    Owner

    released in 0.16.3

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions