google-gemini/gemini-cli · error · Error

Could not install extension because the current workspace at

Error message

Could not install extension because the current workspace at ${this.workspaceDir} is not trusted.

What it means

Thrown when the workspace is not in the trusted-folders list and the user declines the interactive consent prompt that would have trusted it. Folder trust is a precondition for installing extensions because extensions can execute hooks and inject tools.

Source

Thrown at packages/cli/src/config/extension-manager.ts:231

    const isUpdate = !!previousExtensionConfig;
    let newExtensionConfig: ExtensionConfig | null = null;
    let localSourcePath: string | undefined;
    let extension: GeminiCLIExtension | null;
    try {
      if (!isWorkspaceTrusted(this.settings).isTrusted) {
        if (
          await this.requestConsent(
            `The current workspace at "${this.workspaceDir}" is not trusted. Do you want to trust this workspace to install extensions?`,
          )
        ) {
          const trustedFolders = loadTrustedFolders();
          await trustedFolders.setValue(
            this.workspaceDir,
            TrustLevel.TRUST_FOLDER,
          );
        } else {
          throw new Error(
            `Could not install extension because the current workspace at ${this.workspaceDir} is not trusted.`,
          );
        }
      }
      const extensionsDir = ExtensionStorage.getUserExtensionsDir();
      await fs.promises.mkdir(extensionsDir, { recursive: true });

      if (installMetadata.type === 'local' || installMetadata.type === 'link') {
        installMetadata.source = path.isAbsolute(installMetadata.source)
          ? installMetadata.source
          : path.resolve(this.workspaceDir, installMetadata.source);
      }

      let tempDir: string | undefined;

      if (
        installMetadata.type === 'git' ||
        installMetadata.type === 'github-release'

View on GitHub (pinned to 5024443c72)

Solutions

  1. Pre-trust the folder: run Gemini once interactively and accept, or call the trusted-foldors API to add it.
  2. Re-run the install and answer Yes at the consent prompt.
  3. In non-interactive contexts, set `GEMINI_CLI_TRUST_WORKSPACE=true` or pass `--skip-trust` if the policy allows it.

Example fix

// before
$ gemini extensions install ./ext   # decline prompt
// after
$ gemini   # accept trust prompt once, then retry install
Defensive patterns

Strategy: validation

Validate before calling

const { isTrusted } = isWorkspaceTrusted(settings);
if (!isTrusted) {
  const ok = await requestConsent('Trust this workspace for extension install?');
  if (!ok) throw new Error('Cannot install: workspace not trusted.');
}

Type guard

function workspaceIsTrusted(settings: unknown): boolean {
  return isWorkspaceTrusted(settings as MergedSettings).isTrusted;
}

Prevention

When it happens

Trigger: Running an extension install from a freshly-cloned or unfamiliar directory, seeing the consent prompt, and selecting No / Escape; a non-interactive context where `requestConsent` returns false automatically.

Common situations: First-time use of a new repo; CI runners where no TTY is attached and consent defaults to decline; switching workspace roots; corporate policy that requires explicit trust per folder.

Related errors


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