GSH (Gleam Shell)

GSH is an interactive REPL for the Gleam Programming Language written in Gleam and Erlang.

⚠This is still a work in progress tool⚠

Installation

Add gsh to your project as a development dependency:

gleam add gsh --dev

Usage

gsh can either be used as a standalone REPL or a live-app bootloader.

Standalone

gleam run -m gsh

App loader

gleam run -m gsh -- my_app worker_pool bg_module_1

Built-in Commands

GSH includes several built-in commands to manage your session:

Target limitations

Note: GSH is heavily tied to the Erlang VM (BEAM) for state persistence and dynamic evaluation. It does not support the JavaScript target.

Why a REPL?

After using Elixir’s iex, OCaml’s utop or even Rust’s evcxr. I really wanted to build a tool for Gleam that gets me closer to the BEAM. GSH, expanded as Gleam SHell is a materialization of that dream.

REPL use cases

Demo

How it works

  1. gsh is a “Compiler Injection REPL”.
Gleam code -> Gleam compiler -> Erlang Target -> BEAM
  1. Previously, gsh used to spin up and destroy a separate BEAM node for every evaluation (no state persistence). This introduced the side-effect problem where code can re-execute. gsh currently uses a single persistent BEAM node along with a safety layer where side-effects (like spawning a process or writing to a DB) are wrapped in type-safe process dictionary cache. Only the cached memory pointer is used in all future evaluations.

  2. The shell’s state is stored in memory for every session. It includes constructs like imports, history, assertion, bindings, functions and types.

  3. etch_erlang – a well-maintained TUI backend is used to render characters properly on the terminal.

Feature set comparison with iex

FeatureGSH (Gleam Shell)IEx (Interactive Elixir)
Live App Bootstrappinggleam run -m gsh -- appiex -S mix
SyntaxGleam (Rust-like, strict types)Elixir (Ruby-like, dynamic)
Syntax HighlightingYes (ANSI-based)Yes (Configurable ANSI)
Type SystemStatic (recompiles on the fly)Dynamic
Evaluation EngineFile-backed generation + Hot code reloadDirect Erlang AST evaluation
Side-Effect SafetyYes (Process Dictionary memoization)Yes (Native to AST loop)
VM State PersistenceYes (Actors, PIDs, ETS stay alive)Yes
Fault ToleranceYes (Catches Badarg / VM crashes)Yes
Multiline InputYes (Buffer completion)Yes (Native AST parsing)
Built-in Helperspid() (easily extensible)h(), i(), v(), pid(), etc.
AutocompleteKeywords, bound vars, module exportsDeeply context-aware + docstrings

Acknowledgments

GSH stands on the shoulders of some excellent Gleam libraries:

Contributing

Contributions are massively appreciated! A REPL would be a nice to have tool in the Gleam ecosystem, and there is plenty of room to grow.

Search Document