Skip to content

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

Closed

Description

@ssmirr

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! 🫡

Activity

  1. added
    discussionUsed for feature requests, proposals, ideas, etc. Open discussion
    on Jan 19, 2026
  2. github-actions commented on Jan 19, 2026

    @github-actions
    Contributor

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

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

  3. ssmirr commented on Jan 19, 2026

    @ssmirr
    Author
    • #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.

  4. pschiel commented on Jan 20, 2026

    @pschiel
    Contributor

    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)

  5. R44VC0RP commented on Jan 25, 2026

    @R44VC0RP
    Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

discussionUsed for feature requests, proposals, ideas, etc. Open discussion

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions