{"record":{"id":"3f3f2a81c8fe7aaa","repo":"coder/code-server","slug":"no-opened-code-server-instances-found-to-handle","errorCode":null,"errorMessage":"No opened code-server instances found to handle ${paths[0]}","messagePattern":"No opened code-server instances found to handle (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/node/cli.ts","lineNumber":870,"sourceCode":"    logger.debug(\"Found VSCODE_IPC_HOOK_CLI\")\n    return process.env.VSCODE_IPC_HOOK_CLI\n  }\n\n  const paths = getResolvedPathsFromArgs(args)\n  const client = new EditorSessionManagerClient(sessionSocket)\n\n  // If these flags are set then assume the user is trying to open in an\n  // existing instance since these flags have no effect otherwise.  That means\n  // if there is no existing instance we should error rather than falling back\n  // to spawning code-server normally.\n  const openInFlagCount = [\"reuse-window\", \"new-window\"].reduce((prev, cur) => {\n    return args[cur as keyof UserProvidedArgs] ? prev + 1 : prev\n  }, 0)\n  if (openInFlagCount > 0) {\n    logger.debug(\"Found --reuse-window or --new-window\")\n    const socketPath = await client.getConnectedSocketPath(paths[0])\n    if (!socketPath) {\n      throw new Error(`No opened code-server instances found to handle ${paths[0]}`)\n    }\n    return socketPath\n  }\n\n  // It's possible the user is trying to spawn another instance of code-server.\n  // 1. Check if any unrelated flags are set (this should only run when\n  //    code-server is invoked exactly like this: `code-server my-file`).\n  // 2. That a file or directory was passed.\n  // 3. That the socket is active.\n  // 4. That an instance exists to handle the path (implied by #3).\n  if (Object.keys(args).length === 1 && typeof args._ !== \"undefined\" && args._.length > 0) {\n    if (!(await client.canConnect())) {\n      return undefined\n    }\n    const socketPath = await client.getConnectedSocketPath(paths[0])\n    if (socketPath) {\n      logger.debug(\"Found existing code-server socket\")\n      return socketPath","sourceCodeStart":852,"sourceCodeEnd":888,"githubUrl":"https://github.com/coder/code-server/blob/51f90a376b42e217b38937410fe2855e0c1db87e/src/node/cli.ts#L852-L888","documentation":"When --reuse-window or --new-window is passed, code-server assumes the user wants to open the path in an already-running instance and calls client.getConnectedSocketPath. If no live socket is found (no instance running, or none bound to that path), it throws rather than silently spawning a new server, because those flags have no meaning for a fresh spawn.","triggerScenarios":"Running `code-server --reuse-window file.js` (or --new-window) when no code-server instance is currently running, or when the running instance's socket is not reachable/discoverable for the given path.","commonSituations":"Editor integrations (VS Code remote, CLI wrappers) that always pass --reuse-window; first invocation in a fresh shell where the background server was killed; stale socket directory.","solutions":["Start a normal `code-server` instance first (without --reuse-window/--new-window), then re-run with the flag","Drop --reuse-window/--new-window if you actually want a new server","Check `code-server --config` and confirm the socket path is writable and the instance is alive"],"exampleFix":"# before\ncode-server --reuse-window file.js   # no instance running\n\n# after\ncode-server &            # start instance\ncode-server --reuse-window file.js","handlingStrategy":"validation","validationCode":"import { client } from \"@coder/node\"  // or code-server's client util\nasync function ensureInstanceForReuse(paths: string[]): Promise<void> {\n  const socket = await client.getConnectedSocketPath(paths[0])\n  if (!socket) {\n    throw new Error(\"No running code-server instance; start one before using --reuse-window\")\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await openWithReuse(paths)\n} catch (e) {\n  if (e instanceof Error && /No opened code-server instances/.test(e.message)) {\n    // fall back: start a normal instance, then retry without reuse flags\n    await startCodeServer()\n  } else throw e\n}","preventionTips":["Have editor integrations check for a live instance before passing --reuse-window","Document that --reuse-window/--new-window require a running server","Surface a clear error in wrappers instead of retrying in a loop"],"tags":["cli","ipc","socket","editor-integration","configuration"],"backgroundTag":null,"analyzedSha":"51f90a376b42e217b38937410fe2855e0c1db87e","analyzedAt":"2026-08-12T11:27:34.273Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}