opencode icon indicating copy to clipboard operation
opencode copied to clipboard

BIG BUG! OpenCode The software mistakenly wrote a total of about 130GB of files to my disk

Open fuqicn opened this issue 6 days ago • 12 comments

Description

The software mistakenly wrote a total of about 130GB of files to my disk

Plugins

no third-party plugins

OpenCode version

2.4.2

Steps to reproduce

I do not know,I just use it to do work

Screenshot

<img width="1920" height="1149" alt="屏幕截图 2026-11-29 182202" src="https://github.com/user-attachments/assets/ccd81bd0-02f8

屏幕截图 2026-11-29 182334

-4686-8ca7-80588f7e12e9" />

Operating System

Windows11

Terminal

Windows powershell

fuqicn avatar Nov 29 '26 10:11 fuqicn

Thanks for reporting this. Losing 130 GB of disk is serious and we want to find the cause. The report doesn't yet show where the files are, so could you add:

  1. Where the files are: the full folder path, and a few example file names and sizes. For example, are they inside your project folder, or in OpenCode's own data folder under your user profile?
  2. What created them: do they look like OpenCode's internal data (a database, a git-like objects/pack folder, temp files), or output from a command or script the agent ran during your session?
  3. How you run OpenCode: the terminal (TUI) in PowerShell or the desktop app, and the provider and model you used.
  4. The screenshots: the first image link in the issue is broken (its URL got split by the text around it). Could you upload it again?

You can reply here with the details or edit the issue. If you edit it, please also leave a comment saying you've updated it, so we know when you're done editing.

These existing reports may be related, ordered from most to least likely. Please check whether one of them matches what you see:

  • #65127: the snapshot store (used by undo) grew to 90 GB by including git-ignored and large files
  • #55010: the snapshot repository grew by 15 GB in hours, with loose objects and temp files left behind
  • #47223: opencode.db grew to 73 GB, mostly its event table
  • #36831: orphaned opencode-wal-*.db files piled up in the temp folder
  • #54292: an agent command filled a disk on its own

opencodejr[bot] avatar Nov 29 '26 10:11 opencodejr[bot]

in C:\Users\fuqi.local\share\opencode\shell,not only opencode.db,almost every things in the"shell"was very big,I have deleate them,Because I need to use my computer

fuqicn avatar Nov 29 '26 10:11 fuqicn

and there are many big files in npm cache

fuqicn avatar Nov 29 '26 10:11 fuqicn

屏幕截图 2026-11-29 182202

fuqicn avatar Nov 29 '26 10:11 fuqicn

opencode.log here is the log,I think I can't give you more information,because i have deleated them

fuqicn avatar Nov 29 '26 10:11 fuqicn

Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.

Thanks for the extra detail about the shell folder. It let us reproduce this.

That folder holds a file with the output of each shell command the agent runs. On 2.4.2, with a simulated model, one command that printed about 500 MB left a file of exactly 500,000,000 bytes in shell/<project>/. Only about 52 KB of that output was sent to the model. Nothing limits the file's size, so a few commands with very large or endless output (a verbose build, a watcher, a runaway loop) can fill a disk, which fits what you saw. It still happens on the latest dev (1564bd5).

To be clear about what this covers: we ran on Linux, not Windows, with a simulated model in place of a real one; the shell command and the file writing were the real ones. It doesn't explain a large opencode.db, which is stored elsewhere.

The script and recording below show the steps. Related: #62678 is about the same files being indexed by Windows Search.

https://anoma.ly/team/github-bot/media/8eee8496e093f2823a9f1ec790a022308275e47a4878c05d72480b8adcc7e229.mp4

Screenshot

Reproduction script (drive.ts)
// Repro for anomalyco/opencode#67112: a shell tool call's full output is written to
// <data>/shell/<project>/sh_*.out with no size cap, while the model only gets a truncated tail.
// Run: OPENCODE_DRIVE_MEDIA_DIR=/workspace/media opencode-drive run ./drive.ts   (OC_DEV=<checkout> to run from source)
import { Effect, Stream } from "effect"
import { execSync } from "node:child_process"
import { Llm, OpenCodeDriver } from "opencode-drive"

