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]: execute (Code Mode) runtime has no CommonJS require() — require('fs') throws ReferenceError · Issue #56811 · anomalyco/opencode

[Bug]: execute (Code Mode) runtime has no CommonJS require() — require('fs') throws ReferenceError #56811

New issue
Copy link
New issue
Copy link
Closed
Closed
[Bug]: execute (Code Mode) runtime has no CommonJS require() — require('fs') throws ReferenceError#56811
Copy link

Description

@dimahc
dimahc
opened on Oct 18, 2026
Issue body actions

Summary

The execute tool's confined Code Mode runtime does not expose CommonJS require(). Any snippet that calls require('fs'), require('child_process'), etc. fails with:

ReferenceError: Unknown identifier 'require'. (line 1, col 12)

Reproduction

Call execute with:

const fs = require('fs');
console.log(fs.readdirSync('.'));

Expected: directory listing.
Actual: ReferenceError: Unknown identifier 'require'. (line 1, col 12)

Tool-description mismatch

The tool description states: "Imports, direct filesystem access, and timers are unavailable; all other external access goes through tools." That is only partially accurate — fetch is available, but require() is not available at all, so even pure logic that happens to load a module cannot run. Users are left guessing which globals exist.

Impact

Many realistic scripting workflows in Code Mode are blocked outright (reading files, spawning processes, path math). The gap is undocumented and not discoverable from the tool description.

Suggested fix

Either:

  • expose a minimal require() shim for node built-in modules (fs, path, child_process, os), or
  • document the limitation clearly in the tool description and ship a stable tools.* filesystem/process helper so users are not left guessing.

Environment

  • Host: OpenCode (anomalyco/opencode), plugin oh-my-opencode-slim loaded.

Activity

  1. dimahc
    changed the title [-][Bug]: execute (Code Mode) runtime has no CommonJS — throws ReferenceError[/-] [+][Bug]: execute (Code Mode) runtime has no CommonJS require() — require('fs') throws ReferenceError[/+] on Oct 18, 2026
  2. opencode-agent commented on Oct 18, 2026

    @opencode-agent
    opencode-agentBot
    on Oct 18, 2026 – with OpenCode Agent
    Contributor
    More actions

    Thanks for the detailed write-up, @dimahc!

    This is intended behaviour, not a bug. Code Mode's execute runs in OpenCode's own sandboxed JavaScript interpreter, not in Node. It deliberately has no module system (require/import), so access to files and processes goes through the tools in the Code Mode catalog, where OpenCode's permissions still apply. The tool description already says "Imports, direct filesystem access, and timers are unavailable", which is why require shows up as an unknown identifier.

    I'm treating this as a feature request with two possible directions:

    • a require shim for Node built-ins (fs, path, child_process, os) inside Code Mode, or
    • a clearer description of which globals are available, plus reliable filesystem/process helpers under tools.*.

    Maintainers will consider it. In the meantime, the regular file and shell tools (outside execute, or through tools.* when they're listed in the Code Mode catalog) are the way to read files and run commands.

    Related issues and PRs:

    • feat(codemode): expose host classes and functions through extensions #48941: exposing host classes and functions to Code Mode through extensions
    • feat(core): expose fetch to code mode scripts #49235: how fetch was added to Code Mode
    • fix(core): gate Code Mode fetch on the webfetch permission #54976: gating Code Mode fetch on the webfetch permission
    • "Unknown identifier query" in Code Mode with MCP tools #49115: a different Unknown identifier error in Code Mode
  3. dimahc
    closed this as completedon Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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.