opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: add OPENCODE_DISABLE_FILETIME_CHECK flag

Open luojiyin1987 opened this issue 2 weeks ago • 0 comments

Summary

Adds a new environment variable OPENCODE_DISABLE_FILETIME_CHECK that allows users to skip the FileTime verification check before editing files.

Problem

Currently, OpenCode enforces that files must be read before editing, tracked by timestamps. This causes issues:

  • Time precision errors cause false positives when file wasn't actually modified
  • AI must re-read files that are already in context, wasting tokens
  • Users report 0.2s between read and edit still triggers error

Solution

Added OPENCODE_DISABLE_FILETIME_CHECK flag that:

  • When set to true: Skips all FileTime checks, allowing edits without re-reading
  • When not set or set to false: Maintains existing default behavior for safety

Changes

  • Added OPENCODE_DISABLE_FILETIME_CHECK constant in packages/opencode/src/flag/flag.ts
  • Modified FileTime.assert() in packages/opencode/src/file/time.ts to check flag
  • Added comprehensive tests in packages/opencode/test/file/time-flag.test.ts

Testing

All tests pass:

  • ✅ Flag enabled: FileTime check is skipped
  • ✅ Flag disabled: FileTime check is enforced
  • ✅ Default behavior: Read then assert works correctly

Usage

```bash

Temporary (single command)

OPENCODE_DISABLE_FILETIME_CHECK=true bun dev

Permanent (add to ~/.bashrc or ~/.zshrc)

export OPENCODE_DISABLE_FILETIME_CHECK=true ```

Trade-offs

This is a convenience vs safety trade-off:

  • Benefit: Eliminates token waste and unnecessary re-reads when context is available
  • Risk: Files modified externally won't trigger a warning, potentially missing external changes

Users who are confident in their workflow can enable this flag for better experience.

Closes #4406

luojiyin1987 avatar Jan 01 '26 15:01 luojiyin1987