// ~500 MB of output from one ordinary command (a verbose build/test or a runaway loop behaves the same).
const COMMAND = "yes 'build log line: compiling module xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' | head -c 500000000"

const spoolFiles = () =>
  execSync(
    "find / -xdev -path '*/shell/*' -name 'sh_*.out' -mmin -10 -printf '%s bytes  %p\\n' 2>/dev/null || true",
  ).toString()

let toolResultChars = -1

export default OpenCodeDriver.use(
  {
    ...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
    project: { git: true, files: { "README.md": "demo\n" } },
    tui: { recording: true },
  },
  ({ ui, llm }) =>
    Effect.gen(function* () {
      yield* llm.serve((req) => {
        const body = JSON.stringify(req)
        if (body.includes("Reply with only the title")) return Stream.make(Llm.text("Build"))
        const messages: Array<{ role: string; content: unknown }> = (req as any).body?.messages ?? []
        const tool = messages.find((m) => m.role === "tool")
        if (!tool)
          return Stream.make(
            Llm.toolCall({ index: 0, id: "call_build", name: "shell", input: { command: COMMAND } }),
            Llm.finish("tool-calls"),
          )
        toolResultChars = JSON.stringify(tool.content).length
        return Stream.make(Llm.text("The build finished."))
      })
      yield* ui.submit("Run the build")
      yield* ui.waitFor("The build finished.", { timeout: 120_000 }).pipe(
        Effect.catch(() => Effect.void),
      )
      yield* Effect.sleep("3 seconds")
      yield* ui.screenshot("after-build")
      yield* Effect.log(`tool result sent to the model: ${toolResultChars} chars`)
      yield* Effect.log(`shell spool files on disk:\n${spoolFiles()}`)
    }),
)

Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.

opencodejr[bot] avatar Nov 29 '26 10:11 opencodejr[bot]

ok,thank you to help me to know and solve the problem. maybe you need to solve it quickly

fuqicn avatar Nov 29 '26 10:11 fuqicn

I'd like to take a stab at this. Root cause looks like the pipe reader in packages/process-daemon/src/service/pipe.rs writing every byte to outputPath with no cap — a single command printing 500 MB left a 500 MB file.

Proposed fix: cap the output file at 10 MiB, close it at the cap, and reuse the existing OutputFileFailed path so the client reports the file stopped early. I've pushed a branch with the change and a regression test; I'll open a PR against dev.

realbarusu avatar Nov 29 '26 11:11 realbarusu

Confirmed, and your second screenshot pins down where it went: the shell folder at C:\Users\fuqi\.local\share\opencode\shell holds 105 GB in 90 files. That is OpenCode's retained shell-command output, not the snapshot store or the database, so the snapshot issues listed above are a different problem.

The mechanism: every shell command's combined stdout/stderr is written to <data>/shell/<project>/<id>.out with no size bound, on both the daemon path and the direct-spawn path. The only cleanup is the hourly sweep, and it only removes files older than 7 days. Nothing ever reads most of those bytes back: the model only ever sees the last 50 KiB of a result. So a week of chatty commands, or a long-running background command that keeps logging, can fill a disk with no warning.

I reproduced the shape of it locally: three recent output files totalling 6 MB all survive Shell.cleanup() untouched, because the sweep is age-only.

Fix is ready on fanyzp/opencode branch shell-output-cap (commit fdb8ad7c): the same hourly sweep now also evicts the oldest finished outputs first until the whole shell folder fits a 1 GiB total. Files belonging to running commands are never touched. Regression tests cover the eviction order and the running-command exemption.

One thing that would still help confirm the picture on your side: are any of those 90 files from a long-running background command (dev server, watcher, something that logs continuously)? That would explain reaching 105 GB inside the 7-day window.

fanyzp avatar Nov 29 '26 11:11 fanyzp

Update: Critical Context on the Timeline! @fanyzp @realbarusu

I just realized something extremely important: This did NOT take several days. It happened in just a few hours today!

Here is the exact timeline of the disaster:

This morning, I updated OpenCode to version 2.4.2.

I gave the agent a task to fix a bug in my program (missing icon in file explorer).

The agent got stuck in a loop and started manually parsing PE (Portable Executable) files via shell commands to find the icon.

I left it running in the background for a few hours.

