High CPU usage
Description
I use opencode on MacOS ( Intel ) and after sometime the CPU usage keeps increasing. Even when session is idle, the CPU usage stays high.
My main usage is in 2 projects and I see the same behaviour in both.
- typescript, javascript, html app
- Dart / Flutter app
I don't use it anywhere else so not sure if this is related.
OpenCode version
1.0.110
Steps to reproduce
Unsure of the steps. Just keep using opencode, switch sessions, fork sessions etc
Screenshot and/or share link
Operating System
macOS 15.7.2
Terminal
iTerm2, CodeNomad
This issue might be a duplicate of existing issues. Please check:
- #811: Text rendering is VERY slow (and CPU usage is really high even when idle) - Closed but reports similar high CPU usage on idle
- #2688: Opencode freezes when pressing
option+ left arrow key on MacBook with high CPU usage - MacBook CPU spike issue - #2805: High RAM usage in latest release - Related to high resource usage
- #3013: Uses a huge amount of memory - Memory usage keeps increasing with AI use
- #3798: OpenTUI causes crashes and heavy memory usage - opentui related resource consumption
Feel free to ignore if none of these address your specific case.
do you have permissions turned on?
happens to me too
do you have permissions turned on?
No permissions aren't enabled in any of the projects
Just observed an agent running into this very issue on accident. Reproduction steps are as follows:
- Asked an agent to implement some feature and trigger a build / compile afterwards.
- Agent completed the implementation and compiled successfully, which caused our build output directory to fill up (and, due to a misconfiguration on my end, this directory is not in any .gitignore file or similar)
- Agent noticed the huge amount of new files after checking
git statusand decided to remove them usingrm -rf. - After freezing for about 30s, OpenCode's "Modified Files" sidebar started listing every single deleted file that previously existed in the now deleted directory. In this state, the TUI does not react to any key presses anymore and needs to be killed.
I submitted https://github.com/sst/opencode/pull/4963 to introduce pagination for this scenario.
are you sure the issue was the sidebar rendering and not the diff checking? just curious
Did you use btop to figure that out
The diff itself seems to be pretty fast - at least based on what I saw during debugging. I did not measure the timing though (also no btop). My first approach was to change the diff panel to be collapsed by default while leaving the diff logic itself unchanged. This immediately improved performance for me; at least until I manually expanded the panel again, which then caused a freeze as expected.
Ahh okay good to know
i'll take a look at the pr just wanted to make sure we address core issue
What I'm seeing is quite a bit different. If I tab away from the agent for a long time, then tab back, it's quite laggy - sometimes typing is very slow, and if I press enter it will send the message without everything I typed in there. And then it won't show the agent replying until some time later (after a delay). Often I Ctrl c out of open code then reopen it and go to the session to see that the agent indeed was working and I had just interrupted it midway due to the UI lag. Maybe opencode is trying to update the display constantly when nothing is changing (while tabbed out) and this all gets buffered somehow lagging out future updates? Just a guess.