AgentREPL.jl
CLAUDE.md7 starsChanged 6 months agoApache-2.0View on GitHub
AgentREPL.jl is a Julia package providing a persistent REPL for AI agents via MCP (Model Context Protocol) STDIO transport. It solves Julia's "Time to First X" (TTFX) problem by maintaining persistent Julia worker subprocesses, avoiding the 1-2 second startup penalty for each command. Supports multiple named sessions and Revise.jl hot-reloading. AgentREPL uses a multi-session worker subprocess architecture (via Malt.jl): - The MCP server runs in the main Julia process - Each named session has its own Malt.Worker process for code…
In this repositoryOne other file it gives its agents.
- run-agentreplSkill
The file
We split this CLAUDE.md into the rules it gives an agent
12 rules. About 0 are common, 0 are distinctive, and 12 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 85
create_session!(name): - Create a new named session - Very specific: line 92
ensure_worker!(session): - Ensure a worker exists for a session, creating one if needed. - Very specific: line 100
_start_repl_socket_server!(session): - Start a chmod-600 Unix domain socket server on the worker that evals incoming base64 code in Main … - Very specific: line 104
revise_on_worker!(session): - Call Revise.revise() on worker - Very specific: line 107
is_revise_available(session): - Check if Revise is loaded - Very specific: line 132
All tools except log_viewer and session accept an optional session parameter.
- Very specific: line 156
STDIO transport only: No network ports for security.
- Very specific: line 219
Hot-reloading: Use revise(action="revise") after editing .jl files to reload changes without restart
- Very specific: line 220
Multi-session: Use session(action="create", name="...") for parallel isolated workspaces
- Very specific: line 221
Testing: Use pkg(action="test") to run package tests (call revise first for latest changes)
- Very specific: line 222
Development: Use pkg(action="develop", packages="./path") + Revise for local package development
- Very specific: line 223
Environment management: Use activate + pkg(action="instantiate") for project-specific environments
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
AgentREPL.jl is a Julia package providing a persistent REPL for AI agents via MCP (Model Context Protocol) STDIO transport. It solves Julia's "Time to First X" (TTFX) problem by maintaining persistent Julia worker subprocesses, avoiding the 1-2 second startup penalty for each command. Supports multiple named sessions and Revise.jl hot-reloading.
Build and Test Commands
# Run all tests (Aqua quality + unit suites; fast, no subprocess spawning)
julia --project=. -e "using Pkg; Pkg.test()"
# Include the MCP protocol integration tests (spawns a server subprocess, ~60s)
AGENTREPL_E2E=true julia --project=. -e "using Pkg; Pkg.test()"
# Run a specific test file directly
julia --project=. test/test_eval.jl
# Start the MCP server manually (for debugging)
julia --project=. -e "using AgentREPL; AgentREPL.start_server()"
# Start server with a specific project activated
JULIA_REPL_PROJECT=/path/to/project julia --project=. bin/julia-repl-serverArchitecture
Multi-Session Worker Subprocess Model
AgentREPL uses a multi-session worker subprocess architecture (via Malt.jl):
- The MCP server runs in the main Julia process
- Each named session has its own
Malt.Workerprocess for code evaluation - Sessions are isolated: separate variables, packages, and project environments
resetkills a session's worker and spawns a fresh one (true hard reset)activateswitches a session's active project/environment- Revise.jl is auto-loaded on workers for hot-reloading support
Why Malt, not Distributed.jl: Malt spawns workers with monitor_stdout=false/monitor_stderr=false, so worker output goes to private pipes (drained to the server's stderr by _start_output_drain!) and can never reach the main process's stdout — which is the MCP JSON-RPC transport. Malt also has no global cluster state (each Worker is an independent object) and provides graceful stop (exit → SIGTERM → SIGKILL), isrunning, and TerminatedWorkerException, replacing hand-rolled lifecycle code. IPC is Malt.remote_eval_fetch(Main, w, expr) via the _remote_eval_fetch helper.
File Structure
Files are included in dependency order from AgentREPL.jl. repl_client.jl is the one exception: it is a standalone script run as a subprocess, not part of the module.
src/
AgentREPL.jl # Main module (imports, includes, exports only)
types.jl # State structs (SessionState, SessionRegistry, LogViewerState, HighlightConfig) + audit/registry globals
highlighting.jl # Julia syntax highlighting (uses JuliaSyntaxHighlighting.jl)
formatting.jl # Result formatting, stacktrace truncation
sessions.jl # Multi-session lifecycle (create, switch, list, destroy)
worker.jl # Malt worker lifecycle (ensure_worker!, capture_eval_on_worker, output drain, workspace restore)
revise.jl # Revise.jl integration (revise, track, includet on workers)
packages.jl # Pkg actions, project activation
logging.jl # Log viewer + persistent audit logging
attach.jl # Interactive shared REPL: Unix socket server on worker + tmux client launcher
repl_client.jl # Standalone REPL client (run via tmux subprocess, NOT included in module)
tools.jl # MCP tool definitions (8 tools)
resources.jl # MCP resources (session variables, info, project, log, sessions)
prompts.jl # MCP prompts (julia-dev-setup, julia-benchmark, julia-debug-error)
server.jl # start_server function (registers tools + resources + prompts, declares capabilities)Syntax Highlighting
Julia code in REPL output is syntax highlighted using JuliaSyntaxHighlighting.jl (official Julia package).
Configuration via environment variables:
JULIA_REPL_HIGHLIGHT:"true"(default) or"false"- enable/disable highlightingJULIA_REPL_OUTPUT_FORMAT:"ansi"(default),"markdown", or"plain"- output format
Plotting
UnicodePlots.jl is a dependency loaded on workers (not in the main module). capture_eval_on_worker passes the color preference into the worker so repr renders color-aware types (UnicodePlots output) with ANSI. The julia-plot skill tells the user to expand the tool result (Ctrl+O) for color rather than pasting ANSI art into chat.
Audit Logging
Set JULIA_REPL_AUDIT_DIR to enable persistent per-session audit logs that survive server restarts. server.jl creates the directory and sets _AUDIT_DIR; logging.jl (_get_audit_io) appends each eval interaction to {dir}/{session}_{date}.log. Disabled by default.
Key Functions
Session Management (sessions.jl):
get_current_session!()- Get current session, auto-creates "default" if nonecreate_session!(name)- Create a new named sessionswitch_session!(name)- Switch to a different sessiondestroy_session!(name)- Kill session and its workerlist_sessions()- List all sessions with status (theworker_pidfield carries the OS pid)resolve_session(name)- Resolve optional session name to SessionState
Worker Lifecycle (worker.jl):
ensure_worker!(session)- Ensure a worker exists for a session, creating one if needed; returns theMalt.Workerworker_live(session)/worker_pid(session)- Liveness predicate and OS pid (a non-nothingworker may still be dead)kill_worker!(session)/reset_worker!(session)- Worker lifecycle managementcapture_eval_on_worker(code; timeout, session_name, isolated)- Evaluate code with output capture;isolated=trueruns in a fresh anonymous module so nothing persistsget_worker_info(session)- Returns session metadata_remote_eval_fetch(w, expr)- The one IPC spelling (Malt.remote_eval_fetch(Main, w, expr))
Interactive REPL (attach.jl):
_start_repl_socket_server!(session)- Start a chmod-600 Unix domain socket server on the worker that evals incoming base64 code inMain(shares state with MCP eval)_open_attach_tmux(session)- Launchrepl_client.jlin tmux and open a terminal connected to the socket
Revise Integration (revise.jl):
revise_on_worker!(session)- Call Revise.revise() on workertrack_file_on_worker!(session, filepath)- Track a file with Reviseincludet_on_worker!(session, filepath)- Hot-reloadable includeis_revise_available(session)- Check if Revise is loadedget_revise_status(session)- Get tracking status
Formatting (formatting.jl):
truncate_output(text, max_chars)- Truncate text keeping head (60%) and tail (40%)format_elapsed(elapsed)- Format elapsed time as human-readable stringformat_result(...)- Formats results with syntax highlighting
Packages (packages.jl):
activate_project_on_worker!(path; session_name)- Switches environmentrun_pkg_action_on_worker(action, pkgs; session_name)- Package management
MCP Tools
Eight tools registered via ModelContextProtocol.jl:
eval- Evaluates Julia code with persistent state on the worker. Optional params:timeout(kills the worker if exceeded),max_output(default 50000 chars),max_stackframes(default 5),isolated(eval in a throwaway module, no persistence),ephemeral(spin up a temporary session + worker, eval, then destroy it for full process isolation)reset- Hard reset: kills worker, spawns fresh one (enables type redefinition)info- Returns session metadata (Julia version, project, variables, Revise status, worker pid)pkg- Package management (add, rm, status, update, instantiate, resolve, test, develop, free)activate- Switch active project/environmentlog_viewer- Control log viewer for visual REPL outputsession- Manage multiple named sessions (create, switch, list, destroy, attach).attachopens an interactive human-facing REPL sharing the session's worker staterevise- Hot-reload code changes via Revise.jl (revise, track, includet, status)
All tools except log_viewer and session accept an optional session parameter. The session tool identifies targets via its name parameter instead. Each tool carries a human-friendly title.
MCP Resources
Five read-only resources (resources.jl) expose session state so a client can pull it into context (Claude Code surfaces them as @-mentions) without spending an eval/info tool call. Reads have no side effects — they never spawn a worker — and _resource_safe tags each result ok=true or (ok=false, error=...):
agentrepl://sessions- all sessions with worker pid, project, Revise status, ageagentrepl://session/variables- user variables (name, type, size) in the current sessionagentrepl://session/info- Julia version, project, module count, Revise status, worker pid, setup notesagentrepl://session/project- activeProject.tomlcontents and whether aManifest.tomlis presentagentrepl://session/log- recent out-of-band worker output (recent_outputring: spawn-time precompile, async prints) plus audit-log entries whenJULIA_REPL_AUDIT_DIRis set
MCP Prompts
Three prompts (prompts.jl) expose reusable Julia workflows as slash commands (work without the plugin). Static MCPPrompt templates with {arg}/{?arg?…} substitution handled by the framework: julia-dev-setup (arg path), julia-benchmark (arg code), julia-debug-error (args code, error?). Registered in start_server with PromptCapability.
Key Design Decisions
- Multi-session model: Each session has its own
Malt.Workerwith isolated state - Transport isolation: Workers run with
monitor_stdout/stderr=false;_start_output_drain!drains their pipes to the server's stderr so worker output never corrupts the stdout JSON-RPC stream.get_worker_infosnapshots a baseline ofMainsymbols at spawn so Malt's own worker-loop globals don't show up as user variables - Revise.jl auto-loading: Workers attempt
using Reviseon startup; a load failure is recorded insession.worker_notesand surfaced ininfo/ the next eval rather than only logged (graceful degradation) - Lazy worker spawning: Worker created on first tool use, not at server startup
- Expression-based IPC:
_remote_eval_fetch(w, expr)(=Malt.remote_eval_fetch(Main, w, expr)) to avoid closure serialization issues - Capabilities:
start_serverdeclares only Tools + Resources (no prompts, no resource subscriptions), instead of the framework default that over-advertises - STDIO transport only: No network ports for security. The
session attachsocket is the one local IPC channel, a Unix domain socket chmod 600 (owner only) - Environment persistence: Activated environment survives reset.
workspace_path(set byactivate) is the working directory restored on every worker spawn/reset;eval-timecd()calls do not change it - Three isolation levels for eval: shared
Main(default),isolated(throwaway module, same worker),ephemeral(throwaway session + worker) - Output-then-result formatting: Shows stdout first, then result/error, then timing — optimized for collapsed view UX
Framework limitations (would need a ModelContextProtocol.jl PR): the released MCPTool has no annotations field and handle_list_tools does not serialize one, so tool hints (readOnlyHint/destructiveHint) are not available — only title is. There is no tool output_schema/structuredContent support, so tools return text and richer structured state is exposed via resources instead. (Both are implemented on a fork and wired on a separate branch, pending an upstream release.)
Testing
test/runtests.jl runs an Aqua.jl code quality pass (ambiguities off; UnicodePlots ignored in the stale-dep check since it is only used on workers) then includes the unit suites. test/test_mcp_protocol.jl is gated behind AGENTREPL_E2E=true because it spawns a real server subprocess.
Unit suites:
test_eval.jl- evaluation, output capture, error handling, formatting/truncation, worker lifecycle (spawn, reset, timeout kill, crash recovery),worker_notessurfacingtest_sessions.jl- multi-session management (create, switch, isolate, destroy), session-targeted eval, Pkg actions (test, develop, free)test_competitive_features.jl- isolated eval, ephemeral sessions, audit logging, workspace sync, attach socket lifecycletest_revise.jl- Revise.jl integration (status, availability)test_highlighting.jl- syntax highlighting (ANSI, markdown, plain formats)test_resources.jl- the five MCP resources, the ok/error discriminant, non-spawning reads, audit-log branchestest_mcp_protocol.jl- end-to-end MCP protocol over the server subprocess, incl. transport-stream cleanliness (E2E-gated)
Shell scripts test/test_e2e_agent.sh and test/test_plugin_validation.sh exercise the server and plugin manifest outside the Julia test runner.
Entry Point
bin/julia-repl-server is the executable script that loads the module and calls start_server(). It accepts JULIA_REPL_PROJECT environment variable to activate a specific project on the worker.
Plugin
The claude-plugin/ directory contains the plugin itself; .claude-plugin/marketplace.json is the marketplace manifest that points at it. The plugin:
- Auto-configures the MCP server (no manual
claude mcp addneeded) - Provides user-invoked skills:
/julia-reset,/julia-info,/julia-pkg,/julia-activate,/julia-log,/julia-session,/julia-revise,/julia-develop - Includes auto-triggering skills:
julia-evaluation(REPL best practices, inskills/julia/) andjulia-plot(plotting guidance) - Has one hook (
claude-plugin/hooks/hooks.jsonrunshooks/revise-nudge.sh): a non-blocking PostToolUse hook on Write/Edit that injects anadditionalContextreminder to callreviseafter a.jledit. The guidance to display code beforeevaland to expand plot results for color lives in thejulia-evaluation/julia-plotskills, not hooks.
Install with:
claude /plugin add samtalki/AgentREPL.jlOr for local development:
claude --plugin-dir ./claude-pluginUsing the MCP Tools
Important: When using eval, always display the code in a readable format in your message BEFORE calling the tool. The MCP permission prompt shows code as an escaped string which is unreadable. By showing the code first, users can verify what will be executed before approving.
Example:
Running this Julia code:
```julia
x = 1 + 1
println("Hello!")[then call eval]
## Modern Julia Workflows
This package supports modern Julia development workflows:
- **Hot-reloading**: Use `revise(action="revise")` after editing .jl files to reload changes without restart
- **Multi-session**: Use `session(action="create", name="...")` for parallel isolated workspaces
- **Testing**: Use `pkg(action="test")` to run package tests (call `revise` first for latest changes)
- **Development**: Use `pkg(action="develop", packages="./path")` + Revise for local package development
- **Environment management**: Use `activate` + `pkg(action="instantiate")` for project-specific environments
See [Modern Julia Workflows](https://modernjuliaworkflows.org/) for best practices.Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