When I came back, it was still running. I stopped the agent, and realized my C: drive had lost 270 GB of free space (only 7GB left). WizTree showed a 105.8 GB .out file in the shell folder.

Conclusion: The 7-day age-only cleanup mechanism is completely useless for this scenario. A single runaway agent parsing binary files can fill up a disk in just a few hours.

Your proposed fixes (capping the file at 10 MiB or setting a 1 GiB total folder limit) are absolutely critical and must be implemented ASAP. If an agent goes rogue or writes an infinite loop, users will lose their system in half a day.

fuqicn avatar Nov 29 '26 11:11 fuqicn

Thanks, the screenshot and log help a lot, and you don't need to send anything else.

The screenshot confirms what we reproduced above: almost all of the space was one file, shell\589e…\sh_225fe455d001dXJ5Ah4uF23lHu.out, at 105.8 GB. OpenCode stores the output of each shell command the agent runs in that shell folder. In the code I read, the output goes into the file as it arrives with no size limit, and the files are only cleaned up once they are 7 days old. So one command with huge or never-ending output can fill a disk by itself. I couldn't tell from the log which command produced that file.

About the npm cache (AppData\Local\npm-cache, about 17 GB): your log shows the agent running many npx --yes hyperframes@<version> … commands (render, check, lint, snapshot, preview) and npx electron-builder. npm keeps the packages it downloads for those commands in its own cache. That space is used by npm, not written by OpenCode. If you need it back, npm can clear its cache with npm cache clean --force.

The shell output problem is reproduced and handed to the maintainers, so the issue stays open.

opencodejr[bot] avatar Nov 29 '26 11:11 opencodejr[bot]

Same root cause confirmed on Windows, at much larger scale than the repro.

Environment:

  • opencode version: 0.0.0-dev-1381 (dev channel)
  • Client: desktop app (shared background service) + TUI
  • OS: Windows_NT 10.0.26300 (win32 x64)

What happened:

~/.local/share/opencode/shell/<session>/ grew to 113 GB. Two individual sh_*.out files were 68.3 GB and 47.5 GB — full stdout captures of two shell commands on a single evening (2026-11-30). The truncated output shown to the model was tiny by comparison. Nothing warns the user and there is no retention/cleanup, so the files stay forever. Normal-size .out files from older sessions also accumulate indefinitely (346 files over a few weeks, no GC). Total freed after manual cleanup: ~118 GB (incl. ~5 GB of Temp/opencode scratch dirs from past sessions and 311 MB of browser-exports).

Workaround: redirect large command output to a file instead of stdout, or delete shell/<session>/sh_*.out manually. Cleanup had no side effects for current sessions; older sessions only lose the ability to re-read full outputs.

If it helps triage: the two giant files came from long-running commands whose stdout kept streaming (the tool result only carried a fullOutputPath reference). A per-file size cap (e.g. 100 MB) with a warning when exceeded, and/or retention for outputs of old sessions, would have prevented ~118 GB of silent disk usage.

cepice avatar Dec 01 '26 22:12 cepice

Independent reproduction on opencode v2.4.4

I can reproduce the .out disk-growth mechanism in #67112. This is not model output, a damaged project, a GGUF file, or PhotoRec-specific corruption. The core issue is generic shell capture. I am adding details here rather than opening a duplicate.

Report prepared by an AI assistant under human supervision.

Environment

  • opencode v2.4.4, latest
  • OpenCode Desktop + built-in shell tool + background shell service
  • Linux x86_64, Manjaro family
  • /bin/bash, TERM=xterm-256color, COLORTERM=truecolor
  • model/provider not relevant
  • no custom plugins in the minimal reproduction
  • empty disposable project; scratch output filesystem

Minimal reproduction

  1. Start clean opencode v2.4.4 with no custom plugins.

  2. Open an empty disposable project.

  3. Use a disposable scratch filesystem for shell output.

  4. Invoke the built-in shell tool with timeout 120000 ms:

    yes "opencode-output-cap-repro"
    

    Do not add head, timeout, kill, ... | head -c ..., or any external output cap.

  5. While it runs, inspect matching .out size with stat -c '%s %n' ... and df, without reading the whole file.

  6. Let timeout expire; inspect whether the process was killed or moved to background and whether output continues.

  7. Stop the producer manually for test cleanup. No deletion/wiping is required to reproduce.

