Skip to content

Refuse to read a large file#2161

Closed
hujianxin wants to merge 1 commit into
anomalyco:devfrom
hujianxin:dev
Closed

Refuse to read a large file#2161
hujianxin wants to merge 1 commit into
anomalyco:devfrom
hujianxin:dev

Conversation

@hujianxin

@hujianxin hujianxin commented Aug 22, 2025

Copy link
Copy Markdown

• New file added: packages/opencode/src/file/context.ts - Implements file context tracking for sessions
• Modified: packages/opencode/src/tool/grep.ts - Added file context recording for grep operations
• Modified: packages/opencode/src/tool/read.ts - Added file size checking with context-aware logic and recording reads

These changes implement a file context tracking system that:

  1. Tracks which files have been read/grepped in each session
  2. Prevents direct reading of large files (>200KB) unless they've been previously searched
  3. Records file operations in session context

This is a feature enhancement that adds smarter file handling with size limitations based on context.

This small change can significantly improve the performance of opencode in large files (large projects), and will force opencode to use the grep tool instead of reading files mindlessly.

@hujianxin

hujianxin commented Aug 22, 2025

Copy link
Copy Markdown
Author

To be honest, I'm not good at TS. I just modified the program according to my own understanding and tested it in a 2 million line C++ project of mine. After the modification, the performance is much better than before, which allows OpenCode to successfully complete a feature development. If there are any problems with the code I wrote (such as concurrency issues, style issues, etc.), please give me some suggestions, or directly modify the code.

@hujianxin

Copy link
Copy Markdown
Author

IF you got a better about it, free to close

@hujianxin

Copy link
Copy Markdown
Author

I modified the pr, simplified the code, and made the logic of reading large files more consistent with Claude code. This helps force OpenCode to make smarter choices when reading large files. @thdxr

@hujianxin hujianxin closed this Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants