GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [BUG]: Session switching doesn't change working directory context · Issue #6697 · anomalyco/opencode

[BUG]: Session switching doesn't change working directory context #6697

New issue
Copy link
New issue
Copy link
Closed
Closed
[BUG]: Session switching doesn't change working directory context#6697
Copy link
Assignees
thdxr

Description

@bcheung
bcheung
opened on Jan 2, 2026
Issue body actions

When switching/resuming sessions, the entire execution context remains bound to Instance.directory (where opencode was started), not the session's stored directory.

What's affected

  • System prompt - LLM is told "Working directory: X" but session was created in Y
  • All file tools - read, write, edit, grep, glob, ls, patch, multiedit resolve paths relative to wrong directory
  • Bash/shell execution - commands run in wrong cwd
  • LSP connections - language server bound to wrong project
  • File watchers - watching wrong directory
  • Snapshots - git operations in wrong repo
  • Config loading - may load wrong project config

Impact

  • Global project: Sessions from different directories are visible together (this is fine!), but switching to one operates in the current directory, not the session's original directory (this is the bug)
  • Worktrees: Can see session from worktree when in main repo, but continuing that session operates in main repo, not the worktree
  • Clone collision: Even when sessions are incorrectly mixed due to project ID collision, proper directory switching would at least operate in the right place

Note: Global project and shared sessions across directories isn't inherently bad - it's useful for seeing all your work. The bug is that switching sessions doesn't restore the correct working directory context.

Root cause

Instance.directory is set once at startup and never updated when switching sessions:

opencode/packages/opencode/src/project/instance.ts

Lines 17 to 41 in 038cff4

async provide<R>(input: { directory: string; init?: () => Promise<any>; fn: () => R }): Promise<R> {
let existing = cache.get(input.directory)
if (!existing) {
Log.Default.info("creating instance", { directory: input.directory })
existing = iife(async () => {
const project = await Project.fromDirectory(input.directory)
const ctx = {
directory: input.directory,
worktree: project.worktree,
project,
}
await context.provide(ctx, async () => {
await input.init?.()
})
return ctx
})
cache.set(input.directory, existing)
}
const ctx = await existing
return context.provide(ctx, async () => {
return input.fn()
})
},
get directory() {
return context.use().directory

It's used throughout the codebase:

session/system.ts      - system prompt, config loading
session/prompt.ts      - path resolution, shell cwd
tool/*.ts              - all file operations
lsp/*.ts               - language server
file/watcher.ts        - file watching
snapshot/index.ts      - git snapshots

Related

  • Sessions are now mixed with home directory session list, disregarding which directory you're in #3551 - "Sessions are now mixed with home directory session list"

Expected behavior

When switching/resuming a session, Instance.directory (and related context) should be updated to match session.directory so the entire execution context is correct.

Otherwise, opencode should not be showing sessions with different directories even if within the same project.

Activity

  1. github-actions
    assigned
    thdxr
    on Jan 2, 2026
  2. github-actions commented on Jan 2, 2026

    @github-actions
    github-actionsBot
    on Jan 2, 2026 – with GitHub Actions
    Contributor
    More actions

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

    • Sessions are now mixed with home directory session list, disregarding which directory you're in #3551: Sessions are now mixed with home directory session list - related to session visibility across directories
    • Wrong working directory #3391: Wrong working directory - similar issue with incorrect working directory execution
    • [FEATURE]: tie working directory / directories with chat session #4048: tie working directory / directories with chat session - feature request for tying directory with session
    • Concurrent sessions working on different repos interfer each other #4251: Concurrent sessions working on different repos interfere each other - related issue with sessions in different directories interfering

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

  3. bcheung
    changed the title [-]Session switching doesn't change working directory context - tools execute in wrong directory[/-] [+][BUG]: Session switching doesn't change working directory context - tools execute in wrong directory[/+] on Jan 2, 2026
  4. bcheung
    changed the title [-][BUG]: Session switching doesn't change working directory context - tools execute in wrong directory[/-] [+][BUG]: Session switching doesn't change working directory context[/+] on Jan 2, 2026
  5. R44VC0RP commented on Jan 25, 2026

    @R44VC0RP
    R44VC0RP
    on Jan 25, 2026
    Contributor
    More actions

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

  6. R44VC0RP
    closed this as completedon Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @thdxr
    thdxr

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.