Skip to content

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:

rust
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 limitWhat happens at the limit
myagent12 stepsStops immediately, replies with "maximum number of steps exceeded"
OpenCodeNo limit by default; you can set steps per AgentTurns off tools (toolChoice: "none") and adds a "maximum steps reached" prompt, forcing the model to summarize progress in words
gooseGOOSE_MAX_TURNS defaults to 1000Yields control and asks the user whether to continue
CodexWe 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
myagentWhen the conversation exceeds 24000 characters
Codex90% of the context window
OpenCodeWindow minus max(15%, 16k tokens)
goose0.8 of the window
OpenClawStarts maintaining at about 75%

The production-grade approach adds three things:

  1. Measure in tokens, not character counts.
  2. Write the summary as a "handover note". The first sentence of Codex's compaction prompt (codex-rs/prompts/templates/compact/prompt.md):
text
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 continue

OpenCode also requires the summary to be "handed to another Agent to continue", and specifies fixed sections such as goal, decisions, and next steps.

  1. 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.md exists 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 .goosehints and 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):

rust
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 ​

Line them upFrom easiest to hardest, add to myagent...
  1. 1?
  2. 2?
  3. 3?

Click them one by one, in order.

A reference implementation for the first one:

python
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.

gaodong.aiAboutPrivacyContact

Independent tutorials, not affiliated with any product mentioned. Product names and trademarks belong to their owners. Check official pages for prices and policies.