google-gemini/gemini-cli · error

Path already exists: ${path}

Error message

Path already exists: ${path}

What it means

createDirectory() in the 'gemini extensions new' command checks if the target path already exists (via fs.access) before creating it. If the path exists, it throws to prevent silently overwriting an existing directory or extension. The check runs before mkdir.

Source

Thrown at packages/cli/src/commands/extensions/new.ts:35

}

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const EXAMPLES_PATH = join(__dirname, 'examples');

async function pathExists(path: string) {
  try {
    await access(path);
    return true;
  } catch {
    return false;
  }
}

async function createDirectory(path: string) {
  if (await pathExists(path)) {
    throw new Error(`Path already exists: ${path}`);
  }
  await mkdir(path, { recursive: true });
}

async function copyDirectory(template: string, path: string) {
  await createDirectory(path);

  const examplePath = join(EXAMPLES_PATH, template);
  const entries = await readdir(examplePath, { withFileTypes: true });
  for (const entry of entries) {
    const srcPath = join(examplePath, entry.name);
    const destPath = join(path, entry.name);
    await cp(srcPath, destPath, { recursive: true });
  }
}

async function handleNew(args: NewArgs) {
  if (args.template) {

View on GitHub (pinned to 5024443c72)

Solutions

  1. Choose a different path that doesn't exist yet.
  2. Remove or rename the existing directory first: rm -rf ./my-ext.
  3. Verify the intended path is available before running.

Example fix

// before
gemini extensions new ./my-ext  // ./my-ext already exists

// after
rm -rf ./my-ext && gemini extensions new ./my-ext
Defensive patterns

Strategy: validation

Validate before calling

import { access } from 'node:fs/promises';

async function pathIsFree(path: string): Promise<boolean> {
  try {
    await access(path);
    return false; // exists
  } catch {
    return true; // free
  }
}

// Before running new:
if (!(await pathIsFree(targetPath))) {
  throw new Error(`Remove or rename existing path: ${targetPath}`);
}

Prevention

When it happens

Trigger: Running 'gemini extensions new ./my-ext' when ./my-ext already exists on disk. The pathExists() helper uses access() which succeeds for any existing filesystem entry.

Common situations: Re-running the new command after a previous attempt; typo causing path collision with an existing extension; leftover directory from a failed or abandoned creation.

Related errors


AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12). Data as JSON: /api/errors/18b3504ffe252cc5. Report an issue: GitHub.