bgcmd is a way to run (almost) any interactive repl in background
it keeps a persistent session between each line, and it prints any output produced by the repl
- set the $BGCMDPROMPT env var to your repl's prompt string
- (optional) set the $BGCMDDIR env var to some private directory (it defaults to $HOME/.bgcmd otherwise)
- run bgcmd START your-repl-here arg1 arg2 arg3 to start the repl
- run bgcmd input here to pass that input to the repl
after every invocation, the output from the repl will be printed to stdout
this lets you programmatically interact with repls and use their outputs
here's a demo of a cpython session:

and here is claude playing with sqlite3 with no sqlite mcp server:
claudesqlite.mp4your ai tools could not. now they can now drive almost any repl, as long as they can run arbitrary shell commands. for instance, claude code could not easily use the rr debugger (rr is an interactive program but claude code would always wait for the whole session to time out or terminate) but now it easily can
(rr has a a gdbmi interface but it doesn't help for this)
check if it accepts a -i parameter or something to force an interactive mode
bgcmd spawns a reader process that waits for your input through a fifo. its pid is stored in $BGCMDDIR/pid. killing this process will send an end of file to the repl, which causes most repls to gracefully terminate
restarting bgcmd with the same $BGCMDDIR will also do this for you
one way to do this is to create a few mini wrappers, one for each
for instance, this is a wrapper to run rr, which inspired this project:
because then you'd get ansi escapes mixed in, and you'd have to remove them before being able to use the reply from the repl
your repl is bad and you should use something else. however, you can manually resend the input by just writing it to the in fifo in $BGCMDDIR
you can flush the state with cat $BGCMDDIR/out > /dev/null
unfortunately, waiting for the prompt is the only thing that works semi generically for arbitrary repls. yeah it's a bit jank
(btw since you fully control the repl, you can just not cause this to happen)
probably, yeah. but this was short to write and it's generic and easy to use
in most cases, you'd have a similar level of jank with those anyway
mcp mcp mcp mcp mcp mcp mcp mcp mcp mcp mcp mcp mcp
.png)


