BlogDebuggingturno

A folder name that cut Claude Code off from the gateway

The gateway learned each session's folder from an HTTP header, and a path with an accent in NFD form, CJK characters or an emoji is a value Claude Code cannot put in a header, so it refused to connect to any server. The launchers now send the folder as base64url.

5 min read

View sourceFeed

In turno 0.1.1, opening Claude Code in a folder whose name had an accent in NFD form, CJK characters or an emoji took every MCP server behind the gateway away from that session. The same agent in a folder with a plain ASCII name worked.

The servers were fine. Claude Code never reached them, because it refused to connect.

One header in every entry

mcpd needs to know which folder a session runs in: project and session servers start in it, and since 0.2.0 folder rules can also give a folder its own set of servers. The folder travels as a header on every request. In 0.1.1, the entry that turno mcp sync wrote for Claude Code carried "X-Turno-Cwd": "${PWD:-}", and the Codex entry mapped the same header to PWD.

Every Claude Code gateway entry has that header, so a value Claude Code cannot send breaks every entry at once. That is why it looked like the gateway was down.

What a header can carry

An HTTP header value is a string of bytes. As a comment in turno's code puts it, a raw path outside Latin-1 (code points up to U+00FF) is an invalid header value, and Claude Code would refuse to connect. The same limit holds for any client that passes a header value through the Fetch Headers interface. The Fetch standard types that value as a ByteString, and converting a string to a ByteString follows a rule in Web IDL: "If the value of any element of x is greater than 255, then throw a TypeError." A path is Unicode text, and most of it fits. The parts that do not fit are the ones in the folder names that failed.

Part of a nameCode pointsUTF-8 bytesInside Latin-1
é, NFCU+00E9C3 A9yes
e + U+0301, NFDU+0065 U+030165 CC 81no
日U+65E5E6 97 A5no
🚀U+1F680F0 9F 9A 80no

The two forms of é look the same on screen. NFC writes it as one code point inside Latin-1. NFD writes an e followed by a combining accent, U+0301, which is outside it. So a folder could fail or work depending on how its name had been typed or saved, which made the bug hard to pin down from the name alone.

The fix

turno 0.2.0 stopped sending the path as text. Each launcher now encodes the folder it starts in as base64url of its UTF-8 bytes, which uses only letters, digits, - and _:

packages/turno/src/cli/launchers.tsTypeScript
    "# The session folder for the MCP gateway, base64url so any path fits in an HTTP header.",
    `TURNO_SESSION_CWD_B64="$(printf %s "$PWD" | base64 | tr -d '\\n=' | tr '+/' '-_')"`,
    "export TURNO_SESSION_CWD_B64",

The gateway entries send that variable in a new header, X-Turno-Cwd-B64, instead of PWD:

packages/turno/src/agents/claude.tsTypeScript
export function gatewayEntry(name: string, port: number, token: string, profile: string): Record<string, unknown> {
  return {
    type: "http",
    url: gatewayUrl(name, port),
    headers: {
      Authorization: `Bearer ${token}`,
      "X-Turno-Profile": profile,
      "X-Turno-Pid": "${TURNO_SESSION_PID:-0}",
      "X-Turno-Cwd-B64": "${TURNO_SESSION_CWD_B64:-}", 
    },
  };
}

The path from the gateway's own tests, /Users/a/Café/日本, goes through the launcher's pipeline as plain ASCII:

Shell
printf %s "/Users/a/Café/日本" | base64 | tr -d '\n=' | tr '+/' '-_'
L1VzZXJzL2EvQ2Fmw6kv5pel5pys

Reading it back, and the old header

On the other side, mcpd reads the encoded header first and keeps reading the old one, because configs written by 0.1.1 still send it until they are synced again:

packages/turno/src/mcpd/gateway.tsTypeScript
export function decodeCwdHeaders(headers: Record<string, string | string[] | undefined>): string | undefined {
  const pick = (name: string) => {
    const v = headers[name];
    return (Array.isArray(v) ? v[0] : v)?.trim() || undefined;
  };
  const b64 = pick("x-turno-cwd-b64");
  if (b64 && /^[A-Za-z0-9_-]+={0,2}$/.test(b64)) {
    const path = Buffer.from(b64, "base64url").toString("utf8"); 
    if (isAbsolute(path) && !path.includes("�") && !path.includes("\0")) return path;
  }
  const raw = pick("x-turno-cwd");
  if (!raw || !isAbsolute(raw)) return undefined;
  if (/[\u0080-ÿ]/.test(raw)) {
    const repaired = Buffer.from(raw, "latin1").toString("utf8");
    if (!repaired.includes("�")) return repaired;
  }
  return raw;
}

A decoded path is kept only if it is absolute and decodes cleanly, with no replacement character and no NUL byte. A header that arrives unexpanded, such as the literal text ${TURNO_SESSION_CWD_B64}, fails the pattern and is ignored.

The second half handles a client that sent the old header as raw UTF-8 bytes. Those bytes arrive at mcpd as Latin-1 text, so Café reads as Café. Reading those characters back as bytes and decoding them as UTF-8 gives the original path. A path that really was Latin-1 text does not decode as UTF-8, and is returned as it came.

When neither header gives a usable folder, mcpd looks up the folder of the client process instead, through /proc on Linux and lsof elsewhere. That is also how a plain claude, started without a launcher, gets its folder. mcpd writes a line to its log only when a header names a folder that does not exist.

Picking up the fix takes two commands, because both the entries and the launchers are files turno wrote: turno mcp sync rewrites the entries and turno profile repair rewrites the launchers.

Each agent in its own syntax

The header is the same for every agent, and the way to fill it is not. The Claude Code entry uses ${TURNO_SESSION_CWD_B64:-}. Claude Code's MCP documentation describes that ${VAR:-default} form in a server's headers, in its section on environment variable expansion in .mcp.json. The Codex entry maps the header to the variable with env_http_headers, which Codex's MCP documentation describes as a map of header names to environment variable names. In 0.2.0 only those two sent the folder. turno 0.3.0 gave the Copilot CLI and Cursor CLI entries the same header, in ${TURNO_SESSION_CWD_B64} and ${env:TURNO_SESSION_CWD_B64}, so folder server sets apply to them without the process lookup. The ${env:NAME} form is documented under config interpolation, the page that the MCP documentation on cursor.com redirects to.

The tests that came with it

The tests use the names that failed. One runs a launcher written by turno, with a stand-in for the agent, in a folder named 日本 Café 🚀, with the accent in NFD form. It checks that the value holds only base64url characters and decodes back to the same path. Another opens a session through the gateway from 日本 Café 🚀 and asks a project server which folder it runs in. A third sends /Users/a/Café/日本 as raw UTF-8 in the old header and expects the repaired path.

What is still open

The folder comes from the launcher. A session started without one, such as a plain copilot or the Cursor editor, depends on the process lookup, and a session whose folder the gateway cannot learn sees every server, as the folder rules page says.

The Copilot entry relies on Copilot CLI expanding variables in headers, as its command reference documents ("Supports variable expansion"). The code notes that this has not been verified against the real CLI.

The repair of the old header is a guess from the bytes. A folder whose real name is Latin-1 text that also happens to be valid UTF-8, such as one literally named Café, would be read as Café. Entries rewritten by turno mcp sync send the encoded header and never reach that branch.

Sources