The open source coding agent.
TypeScript
feat(cli): add --dir option to run command (#12443)
Rahul Mishra693127d382ab
diff --git a/packages/opencode/src/cli/cmd/run.ts b/packages/opencode/src/cli/cmd/run.tsindex 163a5820d99..0febec3a207 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)}