chujiu-dev3k downloadsInteractively run code blocks in Obsidian with stdin input support,works on desktop, iOS & Android.. Supports Python, C, C++, Java, Go, JavaScript, TypeScript, Rust, Kotlin and more.
Run code blocks interactively in Obsidian with full stdin input support. 17 language tags are supported: Python runs locally via Pyodide (WebAssembly), four more run in the browser (JavaScript, TypeScript, HTML, Wenyan), and the remaining twelve go through public playground APIs.
Code Runner provides the most complete Python input experience of any Obsidian plugin:
| Platform | Mode | Behavior |
|---|---|---|
| Desktop (SAB available) | Interactive | Pre-fill the first input() prompt, then each subsequent input() triggers an inline popup in real time — type and press Enter as the program runs |
| Tablet / Mobile (no SAB) | Pre-fill | All input() prompts are parsed and shown as labeled fields. Loop-based programs get a raw textarea for unlimited lines |
while True: loop that never asks for inputinput() inside while/for loops is detected automatically; tablet mode switches to a multi-line textareastdin-capable remote languages (C, C++, Java, Go, C#, Swift, R) get a plain stdin textarea. The text is handed to the compiler service with the compile request, so these languages cannot prompt you mid-run the way Python can — fill in everything the program will read before starting it.
A lecture note usually quotes a few lines, not a whole program:
int n = 0x12345678;
unsigned char *q = (unsigned char *)&n;
for (int i = 0; i < 4; i++)
printf("%02x ", q[i]);
That has no main and no <stdio.h>, so a compiler can do nothing with it — but there is nothing
ambiguous about what running it should mean. When a block is a fragment like this, the plugin wraps
it in the standard shape for its language: the missing entry point, plus the includes the snippet
actually uses and does not declare. The first line of the output says what was added; expanding it
shows the exact code that ran, which is how a compiler diagnostic's line number can be mapped back
to the note.
| Language | What a fragment gets |
|---|---|
| C / C++ | int main() { … return 0; } and the headers the snippet's own calls need |
| Java | public class Program { public static void main(String[] args) { … } } and the imports it needs |
| Go | package main, the imports it uses, and a func main() { … } |
| Kotlin / V / Rust | an entry point (fun main(), fn main()) — Rust needs nothing else, its prelude covers println! |
| C# | the using lines, and — only if the snippet prints anything outside ASCII — one line setting the console encoding. The playground's stdout is not UTF-8, so Console.WriteLine("中文") comes back as ?? without it. A whole C# program that prints non-ASCII still shows ?: the line would become the entry point and its own Main would never run |
"The includes it needs" is meant literally. A snippet that only prints gets <stdio.h> and nothing
else; one that carries its own #include keeps it (moved above the entry point, where a header
belongs) and is not given a second copy; Go gets no import it does not use, because an unused
import is an error there rather than a warning.
Nothing is wrapped without evidence. Sent exactly as written are: a snippet that already declares
an entry point; one that is defining a function, class or struct of its own (int add(int a, int b) { … } cannot be nested inside main, so wrapping it would trade a link error for a syntax
error); an empty or comment-only block; and a Go snippet that declares a package other than main.
Haskell is not covered at all: main = do is indentation-sensitive, so a fragment cannot be
dropped into one without re-indenting the author's lines.
Turn the whole thing off in Settings → General → Complete program skeleton.
| Language | Backend | stdin |
|---|---|---|
| Python | Pyodide v0.26.x (local WASM) | ✅ interactive |
| C | SoloLearn API (remote) | ✅ one-shot |
| C++ | SoloLearn API (remote) | ✅ one-shot |
| Java | SoloLearn API (remote) | ✅ one-shot |
| Go | SoloLearn API (remote) | ✅ one-shot |
| C# | SoloLearn API (remote) | ✅ one-shot |
| Swift | SoloLearn API (remote) | ✅ one-shot |
| R | SoloLearn API (remote) | ✅ one-shot |
| JavaScript | AsyncFunction on the main thread (local) |
— |
| TypeScript | Transpiled → JavaScript (local) | — |
| Rust | Rust Playground API (remote) | — |
| Kotlin | Kotlin Playground API (remote) | — |
| Haskell | Haskell Playground API (remote) | — |
| Crystal | Crystal Playground API (remote) | — |
| V (Vlang) | V Playground API (remote) | — |
| Wenyan | wenyan-lang from CDN (local) | — |
| HTML | Rendered into a shadow root (local) | — |
Fence tags accepted: the names above, plus these aliases — py (Python), javascript, typescript,
haskell, vlang, wenyan, cr, R, golang. A fence tag outside that list is not recognised at
all: the block stays a plain code block with no run button. py was the usual casualty of that
(python and py are the same backend).
c++ and c# are deliberately not aliases: write cpp and csharp. Obsidian turns a
registered tag into a CSS selector, and those two are not valid selectors, so registering them
breaks the rendering of every note in the vault.
app.plugins.plugins['code-runner'].api. Note that for the languages in Incomplete Snippets the returned array's first element is the completion notice as HTML markup, present only when something was added — callers that want the program's own output should skip a leading line starting with <detailsWorth knowing before you write a long loop:
while (true) {} in a JS block freezes Obsidian, and JS blocks have no stop button.SharedArrayBuffer) Python also occupies the UI thread, so no stop button is offered there — the button only appears when it can actually work.while True: with no break/return/exit), the hint says it may be an infinite loop instead — a program that keeps printing is left alone unless its shape is loop-like. Languages that cannot be stopped mid-run wait 30 s and are told to check the network rather than to press a button that does not exist.main.js, manifest.json, styles.css from the latest release<vault>/.obsidian/plugins/code-runner/ and copy the 3 files inOnce approved, install directly via Settings → Community Plugins → Browse → "Code Runner".
Create a fenced code block with a language tag:
```python
name = input("Enter your name: ")
age = input("Enter your age: ")
print(f"Hello {name}, you are {age} years old!")
```
input() call, consumed in order. Anything the program still asks for after your lines run out is prompted interactively (desktop).3 4 on one line for two scanf/Scanner calls, Alice then 25 on separate lines for readLine-style readers.Code Block → needsStdin() → input form (only for languages that can be fed)
│
which language?
┌────────────┴─────────────┐
Python C/C++/Java/Go/C#/Swift/R
│ │
SAB available? SoloLearn compile API
┌─┴──┐ (stdin travels with
Yes No the request)
│ │
Worker Main-thread
+ SAB Pyodide
(inter- (pre-fill
active) only)
└────────────┬─────────────┘
Output
Atomics.wait/notify blocks the Worker for interactive input without freezing the UI; a SIGINT cell handed to pyodide.setInterruptBuffer plus an abort sentinel in the same buffer is what the stop button usesgit clone https://github.com/chujiu-dev/obsidian-code-runner.git
cd obsidian-code-runner
npm install
npm run typecheck # tsc --noEmit
npm run lint # eslint
npm run build # typecheck + vite build → dist/main.js, dist/styles.css, dist/manifest.json
To copy the build into a vault you test against, create a .env file (gitignored):
VAULT_PLUGIN_DIR=E:/path/to/vault/.obsidian/plugins/code-runner
and run npm run deploy.
Forked from Code Emitter by YISH (MIT). Key additions:
input() support via builtins.input replacement (Pyodide v0.26.x / Python 3.12)MIT — see LICENSE.