{"record":{"id":"be6e30d60cb4839c","repo":"paperclipai/paperclip","slug":"refusing-to-replace-existing-non-managed-command","errorCode":null,"errorMessage":"Refusing to replace existing non-managed command ${paths.shimPath}.","messagePattern":"Refusing to replace existing non-managed command (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/src/install-store.ts","lineNumber":370,"sourceCode":"  const homeDir = path.dirname(path.dirname(path.dirname(paths.shimPath)));\n  for (const directoryPath of [homeDir, path.join(homeDir, \".local\"), path.dirname(paths.shimPath)]) {\n    if (!fs.existsSync(directoryPath)) continue;\n    const directoryStat = fs.lstatSync(directoryPath);\n    if (!directoryStat.isDirectory() || directoryStat.isSymbolicLink()) {\n      throw new Error(`Refusing to use unsafe shim directory ${directoryPath}.`);\n    }\n    assertOwnedByCurrentUser(directoryStat, directoryPath);\n  }\n  try {\n    const stat = fs.lstatSync(paths.shimPath);\n    if (!stat.isFile() || stat.isSymbolicLink()) {\n      throw new Error(`Refusing to replace non-regular shim ${paths.shimPath}.`);\n    }\n    assertOwnedByCurrentUser(stat, paths.shimPath);\n    if (stat.nlink > 1) throw new Error(`Refusing to replace multiply linked shim ${paths.shimPath}.`);\n    const existing = fs.readFileSync(paths.shimPath, \"utf8\");\n    if (!isManagedShimContents(existing)) {\n      throw new Error(`Refusing to replace existing non-managed command ${paths.shimPath}.`);\n    }\n  } catch (error) {\n    if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n  }\n}\n\nfunction shellQuote(value: string): string {\n  return `'${value.replace(/'/g, `'\"'\"'`)}'`;\n}\n\nfunction isManagedShimContents(contents: string): boolean {\n  const lines = contents.split(\"\\n\");\n  // Accept the original pinned-runtime shim so upgrades can replace it.\n  const withRuntimePath = lines.length === 6;\n  const execIndex = withRuntimePath ? 4 : 3;\n  return (\n    (lines.length === 5 || withRuntimePath) &&\n    lines[0] === \"#!/bin/sh\" &&","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/cli/src/install-store.ts#L352-L388","documentation":"The shim path is occupied by a file that does not contain the managed marker content, i.e. some other tool's binary; the guard refuses to clobber non-managed commands.","triggerScenarios":"Thrown at cli/src/install-store.ts:370 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Rename or remove the existing non-managed command at ${paths.shimPath}, then retry.","Choose a different shim name or directory."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}