@devries-cameron20 / t3code-1 / commits / 5f6b5a8e60
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(cli): the already-running error names the t3 pair command that connects (#31543)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 14, 2026 at 20:41 UTC 5f6b5a8e60a2ef8e3caa09a4665abc198120dcd9
3 files changed +64 -4
apps/server/src/cli/config.test.ts
+53
@@ -214,6 +214,59 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
214 }),
215 );
216
217 + it.effect("names the pair command for the refused server's home", () =>
218 + Effect.gen(function* () {
219 + const fs = yield* FileSystem.FileSystem;
220 + const path = yield* Path.Path;
221 + const child = yield* liveProcess;
222 + assert(child.pid !== undefined);
223 + for (const source of ["flag", "T3CODE_HOME", "default"] as const) {
224 + const home = yield* fs.makeTempDirectoryScoped({ prefix: "t3-cli-preflight-pair-" });
225 + const baseDir = source === "default" ? path.join(home, ".t3") : home;
226 + const stateDir = path.join(baseDir, "userdata");
227 + yield* fs.makeDirectory(stateDir, { recursive: true });
228 + yield* fs.writeFileString(
229 + path.join(stateDir, "server-runtime.json"),
230 + yield* encodeUnknownJson({
231 + version: 1,
232 + pid: child.pid,
233 + port: 3773,
234 + origin: "http://127.0.0.1:3773",
235 + startedAt: "2026-10-01T00:00:00.000Z",
236 + }),
237 + );
238 + const error = yield* resolveServerConfig(
239 + {
240 + ...minimalWebFlags(baseDir),
241 + baseDir: source === "flag" ? Option.some(baseDir) : Option.none(),
242 + cwd: Option.some(path.join(home, "project")),
243 + },
244 + Option.none(),
245 + { rejectRunningServer: true },
246 + ).pipe(
247 + Effect.provide(
248 + Layer.merge(
249 + NetService.layer,
250 + ConfigProvider.layer(
251 + ConfigProvider.fromEnv({
252 + env: source === "T3CODE_HOME" ? { T3CODE_HOME: baseDir } : {},
253 + }),
254 + ),
255 + ),
256 + ),
257 + Effect.provideService(HostProcess.HomeDirectory, home),
258 + Effect.provideService(HostProcess.Platform, "linux"),
259 + Effect.flip,
260 + );
261 + // A temp dir with spaces or backslashes is single-quoted for the shell.
262 + const homePattern = baseDir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
263 + expect(String(error)).toMatch(
264 + new RegExp(`pair --base-dir (${homePattern}|'${homePattern}')`),
265 + );
266 + }
267 + }),
268 + );
269 +
270 it.effect("enables a trimmed reusable auth token only for web dev mode", () =>
271 Effect.gen(function* () {
272 const baseDir = yield* FileSystem.FileSystem.pipe(
apps/server/src/cli/config.ts
+7 -1
@@ -27,6 +27,7 @@ import { resolveServiceLauncherMode } from "../cloud/serviceLauncherClient.ts";
27 import * as ServerConfig from "../config.ts";
28 import { expandHomePath, resolveBaseDir } from "../os-jank.ts";
29 import { isProcessAlive, readPersistedServerRuntimeState } from "../serverRuntimeState.ts";
30 +import { resolveHostCliCommand } from "./invocation.ts";
31
32 const modeFlag = Flag.Literals("mode", ServerConfig.RuntimeMode.literals).pipe(
33 Flag.withDescription("Runtime mode. `desktop` keeps loopback defaults unless overridden."),
@@ -355,8 +356,13 @@ export const resolveServerConfig = Effect.fn("config.resolveServerConfig")(funct
356 runtime.value.pid !== process.pid &&
357 isProcessAlive(runtime.value.pid)
358 ) {
359 + // Bare `t3 pair` prefers a linked worktree's `.t3`, so always name this home.
360 + const { command: pairCommand } = yield* resolveHostCliCommand("pair", [
361 + "--base-dir",
362 + baseDir,
363 + ]);
364 return yield* new CliError.UserError({
359 - cause: `A T3 Code server is already running for ${baseDir} (pid ${runtime.value.pid}, ${runtime.value.origin}). Connect to that server, stop it before starting another, or use a different --base-dir.`,
365 + cause: `A T3 Code server is already running for ${baseDir} (pid ${runtime.value.pid}, ${runtime.value.origin}). To open it, run \`${pairCommand}\` and open the pairing URL it prints. To start another server, stop this one first or use a different --base-dir.`,
366 });
367 }
368 }
docs/user/install.md
+4 -3
@@ -42,9 +42,10 @@ Run `t3 help` or `t3 --help` for the full reference. To start in a new working
42 directory, use an explicit path such as `t3 ./my-project`. A bare directory name
43 is accepted only if it already exists.
44
45 -If `t3` or `t3 start` reports an already running server, connect to that server
46 -instead. Stop it before starting a replacement, or use a different `--base-dir`
47 -for an independent server.
45 +If `t3` or `t3 start` reports an already running server, run the `t3 pair`
46 +command it names and open the pairing URL to connect to that server. Stop it
47 +before starting a replacement, or use a different `--base-dir` for an
48 +independent server.
49
50 To try T3 Code once without installing it, run `npx t3@latest` instead (needs
51 Node.js for `npx`). It offers to install the `t3` command first. If you say no,