pi-clojure
A set of Clojure development tools implemented in pure JavaScript for the [pi-coding-agent](https://github.com/badlogic/pi-mono).
Package details
Install pi-clojure from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:pi-clojure- Package
pi-clojure- Version
1.0.3- Published
- Apr 20, 2026
- Downloads
- 504/mo · 12/wk
- Author
- markokocic
- License
- EPL-2.0
- Types
- extension
- Size
- 30.6 KB
- Dependencies
- 3 dependencies · 0 peers
Pi manifest JSON
{
"extensions": [
"./src/index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-clojure
A set of Clojure development tools implemented in pure JavaScript for the pi-coding-agent.
Why this project?
Existing solutions for Clojure evaluation in AI coding agents (e.g., clojure-mcp, clojure-mcp-light) either:
- Introduce the overhead of MCP (Model Context Protocol) as an additional communication layer
- Rely on CLI tools for execution, which adds process spawn overhead
These approaches can create performance bottlenecks, especially on resource-constrained systems. Additionally, MCP introduces complexity in setup and maintenance.
This project takes a different approach: implementing Clojure evaluation as native pi tools that communicate directly with nREPL via TCP sockets. This eliminates any middleware layer, providing:
- Zero overhead: Direct tool invocation without MCP protocol translation
- Direct execution: Code evaluated directly via nREPL without CLI process spawning overhead
- Simpler architecture: No external dependencies or protocol adapters
Installation
pi install npm:pi-clojure
Tools
| Tool | Description |
|---|---|
clojure_eval |
Evaluates Clojure code via nREPL |
clojure_find_nrepl_port |
Finds nREPL port by checking port files or trying default ports |
clojure_paren_repair |
Fixes unbalanced delimiters in Clojure/ClojureScript/Babashka code. Standalone — no nREPL required. |
clojure_eval
Evaluates Clojure code via nREPL.
Note: Requires an existing nREPL connection. Use clojure_find_nrepl_port to find a running nREPL, or start one manually.
Features
- Evaluates Clojure code via nREPL protocol
- Discovers nREPL endpoints on common ports
- Supports custom namespaces
- Handles stdout/stderr output
Configuration
Default nREPL Ports
The extension auto-detects nREPL on these ports:
- 7888, 1666, 50505, 58885, 63333, 7889
Parameters
| Parameter | Type | Description |
|---|---|---|
code |
string | Clojure code to evaluate |
port |
number | nREPL port (required) |
host |
string | nREPL host (default: localhost) |
ns |
string | Target namespace |
Usage
Start nREPL in your Clojure project:
clj -M:nrepl
Then use the clojure_eval tool in pi-coding-agent to evaluate code.
clojure_find_nrepl_port
Finds the nREPL port by checking for port files in the current directory or trying common default ports. Validates the connection by evaluating (+ 1 1).
Features
- Checks for common nREPL port files:
.nrepl-portnrepl-port.shadow-cljs/nrepl.port.cider-nrepl.port
- Falls back to default ports: 7888, 1666, 50505, 58885, 63333, 7889
- Validates by connecting and evaluating
(+ 1 1)
Parameters
None.
Usage
;; Find the nREPL port
(clojure_find_nrepl_port {})
;; Returns: Found nREPL port 7888 at localhost:7888
clojure_paren_repair
Fixes unbalanced delimiters in Clojure, ClojureScript, and Babashka code using parinfer. Standalone tool — does not require nREPL or any running process.
Works with all Clojure-type source files: .clj, .cljs, .cljc, .bb
Features
- Works with Clojure, ClojureScript, and Babashka
- Detects unbalanced
(,[,{,),],} - Auto-inserts missing closing delimiters
- Handles strings, comments, and escape sequences
- Pure JavaScript implementation (no native deps)
Parameters
| Parameter | Type | Description |
|---|---|---|
code |
string | Clojure code with potentially unbalanced delimiters |
check |
boolean | (optional) Only check if balanced, don't fix |
Usage
;; Fix unbalanced delimiters
(clojure_paren_repair { code: "(defn foo [x]" })
;; Returns: Fixed delimiters:
;; ```clojure
;; (defn foo [x])
;; ```
;; Check if balanced (without fixing)
(clojure_paren_repair { code: "(defn foo [x])", check: true })
;; Returns: Code has balanced delimiters
Examples
| Input | Output |
|---|---|
(defn foo [x] |
(defn foo [x]) |
((foo [bar] [baz] |
((foo [bar] [baz])) |
(defn foo [x y] x) |
(defn foo [x y] x) (no change) |
License
EPL-2.0
Copyright © 2026-present Marko Kocic marko@euptera.com