coder/code-server · error · Error

No opened code-server instances found to handle ${paths[0]}

Error message

No opened code-server instances found to handle ${paths[0]}

What it means

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.

Source

Thrown at src/node/cli.ts:870

    logger.debug("Found VSCODE_IPC_HOOK_CLI")
    return process.env.VSCODE_IPC_HOOK_CLI
  }

  const paths = getResolvedPathsFromArgs(args)
  const client = new EditorSessionManagerClient(sessionSocket)

  // If these flags are set then assume the user is trying to open in an
  // existing instance since these flags have no effect otherwise.  That means
  // if there is no existing instance we should error rather than falling back
  // to spawning code-server normally.
  const openInFlagCount = ["reuse-window", "new-window"].reduce((prev, cur) => {
    return args[cur as keyof UserProvidedArgs] ? prev + 1 : prev
  }, 0)
  if (openInFlagCount > 0) {
    logger.debug("Found --reuse-window or --new-window")
    const socketPath = await client.getConnectedSocketPath(paths[0])
    if (!socketPath) {
      throw new Error(`No opened code-server instances found to handle ${paths[0]}`)
    }
    return socketPath
  }

  // It's possible the user is trying to spawn another instance of code-server.
  // 1. Check if any unrelated flags are set (this should only run when
  //    code-server is invoked exactly like this: `code-server my-file`).
  // 2. That a file or directory was passed.
  // 3. That the socket is active.
  // 4. That an instance exists to handle the path (implied by #3).
  if (Object.keys(args).length === 1 && typeof args._ !== "undefined" && args._.length > 0) {
    if (!(await client.canConnect())) {
      return undefined
    }
    const socketPath = await client.getConnectedSocketPath(paths[0])
    if (socketPath) {
      logger.debug("Found existing code-server socket")
      return socketPath

View on GitHub (pinned to 51f90a376b)

Solutions

  1. Start a normal `code-server` instance first (without --reuse-window/--new-window), then re-run with the flag
  2. Drop --reuse-window/--new-window if you actually want a new server
  3. Check `code-server --config` and confirm the socket path is writable and the instance is alive

Example fix

# before
code-server --reuse-window file.js   # no instance running

# after
code-server &            # start instance
code-server --reuse-window file.js
Defensive patterns

Strategy: validation

Validate before calling

import { client } from "@coder/node"  // or code-server's client util
async function ensureInstanceForReuse(paths: string[]): Promise<void> {
  const socket = await client.getConnectedSocketPath(paths[0])
  if (!socket) {
    throw new Error("No running code-server instance; start one before using --reuse-window")
  }
}

Try / catch

try {
  await openWithReuse(paths)
} catch (e) {
  if (e instanceof Error && /No opened code-server instances/.test(e.message)) {
    // fall back: start a normal instance, then retry without reuse flags
    await startCodeServer()
  } else throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of coder/code-server@51f90a376b (2026-08-12). Data as JSON: /api/errors/3f3f2a81c8fe7aaa. Report an issue: GitHub.