paperclipai/paperclip · error

Cannot remove the shared managed CLI while other instance se

Error message

Cannot remove the shared managed CLI while other instance services are installed: ${otherDefinitions.join(", ")}. Uninstall those services first.

What it means

Thrown by uninstallCommand when other Paperclip background-service definitions (systemd .service files on Linux, launchd .plist files on macOS) for different instance IDs still exist on disk. The shared managed CLI store is a single payload directory shared across all instances, so removing it would break those other still-installed instance services. The error lists the offending definition file paths so the operator knows exactly what to remove first.

Source

Thrown at cli/src/commands/uninstall.ts:49

  const pattern = platform === "linux"
    ? /^paperclipai(?:-.+)?\.service$/
    : /^ing\.paperclip\.paperclipai(?:\..+)?\.plist$/;
  return fs.readdirSync(directory)
    .filter((name) => name !== currentName && pattern.test(name))
    .map((name) => path.join(directory, name));
}

export async function uninstallCommand(
  dependencies: Partial<UninstallDependencies> = {},
): Promise<void> {
  const instanceId = resolvePaperclipInstanceId();
  const detect = dependencies.detectServiceManager ?? detectServiceManager;
  const platform = dependencies.platform ?? process.platform;
  const userHomeDir = dependencies.userHomeDir ?? os.homedir();
  const detection = await detect({ instanceId, platform });
  const otherDefinitions = otherServiceDefinitions(platform, userHomeDir, instanceId);
  if (otherDefinitions.length > 0) {
    throw new Error(`Cannot remove the shared managed CLI while other instance services are installed: ${otherDefinitions.join(", ")}. Uninstall those services first.`);
  }
  if (!detection.supported && platform === "linux") {
    const definitionPath = path.join(
      userHomeDir,
      ".config",
      "systemd",
      "user",
      systemdServiceName(instanceId),
    );
    if (fs.existsSync(definitionPath)) {
      throw new Error(
        `Cannot verify or remove the background service: ${detection.reason}. Retry when the service manager is available.`,
      );
    }
  }
  if (detection.supported) {
    const status = await detection.manager.status();
    if (status.installed || status.active) await detection.manager.uninstall();

View on GitHub (pinned to 67001ec6eb)

Solutions

  1. Uninstall each remaining instance first via its own `paperclipai uninstall` (run with that instance's PAPERCLIP_HOME/instance env), so otherServiceDefinitions returns empty.
  2. Manually delete the listed service definition files (the paths are in the error message), then re-run `paperclipai uninstall`.
  3. Disable/stop the other services first (`systemctl --user stop <name>` / `launchctl unload <plist>`) before removing their definition files.

Example fix

# before: only one instance uninstalled, others still installed
paperclipai uninstall
# after: uninstall every instance, then the shared CLI store is freed
PAPERCLIP_HOME=/home/u/.paperclip-a paperclipai uninstall
PAPERCLIP_HOME=/home/u/.paperclip-b paperclipai uninstall
Defensive patterns

Strategy: validation

Validate before calling

// Run before uninstallCommand to detect blocking services
import fs from 'node:fs';
import path from 'node:path';
import os from 'node:os';

function listOtherInstanceServices(instanceId: string, platform: NodeJS.Platform = process.platform): string[] {
  const dir = platform === 'linux'
    ? path.join(os.homedir(), '.config', 'systemd', 'user')
    : platform === 'darwin'
      ? path.join(os.homedir(), 'Library', 'LaunchAgents')
      : null;
  if (!dir || !fs.existsSync(dir)) return [];
  const pattern = platform === 'linux' ? /^paperclipai(?:-.+)?\.service$/ : /^ing\.paperclip\.paperclipai(?:\..+)?\.plist$/;
  return fs.readdirSync(dir).filter((n) => pattern.test(n));
}
// if (listOtherInstanceServices(instanceId).length > 0) { /* uninstall each first */ }

Try / catch

try {
  await uninstallCommand();
} catch (error) {
  if (error instanceof Error && error.message.startsWith('Cannot remove the shared managed CLI')) {
    // parse the listed service files, uninstall each instance, then retry
    const files = error.message.match(/\/\S+\.(?:service|plist)/g) ?? [];
    for (const f of files) fs.rmSync(f, { force: true });
    await uninstallCommand();
  } else throw error;
}

Prevention

When it happens

Trigger: Calling `paperclipai uninstall` (uninstallCommand) on a machine that has two or more Paperclip instances registered, where at least one other instance's service file still lives under ~/.config/systemd/user/ (Linux) or ~/Library/LaunchAgents/ (macOS). The otherServiceDefinitions scan finds service files whose names match the paperclipai pattern but differ from the current instance's service name.

Common situations: Running multiple isolated Paperclip instances (different PAPERCLIP_HOME / instance IDs) on one host and uninstalling only one. Leftover service files from a partially-failed prior uninstall or from a manually-registered second instance.

Related errors


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