r/opencodeCLI • • 1d ago

Code Mode is great

https://github.com/anomalyco/opencode/blob/dev/packages/codemode/README.md
156 Upvotes

22 comments sorted by

54

u/megablue 1d ago edited 23h ago

brief description of what it does

- instead of the agent calling the tools directly, code mode let the agent write a short script to do a batch/netested call of the tools so that there are less back-and-forth calls between the harness and LLM.

to enable it
add following to opencode.json

"experimental": { "full_codemode": true }

-7

u/Kyxstrez 19h ago

4

u/megablue 18h ago

uh... ok?

10

u/james__jam 17h ago

Claude code did not introduced this. Cloudflare did last year. In fact, both claude code and opencode are late in the game. Goose had this since Dec 2025. Codex since March 2026, pi and droid since last month.

-2

u/Kyxstrez 17h ago

I'm aware, I was just pointing out since OP made it sound like it's a big deal. Opencode didn't invent anything here.

2

u/james__jam 16h ago

What are you aware of? That opencode has had it experimental since a few months ago and it’s now officially on since last month and that claude code had just introduced it as experimental 10 days ago?

Yes, code mode is old news. You could have mentioned pi, or codex or something else, but you chose to mention the tool that is the most late in the game

-1

u/tactic-impress-55 14h ago

raisins have fiber and sugar. maybe you need some right now

26

u/AlmostEasy89 23h ago

Cloudflare has been doing this for quite some time. It’s great. Every one of my MCPs goes behind a Cloudflare mcp portal with code mode enabled by default. That one connection provides any mcp client with every mcp you have behind the portal.

3

u/ECrispy 20h ago

Every one of my MCPs goes behind a Cloudflare mcp portal with code mode enabled by default. That one connection provides any mcp client with every mcp you have behind the portal.

can you give some more details? is this on their free tier?

2

u/AlmostEasy89 16h ago

First google result for Cloudflare MCP Portals: https://developers.cloudflare.com/cloudflare-one/access-controls/ai-controls/mcp-portals/

Lookit how easy that is 😉

1

u/FailedGradAdmissions 16h ago

Do you this with subscriptions? How do you route the requests then?

1

u/AlmostEasy89 10m ago

Cloudflare has 2 GUI controls. MCP Portals and MCP Servers.

MCP servers you just place the http transport URL like https://saasiuse.com/mcp and then choose auth method. Auth login is the usual. Custom headers you can use API/bearer token so it's a permanent access that doesn't expire.

So say you add 20 of those.

Then you can add 2..3..20 to ONE MCP Portal to say ChatGPT or Claude code or OpenCode, whatever.

That MCP client (ChatGPT and Claude code are MCP clients) then only needs you to add 1 MCP to it. The client then only sees 5 tools. Essentially the ones you use are tool_search and then tool_execute or something like that. Another is toggle servers on/off.

So in context you don't keep 800 tools every turn. You keep 5 and it can search and execute the tools it needs.

I have 2 Google Workspace accounts for my business. Google fucking finally released an MCP for it's main products. Mail, Docs, Drive, Sheets, Slides, Workspace Search etc. Being Google, it was a massive pain in the ass to set that up but once I did, I had 7-8 MCPs per workspace and added a Google Admin portal and Google Support portal. Many clients have Google stuff built in nowadays but now I have a portable, fully accessible suite of Google MCPs and Portals that I can take with me wherever I go and will always be mine and will always work.

I could add them all to one portal, or multiple, or mix and match. For terminal clients I have one huge MCP Portal. For ChatGPT Business chats I have a Marketing Portal, Operations Portal, Google Workspace Portal etc just for scoping access.

I think it's obfuscation by complexity with Cloudflare because idk why this isn't the most popular AI companion software for everyone. It's a game changer.

1

u/stvn_wthrsp 14m ago

To be clear, the MCP Portal Code Mode is a bit different than the harness implementations. The naming is kind of poor. I like to clarify this because they have different benefits, you can use one without getting the benefit of the other. Ideally you should use both.

Code Mode in a harness means scripting tool calls, so instead of calling read/edit/bash/etc. it all becomes a single "execute" tool. The benefit here is that it reduces turns and therefore time spent.

Cloudflare MCP Portal Code Mode implements a "search-and-execute" pattern for tool calling, and is called "tool optimization" by other MCP gateways like Toolhive. Without this feature, every tool connected via MCP injects it's full instructions into the context. The benefit here is reduced context and token usage when you have a lot of tools connected.

1

u/AlmostEasy89 8m ago

Yes, you are correct. Codemode writes JavaScript in a sandbox to execute commands while search and execute is different. I believe the MCP Portals have both but also it names it codemode directly in the Cloudflare GUI for some reason. So it operates via codemode for execution but it is also a search and execute style MCP.

I should also note too Cloudflare CLI 'cf cli' release candidate 1 has shipped so setting these up is significantly easier via terminal than it was before. This is separate from wrangler.

Cloudflares support agent is Kimi using codemode and is essentially an unlimited open model agent that has access to your Cloudflare account and can create complete repos you can download and configure of Cloudflare primitives. Workers, D1, durable objects. It's wild lol. Cloudflare gives away so much for free.

1

u/stvn_wthrsp 0m ago

MCP Portals is not an agent harness itself, so it only "has" the search-and-execute pattern. The portal is indeed compatible with the OpenCode (and other harness) codemode for the JavaScript execution, though.

Within the Cloudflare ecosystem, their Agents do also support the harness Code Mode, the scripted tool-use pattern. Here's their 2 documentation pages showing their entirely different definitions of Code Mode!

https://developers.cloudflare.com/agents/tools/codemode/ https://developers.cloudflare.com/cloudflare-one/access-controls/ai-controls/mcp-portals/#code-mode

0

u/Amarsir 22h ago

Also kind of a big deal when Claude Code started doing it not long ago.

4

u/AlmostEasy89 22h ago

Yes. It’s absolutely a game changer. The portability of my portals was amazing as well. Skills-over-mcp is coming as well. Good times!

1

u/SamPlaysKeys 17h ago

Skills over mcp is also part of Aperture, a tool created by the same team that made Tailscale. It proxies your API keys as well, so you don't have to share those with a harness.

1

u/AlmostEasy89 16h ago

Oh shit. I'll check that out. Highly recommend Toolport for local MCPs as well. With an MCP Tunnel and Toolport you can use your local MCPs via ChatGPT lol it's wild. ChatGPT using playwright on my laptops browser is a trip and a half.

1

u/squirrelscrush 11h ago

I thought it was already enabled lol

1

u/Melodic_Reality_646 2h ago

Isn’t this what smolagents from HF does?