diff options
| author | Rahul Mishra <[email protected]> | 2026-02-13 12:29:37 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-02-13 00:59:37 -0600 |
| commit | 693127d382abed14113f3b7a347851b7a44d74cd (patch) | |
| tree | 0e69e544766204a986d03f5f36b5be0d9bc5e855 | |
| parent | 0d90a22f9057dd69dca65ab52450f17d47a8656e (diff) | |
| download | opencode-693127d382abed14113f3b7a347851b7a44d74cd.tar.gz opencode-693127d382abed14113f3b7a347851b7a44d74cd.zip | |
feat(cli): add --dir option to run command (#12443)
| -rw-r--r-- | packages/opencode/src/cli/cmd/run.ts | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/packages/opencode/src/cli/cmd/run.ts b/packages/opencode/src/cli/cmd/run.ts index 163a5820d..0febec3a2 100644 --- a/packages/opencode/src/cli/cmd/run.ts +++ b/packages/opencode/src/cli/cmd/run.ts @@ -274,6 +274,10 @@ export const RunCommand = cmd({ type: "string", describe: "attach to a running opencode server (e.g., http://localhost:4096)", }) + .option("dir", { + type: "string", + describe: "directory to run in, path on remote server if attaching", + }) .option("port", { type: "number", describe: "port for the local server (defaults to random port if no value provided)", @@ -293,6 +297,18 @@ export const RunCommand = cmd({ .map((arg) => (arg.includes(" ") ? `"${arg.replace(/"/g, '\\"')}"` : arg)) .join(" ") + const directory = (() => { + if (!args.dir) return undefined + if (args.attach) return args.dir + try { + process.chdir(args.dir) + return process.cwd() + } catch { + UI.error("Failed to change directory to " + args.dir) + process.exit(1) + } + })() + const files: { type: "file"; url: string; filename: string; mime: string }[] = [] if (args.file) { const list = Array.isArray(args.file) ? args.file : [args.file] @@ -582,7 +598,7 @@ export const RunCommand = cmd({ } if (args.attach) { - const sdk = createOpencodeClient({ baseUrl: args.attach }) + const sdk = createOpencodeClient({ baseUrl: args.attach, directory }) return await execute(sdk) } |
