r/PiCodingAgent • • Oct 05 '26

Plugin How to Enable Codemode in Pi?

Yes, that's exactly what I searched first when i wanted to try codemode.

Pi does have docs for enabling Codemode, but the documented way is through settings or cli flags.

What I was looking for was much simpler: I'm already inside a Pi session, how do I just turn Codemode on or off?

So I ended up making a small toggle around Pi's native Codemode.

It doesn't replace Codemode or implement another version of it. It just gives me a simple way to switch the native tool on and off while I'm working.

check it out: pi-codemode-toggle

Curious how others are using Codemode.

41 Upvotes

23 comments sorted by

14

u/adamshand Oct 05 '26

The big surprise for me is that codemode is actually way easier to read than the way astra/sol have been writing python scripts for everything.

Don't think I'm ever turning codemode off!

2

u/Heavy-Focus-1964 Oct 05 '26

they write the most obfuscated Python imaginable

8

u/pcrz81 Oct 05 '26

I don't understand Codemode, i feel that i'm mising something great and that this extension seems useful. Please, could anybody explain me like i'm five with a usecase? Thanks!

42

u/rimaa_nahk Oct 05 '26

Codemode = let the agent write a tiny program to use tools, instead of calling tools one by one.

Before:

Agent -> search
Agent -> read file A
Agent -> read file B
Agent -> read file C
Agent -> compare results

After:

Agent -> writes small JS program
           |
           +-> search
           +-> read A/B/C in parallel
           +-> filter/combine results
           |
           v
        useful result only

Pi has to keep waking the LLM up to decide what to do next. And every intermediate result potentially occupies context. Codemode changes that. Pi can effectively write a little program like:

const matches = await tools.grep({
  pattern: "SystemOneProvider"
});

const files = unique(matches.map(x => x.file));

const contents = await Promise.all(
  files.map(file => tools.read({ path: file }))
);

const relevant = contents.map(...);

return relevant;

2

u/pcrz81 Oct 05 '26

Wow! Nice explanation. Thank you so much!!!!

13

u/ir210 Oct 05 '26

I think the best way to know about it is to just enable it and see what your model is doing with it.

I was also initially confused and didn’t understand what it is. The documentation didn’t help.

If I were to explain it, I would say, it’s a mechanism that allows your model to run multiple tools in one go. In theory, it also allows your model to write a script that processes the output and only feed the summary back to your model, for instance. It’s kinda similar to what it normally does with bash+python, only that codemode gives access to your harness internals in a sandboxed way.

3

u/pcrz81 Oct 05 '26

Thank you. I understand It better now!

9

u/VickWildman Oct 05 '26 edited Oct 05 '26

Without codemode: imagine you have a lot of tools and you describe all of them in the system prompt, so your model can use them. When your model uses a tool Pi executes it and puts it's output in the context. For example when your model knows it can use ketch to search the web, Pi executes the ketch binary and puts it's output in the context.

With codemode: your model only uses one tool, which is codemode. It lets the model write JavaScript code against an interface that the model can use to search for all the tools made available by MCP servers. That Javascript code is executed in QuickJS, an embedded JavaScript engine provided by Pi.  When the model uses a tool Pi calls it and allows it's output to be filtered by JavaScript or a classifier model like Jev before returning to the model. With codemode you can currently do filtering and potentially sandboxing too in the future. It also allows models to call tools asynchronously, in parallel. You don't have to list all the tools in the system prompt either, the model can just search for them (although currently a description of the tools is included, even if limited to a few thousand tokens).

→ More replies (4)

2

u/qehgt Oct 05 '26

tools.ts in example folder can enable/disable tools (including codemode) in run time.

1

u/rimaa_nahk Oct 05 '26

Great, and how is it usefull and handy in running session?

2

u/quinncom Oct 05 '26

Keep in mind that if you change tool definitions mid-session, it can break the prompt cache, resulting in higher API costs. Codemode is a tool like the others, appended to the tool definitions at the start of a session.

1

u/rimaa_nahk Oct 05 '26

I tried it, so far I haven't seen any cache break

→ More replies (1)

1

u/rimaa_nahk Oct 05 '26

Also do you mind sharing the link ?

→ More replies (1)

1

u/vertigo235 Oct 05 '26

I didn't have to enable it, it seems the model chooses to use it automatically when needed.

1

u/aparamonov Oct 06 '26

What do you toggle exactly? I wonder how I could link pi-subagents-lite to extensions like this for a Killswitch behavior