@devries-cameron20 / t3code-1 / commits / 27c2b145f8
Fork 0

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

feat(cli): allow optional positional cwd argument (#1727)

Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>

Julius Marminge committed Apr 3, 2026 at 19:49 UTC 27c2b145f8d214b5c578eefc463278d0916fb048
2 files changed +22 -3
apps/server/src/cli-config.test.ts
+9
@@ -40,6 +40,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
40 port: Option.none(),
41 host: Option.none(),
42 baseDir: Option.none(),
43 + cwd: Option.none(),
44 devUrl: Option.none(),
45 noBrowser: Option.none(),
46 authToken: Option.none(),
@@ -102,6 +103,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
103 port: Option.some(8788),
104 host: Option.some("127.0.0.1"),
105 baseDir: Option.some(baseDir),
106 + cwd: Option.none(),
107 devUrl: Option.some(new URL("http://127.0.0.1:4173")),
108 noBrowser: Option.some(true),
109 authToken: Option.some("flag-token"),
@@ -178,6 +180,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
180 port: Option.none(),
181 host: Option.none(),
182 baseDir: Option.none(),
183 + cwd: Option.none(),
184 devUrl: Option.none(),
185 noBrowser: Option.none(),
186 authToken: Option.none(),
@@ -228,6 +231,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
231 const fs = yield* FileSystem.FileSystem;
232 const path = yield* Path.Path;
233 const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-cli-config-dirs-" });
234 + const customCwd = path.join(baseDir, "nested", "project");
235
236 const resolved = yield* resolveServerConfig(
237 {
@@ -235,6 +239,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
239 port: Option.some(4888),
240 host: Option.none(),
241 baseDir: Option.some(baseDir),
242 + cwd: Option.some(customCwd),
243 devUrl: Option.some(new URL("http://127.0.0.1:5173")),
244 noBrowser: Option.none(),
245 authToken: Option.none(),
@@ -253,6 +258,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
258 );
259
260 for (const directory of [
261 + customCwd,
262 resolved.stateDir,
263 resolved.logsDir,
264 resolved.providerLogsDir,
@@ -264,6 +270,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
270 ]) {
271 expect(yield* fs.exists(directory)).toBe(true);
272 }
273 + expect(resolved.cwd).toBe(path.resolve(customCwd));
274 }),
275 );
276
@@ -290,6 +297,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
297 port: Option.some(8788),
298 host: Option.some("127.0.0.1"),
299 baseDir: Option.none(),
300 + cwd: Option.none(),
301 devUrl: Option.some(new URL("http://127.0.0.1:4173")),
302 noBrowser: Option.none(),
303 authToken: Option.some("flag-token"),
@@ -360,6 +368,7 @@ it.layer(NodeServices.layer)("cli config resolution", (it) => {
368 port: Option.some(4888),
369 host: Option.none(),
370 baseDir: Option.some(baseDir),
371 + cwd: Option.none(),
372 devUrl: Option.none(),
373 noBrowser: Option.none(),
374 authToken: Option.none(),
apps/server/src/cli.ts
+13 -3
@@ -1,7 +1,7 @@
1 import { NetService } from "@t3tools/shared/Net";
2 import { parsePersistedServerObservabilitySettings } from "@t3tools/shared/serverSettings";
3 import { Config, Effect, FileSystem, LogLevel, Option, Path, Schema } from "effect";
4 -import { Command, Flag, GlobalFlag } from "effect/unstable/cli";
4 +import { Argument, Command, Flag, GlobalFlag } from "effect/unstable/cli";
5
6 import {
7 DEFAULT_PORT,
@@ -13,7 +13,7 @@ import {
13 type ServerConfigShape,
14 } from "./config";
15 import { readBootstrapEnvelope } from "./bootstrap";
16 -import { resolveBaseDir } from "./os-jank";
16 +import { expandHomePath, resolveBaseDir } from "./os-jank";
17 import { runServer } from "./server";
18
19 const PortSchema = Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 65535 }));
@@ -140,6 +140,7 @@ interface CliServerFlags {
140 readonly port: Option.Option<number>;
141 readonly host: Option.Option<string>;
142 readonly baseDir: Option.Option<string>;
143 + readonly cwd: Option.Option<string>;
144 readonly devUrl: Option.Option<URL>;
145 readonly noBrowser: Option.Option<boolean>;
146 readonly authToken: Option.Option<string>;
@@ -225,6 +226,9 @@ export const resolveServerConfig = (
226 ),
227 ),
228 );
229 + const rawCwd = Option.getOrElse(flags.cwd, () => process.cwd());
230 + const cwd = path.resolve(yield* expandHomePath(rawCwd.trim()));
231 + yield* fs.makeDirectory(cwd, { recursive: true });
232 const derivedPaths = yield* deriveServerPaths(baseDir, devUrl);
233 yield* ensureServerDirectories(derivedPaths);
234 const persistedObservabilitySettings = yield* loadPersistedObservabilitySettings(
@@ -315,7 +319,7 @@ export const resolveServerConfig = (
319 otlpServiceName: env.otlpServiceName,
320 mode,
321 port,
318 - cwd: process.cwd(),
322 + cwd,
323 baseDir,
324 ...derivedPaths,
325 serverTracePath,
@@ -336,6 +340,12 @@ const commandFlags = {
340 port: portFlag,
341 host: hostFlag,
342 baseDir: baseDirFlag,
343 + cwd: Argument.string("cwd").pipe(
344 + Argument.withDescription(
345 + "Working directory for provider sessions (defaults to the current directory).",
346 + ),
347 + Argument.optional,
348 + ),
349 devUrl: devUrlFlag,
350 noBrowser: noBrowserFlag,
351 authToken: authTokenFlag,