Breaking down open-source coding Agents: Codex, OpenCode, goose
This section is about reading source code. All three projects are open-source terminal or desktop coding Agents: OpenAI's Codex CLI (Rust, Apache-2.0), OpenCode (TypeScript, MIT; we read the new architecture as of 2.3.0), and goose (Rust, Apache-2.0, 1.60.0, now a project of the Linux Foundation's AAIF). We cloned them on 2026-11-20; the file paths and line numbers below all correspond to that version.
You'll find that the core loop is almost identical to what you wrote — the differences all lie in the "brakes" and engineering details.
1. The loop: all of them are "keep going while tools are still needed"
Codex's loop (codex-rs/core/src/session/turn.rs) uses a single variable to decide whether to run another round:
let needs_follow_up = model_needs_follow_up || has_pending_input;If the model wants to call tools, or the user interjects something new mid-run, it continues; otherwise break. This is the same thing as myagent's if not msg.tool_calls: return.
OpenCode calls it needsContinuation (true if this step contains locally executed tool calls), and goose calls it ends_turn (it ends when the last message is a reply with no tool requests).
The difference is in the brakes:
| Step limit | What happens at the limit | |
|---|---|---|
| myagent | 12 steps | Stops immediately, replies with "maximum number of steps exceeded" |
| OpenCode | No limit by default; you can set steps per Agent | Turns off tools (toolChoice: "none") and adds a "maximum steps reached" prompt, forcing the model to summarize progress in words |
| goose | GOOSE_MAX_TURNS defaults to 1000 | Yields control and asks the user whether to continue |
| Codex | We could not find a step limit in the source code | — |
OpenCode's approach is better than ours: cutting off directly loses the progress, while letting the model write a summary in the final step means the user at least knows where things got to.
2. Permissions: from y/N to "rules table + review + sandbox"
Look it upTheir permissions…
Click one to see.
goose's smart_approve, the review model of the Grok Bot from the previous section, and OpenClaw's auto tier share the same idea: decide automatically what can be decided automatically, and only ask a human when unsure.
3. Compaction: same idea as your compact(), plus three extra things
| When compaction starts | |
|---|---|
| myagent | When the conversation exceeds 24000 characters |
| Codex | 90% of the context window |
| OpenCode | Window minus max(15%, 16k tokens) |
| goose | 0.8 of the window |
| OpenClaw | Starts maintaining at about 75% |
The production-grade approach adds three things:
- Measure in tokens, not character counts.
- Write the summary as a "handover note". The first sentence of Codex's compaction prompt (
codex-rs/prompts/templates/compact/prompt.md):
You are performing a CONTEXT CHECKPOINT COMPACTION. Create a handoff summary for another LLM that will resume the task.
Include:
- Current progress and key decisions made
- Important context, constraints, or user preferences
- What remains to be done (clear next steps)
- Any critical data, examples, or references needed to continueOpenCode also requires the summary to be "handed to another Agent to continue", and specifies fixed sections such as goal, decisions, and next steps.
- Don't split tool calls from their results. Like the while loop in our compact(), all of them handle this.
4. Instruction files and skills: AGENTS.md and load_skill
Almost all of them read AGENTS.md (project instructions written for the Agent):
- Codex: reads layer by layer from the git root down to the current directory and concatenates them, with a total cap of 32 KiB; if
AGENTS.override.mdexists at the same level, it takes priority. - OpenCode: looks for AGENTS.md, falling back to CLAUDE.md when the same directory has none.
- goose: reads
.goosehintsand AGENTS.md.
As for skills, goose's tool name is exactly the same as ours, called load_skill (crates/oi-kit-agent/src/skills/operation.rs):
fn load_skill_tool() -> Tool {
Tool::new(
LOAD_SKILL_TOOL_NAME,
"Load a skill's full content into your context so you can follow its instructions.\n\n\
Skills are listed in your system instructions. When you need to use one, \
load it first to get the detailed instructions.",
schema_for_type::<LoadSkillParams>(),
)
}What you wrote in Chapter 2 is the industry's mainstream practice.
5. MCP: the universal socket for everyone
All three projects support MCP: Codex is configured under config.toml's [mcp_servers.名字]; OpenCode configures local / remote in opencode.json; goose is the most thorough — all tools go through MCP, each extension is an MCP client, and tool names get an "extension name__tool name" prefix.
Hands-on: add three things to myagent by following their examples
- 1?
- 2?
- 3?
Click them one by one, in order.
A reference implementation for the first one:
agents_md = Path("AGENTS.md")
if agents_md.exists():
SYSTEM += "\n\n项目说明(AGENTS.md):\n" + agents_md.read_text(encoding="utf-8")[:8000]Quiz timeAfter reading the source code of all three projects, how does the Agent's core loop compare to the myagent you wrote?
Check yourself
- I can explain how each of the three projects handles "reaching the step limit"
- I can state their compaction thresholds, and why the summary is written as a "handover note"
- I added at least one learned feature to myagent
Go back to FAQ, or head to the OpenClaw course and the Grok Bot course to put these designs to use.