repl
Runs code in an interpreter that stays alive between calls, so variables, imports and loaded data persist.
Use it instead of run_terminal with python3 -c or node -e whenever the work takes more than one step over the same data. Load a file, parse an archive or decode a video once, then keep querying what is already in memory — re-reading the same input on every call is the single most expensive habit available here.
State lasts for the current turn and is discarded when the turn ends.
python: the value of a trailing expression is printed, as in a notebook.
node: a top-level var persists between calls; const and let are scoped to the single call, so assign to globalThis for anything that must outlive it.
This runs real code. It can write files and shell out, and is subject to the same approval and plan-mode rules as run_terminal. Runs a shell command, so it is gated by your approval mode.
Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
language |
string |
Yes | Which interpreter to use. |
code |
string |
Yes | Source to evaluate in the session. May be several statements; it runs in the same namespace as previous calls. |
restart |
boolean |
No | Discard the existing session and start an empty one before running this code. Use after leaving the interpreter in a bad state, not routinely — restarting throws away the loaded data that makes this tool worth using. |
timeout |
number |
No | Seconds this evaluation may run (default: 120). Exceeding it discards the session and its variables. |
Example#
repl({ language: "…", code: "…" })
Approval#
Gated by the approval mode.
See also#
- Tools — every tool, and which of them can change your files
- Approval modes — what gates the tools that change things
Added in woopcode@0.6.0