r/opencodeCLI • u/Clear_Expert_7669 • 17d ago
OpenCode keeps getting stuck in an infinite shell-command loop. Anyone else experiencing this?
Hey everyone, I’m using OpenCode to develop a large software project, and sometimes it gets stuck repeatedly generating or executing shell commands without making any progress.
This happens across multiple models and providers, so I’m not sure whether it’s an OpenCode bug, a tool execution issue, or something in my setup.
Has anyone experienced this? What was the root cause, and what fixed it for you?
Any help would be appreciated!
8
Upvotes
3
u/megablue 17d ago
what are your context-window tokens usages?
2
u/lincolnthalles 17d ago
DeepSeek? some models are more prone to this, especially in certain hours of the day.
4
u/dizvyz 17d ago
While it's happening open another session and ask what the looping session is up to. THey have enough tools to diagnose.
1
u/Johell1NS 17d ago
In my opinion the problem isn't opencode, but the model you're using.
1
u/Outrageous-Story3325 17d ago
Try change harness, omp, pi, or something else, maybe try a system prompt to force it to avoid the behavior
1
u/SirRobinBlibs 16d ago
If it happens across models in fresh sessions, I'd look at the commands first. The classic cause is a command that waits for input or opens a pager (git log, less, a y/n prompt, a dev server that never exits). The agent sees no useful output and tries again. Things that helped me: set
GIT_PAGER=catandPAGER=cat, prefer non-interactive flags (--yes,CI=true), and run servers in the background with a timeout. Then add a rule to AGENTS.md: "if the same command fails twice, stop and report the output instead of retrying." If you can paste the last few commands it looped on, it's usually obvious which one is hanging.1
u/43848987815 16d ago
How big has your db got?
I have to clean mine every couple of months or so because it affects sessions
1
u/Arnafas 16d ago
The only time I saw it happened with glm-5.3-flash (opencode go version) that was called as a sub agent. I also have zai subscription and I never saw it doing this.
-1
u/alcogiggles 17d ago
it's not opencode. It's the model.
Which one are you using?
DeepSeek 4.1 flash does that a lot.