Expected

  • .out <= configured hard byte limit; recommended default 1 MiB = 1048576 bytes.
  • Excess output truncated safely; no partial overshoot; byte offsets remain correct.
  • Output capture stops; producer and child processes are stopped safely; no orphan remains writing.
  • Standard OutputFileFailed / output_error; reason output exceeded 1048576 byte capture limit.
  • Explicit, non-silent truncation and retained-output path.
  • Explicit timeout/background/killed state; no confusion with ordinary preview truncation.

Actual

  • yes outputs forever; .out has no byte cap and can consume all free space.
  • Model receives bounded/truncated preview; fullOutputPath refers to complete/growing output, not bounded output.
  • MAX_LINES=2000, MAX_BYTES=50*1024, MAX_RESULT_BYTES=64*1024*1024, tool_output.max_lines, and tool_output.max_bytes affect result selection/reading only.
  • A direct foreground timeout can move command to background, not kill it. Background output continues streaming to .out.
  • Output-file failure is discovered only when OutputFileFailed fires. Typical output is [output file <FILE> stopped early: <error>]; No space left on device, ENOSPC, os error 28, WriteZero, or read error can occur after disk is already full.
  • Upstream output-file failure does not itself guarantee producer termination.

Full-screen TUI case

PhotoRec 7.2 can be launched through OpenCode shell without changing a source disk. No scan needs to occur to trigger .out growth. Conceptually:

pkexec photorec <SOURCE_DEVICE> 2>&1

<SOURCE_DEVICE> is a sanitized placeholder; real device and recovery details are intentionally omitted.

Observed in the original sanitized case:

  • PhotoRec 7.2, no interactive Proceed in the non-interactive shell;
  • stuck at disk-identification/media-selection, no scan started;
  • no recup_dir*, no GGUF, no recovered model;
  • repeated full-screen redraw with ANSI terminal controls, CR, LF, CRLF;
  • 2>&1 merges stderr into captured output;
  • per-command .out reaches exactly 3,445,493,637 bytes, about 3.21 GiB;
  • output begins with PhotoRec banner, not GGUF magic;
  • no useful recovery output is required to create disk pressure.

A separate ordinary yes test also produces unbounded .out, confirming this is not a PhotoRec parser issue. No unique local diagnostics or artifact attachments are needed.

Root cause in current source

packages/core/src/shell/capture.ts

  • createWriteStream(storagePath, { mode: 0o600 });
  • every chunk goes to stream.write(chunk);
  • no CAPTURE_LIMIT_BYTES, MAX_OUTPUT_FILE_BYTES, truncation threshold, or write-stop;
  • writes stop only if stream itself errors.

packages/process-daemon/src/service/pipe.rs

  • pipe reader writes output file before actor forwarding; output file is complete copy;
  • OutputSink::write has no output-file byte ceiling;
  • write_counting writes chunks; Ok(0) becomes WriteZero;
  • write_counting failure sends ActorMessage::OutputFileFailed("failed to write output file: <error>"), orders event before output, sets self.file = None, but does not itself prove process kill;
  • on write error knownSize / newlines can become unknown; later output cannot be retained.

packages/core/src/tool/plugin/shell.ts

  • fullOutputPath: file with full output when truncated or background;
  • output path shown to model does not imply bounded file;
  • timeout stops waiting; direct foreground can jobs.background; no hard kill at timeout;
  • background still streams output to .out;
  • shell is non-interactive with closed stdin; raw output is not sanitized;
  • killed, signal, timeout, output file stopped early, and truncated are distinct states.

packages/core/src/shell.ts and packages/core/src/shell/result.ts

  • formatStoppedEarly emits [output file <FILE> stopped early: <error>];
  • output truncated means preview/result truncation, not output-file write cap;
  • OutputFileFailed / output_error means output-file stopped early, not command success;
  • output file stopped early should not be confused with killed-only or killed-by-output-limit.

v2.4.4 retention

Official changelog says:

Kept both the start and end of long shell output when truncating,
renamed the shell result field `outputPath` to `fullOutputPath`,
and stopped deleting saved shell output when old commands are evicted.

