Skip to content

Snapshot feature needs safeguards for large directories (home directory filled disk) #8577

Closed
ariane-emory/opencode
#157

Description

@sahilchouksey

The snapshot feature runs git add . on the entire worktree without any size or path checks. When .git exists in a large directory (like home), this causes severe disk exhaustion.

What happened

  • Accidentally had .git in home directory (~)
  • Ran opencode . from home
  • Snapshot started tracking entire home directory (112GB)
  • Disk went from 44GB free → nearly 0 within minutes
  • CPU pinned at 100% from continuous git add .
  • System became unresponsive - couldn't make any changes, had to delete cache just to recover
  • Had to manually pkill -9 git processes and delete ~/.local/share/opencode/snapshot/

Root cause

packages/opencode/src/snapshot/index.ts:31:

await $`git --git-dir ${git} --work-tree ${Instance.worktree} add .`

No checks exist for:

  • Home directory (~, /home/*, /)
  • Directory size or file count
  • Disk space availability

Suggested fixes

  1. Block dangerous paths: Skip snapshot if worktree is $HOME, /home/*, or /
  2. Size threshold: Warn/skip if directory >1GB or >10k files
  3. Disk space check: Abort if available disk < 5GB
  4. User confirmation: Prompt before snapshotting unusually large directories

Activity

  1. added
    perfIndicates a performance issue or need for optimization
    on Jan 15, 2026
  2. github-actions commented on Jan 15, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Both issues describe the same root cause: the snapshot feature accumulating massive disk space without safeguards. Issue #6845 is an earlier report of the same problem with snapshot consuming extreme amounts of disk space.

    Feel free to ignore if your specific case differs from these existing reports.

  3. w32zhong commented on Mar 9, 2026

    @w32zhong

    We really need snapshot pruning. I am running out of disk space with long running opencode tasks.

  4. piknockyou commented on Sep 30, 2026

    @piknockyou

    The accidental-.git case in your report is worth a practical footnote for anyone landing here - I hit exactly that condition (a stray empty .git in the home folder) and it is fixable from the user side without waiting for safeguards:

    From the folder where you start opencode, run git rev-parse --show-toplevel.

    • If it prints your home folder (or another broad parent folder) instead of a real project: that repo is almost certainly accidental (usually zero commits) - delete that .git (rename it if unsure) and start opencode inside an actual project folder; the giant snapshot scan goes away with it.
    • If it prints a real project of yours: check git ls-files --others --exclude-standard | wc -l; if that is very large (100k+), get the heavy folders (node_modules, target, caches) into .gitignore, or set "snapshot": false.

    Deleting the stray ~/.git fixed it completely for me - same failure you describe (whole home tracked, disk gone, system unresponsive).

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

Metadata

Metadata

Assignees

Labels

perfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions