[FEATURE]: Allow sessions to have custom working directories #6767

Closed
opened 2026-02-16 18:05:12 -05:00 by yindo · 4 comments
Owner

Originally created by @ssmirr on GitHub (Jan 19, 2026).

Originally assigned to: @thdxr on GitHub.

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Feature: Allow sessions to have custom working directories

Problem

Currently, all sessions share the same working directory (Instance.directory). This limits the ability to run multiple sessions in parallel when they need isolated file systems, such as:

  • Working on different git branches simultaneously
  • Running sessions in sandboxed environments
  • Supporting non-standard project layouts

Proposed Solution

  1. Add a session.creating plugin hook - Allow plugins to customize session creation, including setting a custom working directory
  2. Add Session.directory accessor - Allow sessions to have their own working directory that tools respect, falling back to Instance.directory if not set

Use Cases

  • Git worktrees: A plugin could create a separate worktree for each session, enabling parallel work on different branches without conflicts
  • Sandboxing: Sessions could operate in isolated directories for security or testing
  • Monorepos: Sessions could target different packages within a monorepo

Implementation

I already started playing around to add this feature and opened these two PRs that would complete the feature:

Let me know what you think and thanks for making opencode! 🫡

Originally created by @ssmirr on GitHub (Jan 19, 2026). Originally assigned to: @thdxr on GitHub. ### Feature hasn't been suggested before. - [x] I have verified this feature I'm about to request hasn't been suggested before. ### Describe the enhancement you want to request ### Feature: Allow sessions to have custom working directories #### Problem Currently, all sessions share the same working directory (`Instance.directory`). This limits the ability to run multiple sessions in parallel when they need isolated file systems, such as: - Working on different git branches simultaneously - Running sessions in sandboxed environments - Supporting non-standard project layouts #### Proposed Solution 1. **Add a `session.creating` plugin hook** - Allow plugins to customize session creation, including setting a custom working directory 2. **Add `Session.directory` accessor** - Allow sessions to have their own working directory that tools respect, falling back to `Instance.directory` if not set #### Use Cases - **Git worktrees**: A plugin could create a separate worktree for each session, enabling parallel work on different branches without conflicts - **Sandboxing**: Sessions could operate in isolated directories for security or testing - **Monorepos**: Sessions could target different packages within a monorepo #### Implementation I already started playing around to add this feature and opened these two PRs that would complete the feature: - https://github.com/anomalyco/opencode/pull/9361 - https://github.com/anomalyco/opencode/pull/9365 Let me know what you think and thanks for making opencode! 🫡
yindo added the discussion label 2026-02-16 18:05:12 -05:00
yindo closed this issue 2026-02-16 18:05:12 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 19, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #4048: [FEATURE]: tie working directory / directories with chat session - Requests the ability to tie working directories with chat sessions
  • #1143: Create session with a different root/working directory - Requests session-specific working directories for monorepo scenarios
  • #6679: [FEATURE]: Multiple model usage with git worktrees - Related request for git worktree support with separate directories
  • #4251: Concurrent sessions working on different repos interfere each other - Reports interference issues when sessions work in overlapping directories

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 19, 2026): This issue might be a duplicate of existing issues. Please check: - #4048: [FEATURE]: tie working directory / directories with chat session - Requests the ability to tie working directories with chat sessions - #1143: Create session with a different root/working directory - Requests session-specific working directories for monorepo scenarios - #6679: [FEATURE]: Multiple model usage with git worktrees - Related request for git worktree support with separate directories - #4251: Concurrent sessions working on different repos interfere each other - Reports interference issues when sessions work in overlapping directories Feel free to ignore if none of these address your specific case.
Author
Owner

@ssmirr commented on GitHub (Jan 19, 2026):

  • #4048 and #1143 are related use-cases to issue I opened here (not necessarily a duplicate IMO)
  • #6679 would become possible with solution i provided, but has a different use-case in mind

None of those previous issues had a solution proposed or implemented, but I have two (hopefully useful) PRs open that adds the feature.

@ssmirr commented on GitHub (Jan 19, 2026): - [#4048](https://github.com/anomalyco/opencode/issues/4048) and [#1143](https://github.com/anomalyco/opencode/issues/1143) are related use-cases to issue I opened here (not necessarily a duplicate IMO) - [#6679](https://github.com/anomalyco/opencode/issues/6679) would become possible with solution i provided, but has a different use-case in mind None of those previous issues had a solution proposed or implemented, but I have two (hopefully useful) PRs open that adds the feature.
Author
Owner

@pschiel commented on GitHub (Jan 19, 2026):

This is actually already working on CLI side. If you start opencode in a subdirectory of a project - it will set session.directory to that pwd. Allowing a different external_directory permission setup and such.

The POST /session API also has that directory parameter.

Issue is just: the web UI just doesn't currently show these (they are shown in TUI), nor allows to select this (in console you just start in that directory)

@pschiel commented on GitHub (Jan 19, 2026): This is actually already working on CLI side. If you start opencode in a subdirectory of a project - it will set `session.directory` to that pwd. Allowing a different `external_directory` permission setup and such. The `POST /session` API also has that directory parameter. Issue is just: the web UI just doesn't currently show these (they are shown in TUI), nor allows to select this (in console you just start in that directory)
Author
Owner

@R44VC0RP commented on GitHub (Jan 25, 2026):

Closing as duplicate of #1143 - this is being addressed in PR #9365 which adds per-session working directory support.

@R44VC0RP commented on GitHub (Jan 25, 2026): Closing as duplicate of #1143 - this is being addressed in PR #9365 which adds per-session working directory support.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6767