Skip to content

Custom tools don't receive project directory in ToolContext #10477

Closed

Description

@rickbassham

Description

Custom tools defined via @opencode-ai/plugin have no way to access the project's working directory at execution time. The ToolContext passed to execute() contains sessionID, messageID, agent, abort, callID, extra, metadata(), and ask() - but no directory or worktree.

This works fine when running opencode directly in a project directory (where process.cwd() happens to be correct), but fails when using opencode web as a daemon serving multiple projects.

Steps to reproduce

  1. Run opencode web as a daemon (e.g., via launchd with a fixed WorkingDirectory)
  2. Create a custom tool that needs the project directory:
    import { tool } from "@opencode-ai/plugin";
    
    export default tool({
      description: "Get git status",
      args: {},
      async execute(args, context) {
        // context has no directory property
        // process.cwd() returns the daemon's cwd, not the project
        const result = await Bun.$`git status`.text();
        return result;
      },
    });
  3. Open a project in the web UI and invoke the tool
  4. The tool runs in the wrong directory

Debug output

Logging the full context and environment from a custom tool shows:

{
  "context": {
    "sessionID": "ses_...",
    "messageID": "msg_...",
    "agent": "build",
    "callID": "toolu_...",
    "extra": { "model": {...} },
    "allKeys": ["sessionID", "abort", "messageID", "callID", "extra", "agent", "metadata", "ask"]
  },
  "cwd": "/Users/rick",
  "env": {
    "OPENCODE": "1",
    "HOME": "/Users/rick"
  }
}

Note: cwd is the daemon's working directory, not the project. No directory in context, no OPENCODE_DIRECTORY env var.

Expected behavior

Custom tools should receive directory and worktree in ToolContext, matching what plugins receive in PluginInput at initialization:

export type ToolContext = {
  sessionID: string
  messageID: string
  agent: string
  abort: AbortSignal
  directory: string    // <- add this
  worktree: string     // <- add this
  // ...
}

Workaround

None currently. Built-in tools work because they import Instance.directory directly, but custom tools can't access that module.

OpenCode version

1.0.x (current dev branch)

Operating System

macOS (but applies to any OS when running as daemon)

Activity

  1. github-actions commented on Jan 25, 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.

  2. adamdotdevin commented on Jan 27, 2026

    @adamdotdevin
    Member

    This will be resolved in today's release:
    a8c18db
    1f93138

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

Metadata

Metadata

Assignees

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