r/opencodeCLI • • 10d ago

Code Mode is great

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

25 comments sorted by

View all comments

Show parent comment

1

u/stvn_wthrsp 9d 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.

2

u/AlmostEasy89 9d 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 9d 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

1

u/AlmostEasy89 9d ago

Codemode isn't a harness either. It's a tool use pattern. Their harnesses are Think, Pi, OpenCode. Their agents can use codemode as a tool.

And wow i just checked, they've added even more harnesses. Cloudflare is fucking cooking lol.