Skip to content

getImageOutputDir: Support configurable image output directory via env var or config #16

Description

@expiren

Problem

getImageOutputDir() in src/plugin/image-saver.ts hardcodes the generated image output directory to ~/.opencode/generated-images/:

function getImageOutputDir(outputDir) {
    const resolved = outputDir ?? join(homedir(), '.opencode', 'generated-images');
    if (!existsSync(resolved)) mkdirSync(resolved, { recursive: true });
    return resolved;
}

There is no way to configure this path — no env var, no config option, no plugin hook on the output side.

Use Case

When using image generation subagents (e.g. task(category="image-generation")), generated images always land in ~/.opencode/generated-images/ regardless of the project context. Users working on specific projects (e.g. e-commerce product shots) need images saved directly to their project directory without manual copying after every generation.

Proposed Solution

Add process.env.OPENCODE_IMAGE_OUTPUT_DIR as a fallback before the hardcoded default:

function getImageOutputDir(outputDir) {
    const resolved = outputDir ?? process.env.OPENCODE_IMAGE_OUTPUT_DIR ?? join(homedir(), '.opencode', 'generated-images');
    if (!existsSync(resolved)) mkdirSync(resolved, { recursive: true });
    return resolved;
}

This is a one-line change that:

  • Maintains full backward compatibility (env var unset = same behavior as today)
  • Lets users set OPENCODE_IMAGE_OUTPUT_DIR globally or per-session
  • Enables plugins to dynamically redirect output by setting process.env.OPENCODE_IMAGE_OUTPUT_DIR in the same Node.js process (since the auth plugin and local plugins share the same runtime)

Current Workaround

We patch dist/src/plugin/image-saver.js and dist/index.js (both in node_modules and the Bun cache at ~/.cache/opencode/packages/@cortexkit/opencode-antigravity-auth@latest/) via a post-install script. The patch gets overwritten on every npm install and must be re-applied manually.

Environment

  • OpenCode on Windows (Bun runtime)
  • @cortexkit/opencode-antigravity-auth@latest
  • Node 26, Bun standalone binary

Note on Bun Cache

Bun loads the plugin from ~/.cache/opencode/packages/@cortexkit/opencode-antigravity-auth@latest/ rather than the project node_modules/, so patches to node_modules/ alone have no effect — the cache copy must also be patched. A native env var support in the source would eliminate this entirely.

Activity

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