Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

core: agent silently stays in old directory when session_move fails ("Unable to move session to <dir>")

Open Beginner friendly
#56,038 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
git, typescript
Domain
tooling

Research direction

The generic error mapping is in packages/core/src/tool/plugin/opencode.ts, in the session_move tool's Effect.mapError. Compare it with the typed-error mapping in the session.move HTTP handler and with worktree_remove in the same file. Reproduce by calling session_move on a nonexistent directory in Code Mode. Done when the tool failure names the cause, such as the directory not existing, instead of only 'Unable to move session to ...'.

Written by the indexing model from the issue text.

Description

reproduced
Description

After creating a worktree, the agent can end up working in the old directory without anyone noticing: session_move failed, the agent couldn't tell why, and it carried on by cd-ing into the worktree in every shell call. The session stayed in the old directory, so the worktree's AGENTS.md was never loaded and relative paths in read/edit/glob resolved against the wrong root.

How it happened (2.0.30, Sonnet 5.5): in one turn the model ran git fetch && git worktree add ../repo-x in a shell call and called tools.opencode.session_move to ../repo-x as a parallel tool call. The move ran ~100 ms after the shell started, before the fetch had finished, so the directory didn't exist yet. Rejecting the move was correct. But the tool result was only:

Unable to move session to /…/repo-x

so the model had no reason to retry. Calling session_move again once the directory existed worked.

Two things would make this recoverable:

  1. Say why the move failed. packages/core/src/tool/plugin/opencode.ts (same on dev) maps every error to one message:
    Effect.mapError(
      (error) => new ToolFailure({ message: `Unable to move session to ${input.directory}`, error }),
    ),
    
    SessionMove already fails with typed errors (DestinationNotFoundError, DestinationNotDirectoryError, DestinationUnavailableError, NotFoundError). The session.move HTTP handler maps them to specific messages, and worktree_remove in the same file maps its own errors, so the same pattern fits here. With Directory does not exist: … the model would most likely have retried.
  2. Say when to call it. The injected hint ("When you create a worktree outside the current working directory … consider using execute to call tools.opencode.session_move") and the tool description ("do not run destination-dependent tools in the same execute call") don't say the directory must exist first. Adding "call it after the command that creates the directory has finished, not in parallel with it" would likely have prevented this.
Plugins

No response

OpenCode version

2.0.30

Steps to reproduce
  1. In Code Mode: await tools.opencode.session_move({ directory: "/tmp/does-not-exist" })
    → Unable to move session to /tmp/does-not-exist (caught error: name: "Error", no cause)
  2. Same move over HTTP: opencode api post /api/session/<sessionID>/move --data '{"directory":"/tmp/does-not-exist"}'
    → 400 {"_tag":"InvalidRequestError","message":"Directory does not exist: /tmp/does-not-exist"}
  3. opencode.log has no entry for the failed tool call.
Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Dominant language
TypeScript
Stars
213k
Forks
28.4k
Avg merge
8h 58m
Merged PRs (30d)
251

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from anomalyco/opencode

All issues in anomalyco/opencode

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.