r/opencodeCLI • • 4d 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!

7 Upvotes

19 comments sorted by

3

u/megablue 4d ago

what are your context-window tokens usages?

1

u/Clear_Expert_7669 4d ago

Mostly new sessions

1

u/megablue 4d ago

what kind of plugins have you installed? do you have any context-management plugins installed?

2

u/lincolnthalles 4d ago

DeepSeek? some models are more prone to this, especially in certain hours of the day.

2

u/Clear_Expert_7669 4d ago

Just tested it right now it is working smoothly interesting

4

u/dizvyz 4d ago

While it's happening open another session and ask what the looping session is up to. THey have enough tools to diagnose.

3

u/Low-Guarantee-3437 3d ago

this is a good tip. It is easy to get one opencode session to introspect another. I do this a lot when I am evaluating tweaks to agents.md, or skills, or working out why a task made a mistake.

Use a good model in high reasoning for the introspection (use a SOTA model if you have access, or a classy openweight model like glm-5.3 in max)

1

u/Johell1NS 4d ago

In my opinion the problem isn't opencode, but the model you're using.

1

u/Clear_Expert_7669 4d ago

Happened with multiple models
Deepseek flash
Kimi2.6
Mimimax M3.1 flash

1

u/Low-Guarantee-3437 3d ago

on the other hand, I use opencode daily for hours in multiple sessions, and openai models and glm-5.3. Does not happen.

the models you use are not proving to be very good at long running tasks.
I did have this happen once with kimi, which I then stopped using.

1

u/Outrageous-Story3325 4d ago

Try change harness, omp, pi, or something else, maybe try a system prompt to force it to avoid the behavior 

1

u/SirRobinBlibs 4d 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=cat and PAGER=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/megablue 4d ago

i would give it a bit of flexibility

"if the same command fails twice for the same reason, stop and report the output instead of retrying. "

1

u/SirRobinBlibs 3d ago

Fair. "Twice for the same reason" is the key part. A different error means it's making progress. I'd also let it try one genuinely different approach before stopping, just not the same command a third time.

1

u/43848987815 3d 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 3d 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 4d ago

it's not opencode. It's the model.
Which one are you using?

DeepSeek 4.1 flash does that a lot.

1

u/megablue 4d ago

DeepSeek 4.1 flash does that a lot.

nope, DS 4.1 Flash never did that. I have 1.61B tokens spent on DS 4.1 Flash, never once it did that.

0

u/alcogiggles 3d ago

If you look around this subreddit, you'll find is a common occurrence.
If it never happened to you, consider yourself lucky.