Related merged PRs: #67159, #67421, #67666.

  • EXITED_LIMIT=25 limits listed exited commands, not bytes;
  • eviction no longer unlinks .out;
  • automatic retention found is seven-day FileRetention.cleanup, not per-file byte bound;
  • terminatePipe leaves output file alone; explicit removal is separate;
  • .out itself is outside source project, but still consumes disk.

v2.4.4 does not introduce infinite PhotoRec output; it amplifies persistence. Unbounded per-file growth was already possible in shell capture.

Existing related upstream items

  • #67112 matching issue, OPEN, severity:high, type/bug.
  • #67115 fix(process-daemon): cap pipe output file at 10 MiB, Fixes #67112, closed/not merged. Verified proposed 10 MiB, not merged; request evaluation against invariants below. 1 MiB default is suggested independently, not claimed upstream.
  • #9808 feat: Support for sudo and password-requiring commands in Bash tool, closed not_planned; related non-interactive shell + terminal issue, not itself proof of .out growth.
  • #67421 outputPath -> fullOutputPath, merged.
  • #67159 preserve start+end output, merged.
  • #67666 no output deletion on eviction + seven-day retention, merged.

Interactive handling can remain a separate issue. Please fix output-file bounding first. Do not block interactive/privileged commands; real TTY or explicit non-interactive mode should be selected independently.

Suggested invariant

per-command combined captured output bytes <= configured hard limit

Recommended configurable default 1048576, unchanged by model display truncation. Preserve retained first bytes; truncate excess; account for partial writes; safe end()/close before any subsequent read; no invalid false output; no silent truncation.

Order at output limit:

write at most limit
-> stop reading
-> close output
-> emit OutputFileFailed(output exceeded 1048576 byte capture limit)
-> stop producer and children safely
-> publish killed/signal where known
-> return bounded output + explicit next bounded commands

On Unix terminate producer process group, escalate SIGTERM -> SIGKILL, do not kill unrelated processes. Use Windows job/process-tree equivalent. Do not rely on SIGPIPE, and handle producers ignoring SIGPIPE/SIGTERM. No orphan. Do not require operator rescue. Keep ordinary truncated, killed, output-error, timeout, and output-limit separate. No command should be blocked.

Suggested regression tests

  • yes forever; bounded time; .out <= limit; no extra bytes; output-limit error; no orphan.
  • producer ignores SIGPIPE; ignores SIGTERM; child in group; escalation; no orphan.
  • producer that ignores SIGPIPE and has no output reader response.
  • sizes limit-1, limit, limit+1, huge chunk, empty output, partial write, zero write.
  • UTF-8 split; CR/LF/CRLF; NUL; ANSI; TUI redraw; slow producer; stderr; 2>&1.
  • output-limit before timeout; timeout before output-limit; user cancel; restart; background; no false completion.
  • output ENOSPC, write error, zero write, read-only output directory; no false success; output-file state preserved; safe process handling.
  • multiple concurrent commands/subagents; eviction; retention does not bound file.
  • full-screen TUI that never exits and cannot receive Proceed; bounded + terminated; no auto-destructive input.
  • invalid limit values; no bypass; no command blocking.
  • retain existing shell-remote output-length and opencode-pty disk-failure tests; do not weaken tests.

Acceptance repro

clean v2.4.4 + no custom plugins + empty disposable project
  -> run `yes`
  -> `.out` stops at 1048576 bytes
  -> producer and children stopped
  -> `output exceeded 1048576 byte capture limit`
  -> no `full output saved` claim without verified retained output
  -> bounded model preview
  -> no disk-full

Privacy

No tokens/keys/authorization/cookies, private URLs, usernames in paths, account names, session IDs, project names, prompts, conversation text, source-file contents, model files, disk serials, source-device names, recovered filenames, or confidential data. No logs attached. No personal cleanup instructions. No agent deletion is part of this report. <SOURCE_DEVICE> is a placeholder.

Priority: output-file byte cap + safe process-group stop; no silent truncation. Separate follow-ups: full-screen PTY/interactive support and retention policy.

DScoNOIZ avatar Dec 04 '26 02:12 DScoNOIZ