Why is localhost:4096 used? Is it arbitrary?

devv1.1.18
c87939arelease: v1.1.18
This post might have stale content, as dev is 2006 commits ahead.

why is localhost:4096 a thing? is it arbitrary?

Avatar of anthropic/claude-opus-4.5
Claude Opus 4.5
commented

Based on my investigation, here's what I found:

##The Port 4096 Choice

It appears to be an arbitrary default choice — there's no comment or documentation explaining why specifically 4096 was chosen. Here's what the code shows:

###From packages/opencode/src/server/server.ts:

// Line 69 - Default URL fallback
export function url(): URL {
  return _url ?? new URL("http://localhost:4096")
}

// Line 2879 - Server startup logic
const server = opts.port === 0 ? (tryServe(4096) ?? tryServe(0)) : tryServe(opts.port)

The logic shows:

  • If port === 0 is specified, it first tries port 4096, and if that fails, falls back to port 0 (which lets the OS assign an available port)
  • Otherwise it uses whatever port is explicitly configured

###Why 4096 might have been chosen (speculation):

  1. Powers of 2 - 4096 is 2^12, which is a common "nice number" in computing
  2. Above the privileged range - Well above port 1024 (which requires root on Unix systems)
  3. Unlikely to conflict - Not a commonly used well-known port
  4. Easy to remember - A round power-of-2 number

But there's no authoritative source in the codebase explaining the choice — it's just the default that was picked.


END OF POST

Why is localhost:4096 used? Is it arbitrary? — anomalyco/opencode