paperclipai/paperclip · error · Error

Current directory is not inside a git repository.

Error message

Current directory is not inside a git repository.

What it means

Thrown by resolvePrimaryGitRepoRoot when detectGitWorkspaceInfo returns null, meaning none of the git rev-parse probes (show-toplevel, git-common-dir, git-dir) succeeded. The worktree repair/init flow requires a git repository to anchor the worktree under .paperclip/worktrees.

Source

Thrown at cli/src/commands/worktree.ts:649

    execFileSync("git", ["check-ref-format", "--branch", value], {
      cwd,
      stdio: ["ignore", "pipe", "pipe"],
    });
  } catch (error) {
    throw new Error(`Invalid branch name "${branchName}": ${extractExecSyncErrorMessage(error) ?? String(error)}`);
  }
  return value;
}

function isPrimaryGitWorktree(cwd: string): boolean {
  const workspace = detectGitWorkspaceInfo(cwd);
  return Boolean(workspace && workspace.gitDir === workspace.commonDir);
}

function resolvePrimaryGitRepoRoot(cwd: string): string {
  const workspace = detectGitWorkspaceInfo(cwd);
  if (!workspace) {
    throw new Error("Current directory is not inside a git repository.");
  }
  if (workspace.gitDir === workspace.commonDir) {
    return workspace.root;
  }
  return path.resolve(workspace.commonDir, "..");
}

function resolveRepairWorktreeDirName(branchName: string): string {
  const normalized = branchName.trim()
    .replace(/[^A-Za-z0-9._-]+/g, "-")
    .replace(/-+/g, "-")
    .replace(/^[-._]+|[-._]+$/g, "");
  return normalized || "worktree";
}

function detectGitWorkspaceInfo(cwd: string): GitWorkspaceInfo | null {
  try {
    const root = execFileSync("git", ["rev-parse", "--show-toplevel"], {

View on GitHub (pinned to 67001ec6eb)

Solutions

  1. cd into the cloned Paperclip git repository before running the worktree command.
  2. Ensure the git binary is installed and on PATH (git --version works).
  3. If you intentionally have no repo, initialize one with git init first, or use a flow that does not require git.
  4. Check filesystem permissions allow reading the .git directory.

Example fix

// before: run from /tmp
// after
git clone <repo> paperclip && cd paperclip && paperclipai worktree ...
Defensive patterns

Strategy: validation

Validate before calling

function isInGitRepo(cwd: string): boolean {
  try {
    execFileSync('git', ['rev-parse', '--git-dir'], { cwd, stdio: 'ignore' });
    return true;
  } catch { return false; }
}

Prevention

When it happens

Trigger: Running paperclipai worktree commands from a directory that is not inside any git worktree; git is not installed or not on PATH (rev-parse throws); the directory is inside a bare repo with no working tree; filesystem permissions block git from reading .git.

Common situations: Running the CLI in /tmp or a non-repo scratch dir; fresh clone where git binary is missing in the container; running inside a bare repository; misconfigured PATH in CI.

Related errors


AI-assisted analysis of paperclipai/paperclip@67001ec6eb (2026-08-12). Data as JSON: /api/errors/ebe5de942955d94a. Report an issue: GitHub.