Skip to content

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

@ssmirr

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

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