# A folder name that cut Claude Code off from the gateway (/blog/folder-names-outside-latin-1)

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.

Published 2026-12-03 by William Monroy.

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](/docs/concepts/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 [#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](/docs/concepts/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 [#what-a-header-can-carry]

An HTTP header value is a string of bytes. As a [comment in turno's code](https://github.com/wimo-dev/turno/blob/turno-cli%400.2.0/packages/turno/src/agents/claude.ts#L73-L79) 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](https://fetch.spec.whatwg.org/#headers-class) types that value as a `ByteString`, and converting a string to a `ByteString` follows a rule in [Web IDL](https://webidl.spec.whatwg.org/#js-ByteString): "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 name | Code points | UTF-8 bytes | Inside Latin-1 |
| --- | --- | --- | --- |
| `é`, NFC | U+00E9 | C3 A9 | yes |
| `e` + U+0301, NFD | U+0065 U+0301 | 65 CC 81 | no |
| `日` | U+65E5 | E6 97 A5 | no |
| `🚀` | U+1F680 | F0 9F 9A 80 | no |

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 [#the-fix]

[turno 0.2.0](/releases/cli/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 `_`:

```ts title="packages/turno/src/cli/launchers.ts"
    "# 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`:

```ts title="packages/turno/src/agents/claude.ts"
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:-}", // [!code highlight]
    },
  };
}
```

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

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

```text
L1VzZXJzL2EvQ2Fmw6kv5pel5pys
```

## Reading it back, and the old header [#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:

```ts title="packages/turno/src/mcpd/gateway.ts"
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"); // [!code highlight]
    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 [#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`](https://code.claude.com/docs/en/mcp#environment-variable-expansion-in-mcp-json). The Codex entry maps the header to the variable with `env_http_headers`, which [Codex's MCP documentation](https://learn.chatgpt.com/docs/extend/mcp?surface=cli#streamable-http-servers) 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](/releases/cli/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](https://docs.grok.com/build/agents-window/mcp#config-interpolation), the page that the MCP documentation on cursor.com redirects to.

## The tests that came with it [#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 `日本 Café 🚀`, 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 [#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](/docs/concepts/folder-rules#server-sets-which-mcp-servers-a-folder-sees) says.

The Copilot entry relies on Copilot CLI expanding variables in headers, as its [command reference](https://docs.github.com/en/copilot/reference/copilot-cli-reference/cli-command-reference#remote-server-configuration-fields) 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 [#sources]

- The encoded header for the Claude Code and Codex entries: [pull request 22](https://github.com/wimo-dev/turno/pull/22), released in [turno 0.2.0](/releases/cli/0-2-0). The header for Copilot CLI and Cursor CLI: [pull request 59](https://github.com/wimo-dev/turno/pull/59), released in [turno 0.3.0](/releases/cli/0-3-0).
- The three excerpts are the same at turno-cli 0.2.0 and 0.6.4: [`launchers.ts`](https://github.com/wimo-dev/turno/blob/turno-cli%400.6.4/packages/turno/src/cli/launchers.ts), [`claude.ts`](https://github.com/wimo-dev/turno/blob/turno-cli%400.6.4/packages/turno/src/agents/claude.ts) and [`gateway.ts`](https://github.com/wimo-dev/turno/blob/turno-cli%400.6.4/packages/turno/src/mcpd/gateway.ts).