{"record":{"id":"687184dcd8bbf84e","repo":"google-gemini/gemini-cli","slug":"cannot-install-extension-newextensionname-bec","errorCode":null,"errorMessage":"Cannot install extension \"${newExtensionName}\" because a directory with that name already exists. Please remove it manually.","messagePattern":"Cannot install extension \"(.+?)\" because a directory with that name already exists\\. Please remove it manually\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/config/extension-manager.ts","lineNumber":362,"sourceCode":"          newExtensionConfig,\n          requestConsentOverride ?? this.requestConsent,\n          newHasHooks,\n          previousExtensionConfig,\n          previousHasHooks,\n          newSkills,\n          previousSkills,\n          isMigrating,\n        );\n        const extensionId = getExtensionId(newExtensionConfig, installMetadata);\n        const destinationPath = new ExtensionStorage(\n          newExtensionName,\n        ).getExtensionDir();\n\n        if (\n          (!isUpdate || newExtensionName !== previousName) &&\n          fs.existsSync(destinationPath)\n        ) {\n          throw new Error(\n            `Cannot install extension \"${newExtensionName}\" because a directory with that name already exists. Please remove it manually.`,\n          );\n        }\n\n        let previousSettings: Record<string, string> | undefined;\n        let wasEnabledGlobally = false;\n        let wasEnabledWorkspace = false;\n        if (isUpdate && previousExtensionConfig) {\n          const previousExtensionId = previous?.installMetadata\n            ? getExtensionId(previousExtensionConfig, previous.installMetadata)\n            : extensionId;\n          previousSettings = await getEnvContents(\n            previousExtensionConfig,\n            previousExtensionId,\n            this.workspaceDir,\n          );\n          if (newExtensionName !== previousName) {\n            wasEnabledGlobally = this.extensionEnablementManager.isEnabled(","sourceCodeStart":344,"sourceCodeEnd":380,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/cli/src/config/extension-manager.ts#L344-L380","documentation":"Thrown when the computed destination directory (`ExtensionStorage(name).getExtensionDir()`) already exists on disk for a fresh install, or for an update that renames the extension. The manager will not overwrite an existing directory because it cannot safely attribute it.","triggerScenarios":"A previous install/uninstall cycle left the directory behind; the user manually created a directory with the same name; a prior copy step was interrupted leaving a partial directory.","commonSituations":"Interrupted installs; partial uninstalls; manual `mkdir`/`cp` into the extensions dir; switching machines where half a directory was synced.","solutions":["Remove the destination directory manually and retry the install.","Run `gemini extensions uninstall <name>` to let the manager clean it up.","Check `~/.gemini/extensions/<name>` (and the workspace extensions dir) for stale folders."],"exampleFix":"// before\n$ gemini extensions install owner/repo  # dir exists\n// after\n$ rm -rf ~/.gemini/extensions/my-ext && gemini extensions install owner/repo","handlingStrategy":"validation","validationCode":"const dest = new ExtensionStorage(newExtensionName).getExtensionDir();\nif ((!isUpdate || newExtensionName !== previousName) && fs.existsSync(dest)) {\n  throw new Error(`Destination ${dest} already exists; remove it manually.`);\n}","typeGuard":"function destinationIsClear(dest: string): boolean {\n  return !fs.existsSync(dest);\n}","tryCatchPattern":null,"preventionTips":["Run `gemini extensions uninstall` rather than `rm -rf` to keep state consistent.","Before install, check the destination path and clean stale dirs.","Treat leftover directories after a failed install as a defect to clean up."],"tags":["extensions","filesystem","conflict","install"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}