summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKit Langton <[email protected]>2026-04-25 01:14:52 -0400
committerGitHub <[email protected]>2026-04-25 01:14:52 -0400
commit4877eccc0d06c747624bf61aaa6f3e65cea9cc8d (patch)
tree18d95bcfeb7758be317471216861e8bd30f74e08
parentf7d527cd28affbd68c18e11c36799d252d88df13 (diff)
downloadopencode-4877eccc0d06c747624bf61aaa6f3e65cea9cc8d.tar.gz
opencode-4877eccc0d06c747624bf61aaa6f3e65cea9cc8d.zip
Fix shell cwd after login startup (#24215)
-rw-r--r--packages/opencode/src/session/prompt.ts12
-rw-r--r--packages/opencode/test/session/prompt.test.ts24
2 files changed, 31 insertions, 5 deletions
diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts
index 5f3530bce..3d07a96ec 100644
--- a/packages/opencode/src/session/prompt.ts
+++ b/packages/opencode/src/session/prompt.ts
@@ -787,6 +787,7 @@ NOTE: At any point in time through this workflow you should feel free to ask the
const shellName = (
process.platform === "win32" ? path.win32.basename(sh, ".exe") : path.basename(sh)
).toLowerCase()
+ const cwd = ctx.directory
const invocations: Record<string, { args: string[] }> = {
nu: { args: ["-c", input.command] },
fish: { args: ["-c", input.command] },
@@ -795,12 +796,13 @@ NOTE: At any point in time through this workflow you should feel free to ask the
"-l",
"-c",
`
- __oc_cwd=$PWD
[[ -f ~/.zshenv ]] && source ~/.zshenv >/dev/null 2>&1 || true
[[ -f "\${ZDOTDIR:-$HOME}/.zshrc" ]] && source "\${ZDOTDIR:-$HOME}/.zshrc" >/dev/null 2>&1 || true
- cd "$__oc_cwd"
+ cd -- "$1"
eval ${JSON.stringify(input.command)}
`,
+ "opencode",
+ cwd,
],
},
bash: {
@@ -808,12 +810,13 @@ NOTE: At any point in time through this workflow you should feel free to ask the
"-l",
"-c",
`
- __oc_cwd=$PWD
shopt -s expand_aliases
[[ -f ~/.bashrc ]] && source ~/.bashrc >/dev/null 2>&1 || true
- cd "$__oc_cwd"
+ cd -- "$1"
eval ${JSON.stringify(input.command)}
`,
+ "opencode",
+ cwd,
],
},
cmd: { args: ["/c", input.command] },
@@ -823,7 +826,6 @@ NOTE: At any point in time through this workflow you should feel free to ask the
}
const args = (invocations[shellName] ?? invocations[""]).args
- const cwd = ctx.directory
const shellEnv = yield* plugin.trigger(
"shell.env",
{ cwd, sessionID: input.sessionID, callID: part.callID },
diff --git a/packages/opencode/test/session/prompt.test.ts b/packages/opencode/test/session/prompt.test.ts
index 8ffb20f15..911cb4415 100644
--- a/packages/opencode/test/session/prompt.test.ts
+++ b/packages/opencode/test/session/prompt.test.ts
@@ -1078,6 +1078,30 @@ unix("shell completes a fast command on the preferred shell", () =>
),
)
+unix("shell commands can change directory after startup", () =>
+ provideTmpdirInstance(
+ (dir) =>
+ Effect.gen(function* () {
+ const { prompt, run, chat } = yield* boot()
+ const parent = path.dirname(dir)
+ const result = yield* prompt.shell({
+ sessionID: chat.id,
+ agent: "build",
+ command: "cd .. && pwd",
+ })
+
+ expect(result.info.role).toBe("assistant")
+ const tool = completedTool(result.parts)
+ if (!tool) return
+
+ expect(tool.state.output).toContain(parent)
+ expect(tool.state.metadata.output).toContain(parent)
+ yield* run.assertNotBusy(chat.id)
+ }),
+ { git: true, config: cfg },
+ ),
+)
+
unix("shell lists files from the project directory", () =>
provideTmpdirInstance(
(dir) =>