agent-ops-patterns / gallery / opencode map / how it decides

How opencode decides

In opencode, the AI model chooses each next step, and a step normally ends the turn when it calls no local tool; plain code checks its tool calls, decides when older history is summarised, and decides from the agent's and session's rules whether an action runs, waits for you, or is refused. Nothing reads the final answer to check the work, and unless an agent sets a step limit, nothing caps how many steps a run takes.

From anomalyco/opencode at source version 0093fe57, mapped 2026-10-24. Each answer links the code where that decision is made.

What it does without asking you

How it decides it is done

Limits and memory

Other judgments

Three problems in the code

  1. 1. An agent's chosen model can be swapped for the default without a warning

    When a session has no model of its own and the model its agent is set up with is not among the available models, code uses the default model instead. Nothing tells you the agent is running on a different model from the one it was configured with.

    Not reported upstream, checked 2026-11-01.

    Where: model.ts:79-87. How we checked: the code was re-read at the source version named above; the sentences were checked by an independent AI reviewer from another company (OpenAI Codex, read-only) on 2026-11-01; every sentence it found too wide was rewritten or removed, and every rewrite was checked again.

  2. 2. A patch change goes to the first lines that match

    For the models that edit files through patches (some GPT models), each change is placed at the first spot, searching from the end of the previous change, where its lines match, trying looser matches (ignoring spaces at the ends of lines, then at both ends) when there is no exact match. If the same lines appear more than once, the change goes to the first of them; the edit tool that other models use returns that case to the model as a failure unless it was asked to replace every match.

    Not reported upstream, checked 2026-11-01.

    Where: patch.ts:344-360, patch.ts:311-342. How we checked: the code was re-read at the source version named above; the sentences were checked by an independent AI reviewer from another company (OpenAI Codex, read-only) on 2026-11-01; every sentence it found too wide was rewritten or removed, and every rewrite was checked again.

  3. 3. No default limit on a run that keeps repeating itself

    By default an agent has no step limit, and the map found no check in the current core for a model that keeps making the same tool calls, so a run whose repeated calls keep succeeding has no built-in limit and can go on until you stop it. opencode's tracker has an open discussion of this (#59339) and an open pull request that proposes loop detection.

    Reported; a fix is proposed, not merged (#53032), checked 2026-11-01.

    Where: llm.ts:224, agent.ts:39-52. How we checked: the code was re-read at the source version named above; the sentences were checked by an independent AI reviewer from another company (OpenAI Codex, read-only) on 2026-11-01; every sentence it found too wide was rewritten or removed, and every rewrite was checked again.

See the full map →

This card was taken from the published map of opencode at one commit and covers only decisions shown there; it did not look at opencode's hosted services or at code outside the parts the map covers (its core, command line, server and terminal interface), and no opencode code was run to make it.

Map: edition without a gap list or coverage figure, all 123 cards shown (issue states checked 2026-10-29) · taken from the full map · card data: gallery/cards/opencode.json. Found something wrong? Use the correction form.