den-shell/den
publicClone
Push over the same URL. A password will not work: create a token under access tokens and use it in place of one.
- .config
- .github
- .vscode
- bench
- docs
- examples
- Formula
- packaging
- scripts
- src
- tests
- .dockerignore 299 B
- .editorconfig 147 B
- .gitattributes 12 B
- .gitignore 222 B
- aliases.zsh 2.6 KB
- build.zig 48.3 KB
- build.zig.zon 814 B
- bun.lock 39.7 KB
- bunfig.toml 180 B
- CHANGELOG.md 64.1 KB
- CLAUDE.md 1.6 KB
- den 56 B
- den.jsonc 4.7 KB
- deps.yaml 59 B
- docker-compose.yml 986 B
- Dockerfile 1.4 KB
- LICENSE.md 1.1 KB
- main 2.2 MB
- package.json 3.7 KB
- pantry.lock 2.3 KB
- README.md 13.2 KB
- tsconfig.json 700 B
Den Shell
A modern, POSIX-compliant shell written in Zig — a rich built-in feature set, a single self-contained binary, and memory safety.
Den combines the familiarity of traditional shells with a modern, batteries-included interactive experience. It was originally prototyped in TypeScript/Bun and rewritten in Zig for native code and a self-contained binary.
- ⚡ Instant startup — ~4–5 ms cold start; native code, no runtime or VM
- 📦 Self-contained — a ~1.3 MB binary (on par with bash/zsh) that links only libc — fewer dynamic deps than either
- 🛡️ Memory safe — Zig's compile-time safety prevents whole classes of bugs
- 🎯 Feature rich — 58 builtins, job control, history, completion, expansion, and a full line editor — no plugin manager required
- 🧩 Extensible — WASM plugins, AI-assisted completions, distributed sessions, an LSP server
- ✅ Compatible — POSIX-compliant with a zsh compatibility layer and a bash migration path
📖 Full documentation lives in ./docs — every feature below links to its dedicated page.
Table of Contents
- Why Den · Performance
- Quick Start · Installation · Configuration
- Features — core, expansion, interactive, completion, builtins, scripting, extended
- Compatibility & Migration
- Documentation · Building from Source · Contributing
Why Den
Den's draw is what's built in — completion, autosuggestions, syntax highlighting, a git prompt, and a zsh-style feature set with no plugin manager — plus a single self-contained binary and a memory-safe implementation. On raw micro-benchmarks it's competitive with, not dramatically faster than, established shells.
Performance
Measured on an Apple M3 Pro (macOS, arm64) with hyperfine, against the system bash 3.2 and zsh 5.9. Den is the default ReleaseSmall build. These are real numbers from one machine — reproduce them with scripts/bench.sh comparison.
| Metric | Den | Bash 3.2 | Zsh 5.9 |
|---|---|---|---|
Startup, -c true | 3.9 ms | 1.3 ms | 2.1 ms |
| Command exec (per external cmd) | ~2.0 ms | ~1.8 ms | ~2.0 ms |
| Idle memory (clean config) | 4.6 MB | 2.4 MB | 2.3 MB |
| Binary size | 1.33 MB | 1.29 MB | 1.36 MB |
| Dynamic libraries | 1 (libc) | 2 | 4 |
Honest read: Den's binary is now on par with bash/zsh (1.33 MB) and links the fewest libraries. It starts in a few milliseconds (instant in practice) though still a touch behind bash/zsh, and uses somewhat more idle memory — the cost of a much richer built-in experience and memory safety. Further startup/footprint work is on the roadmap.
The engineering behind Den's hot paths is documented in depth:
- Benchmarks — methodology and full results
- Algorithms — the algorithmic choices behind hot paths
- Data Structures — the structures backing history, completion, and expansion
- CPU Optimization — branch-friendly, cache-aware execution
- Memory Optimization — arena/pool strategies and zero-copy parsing
- Concurrency — async git status, background jobs, and the prompt fetcher
- Profiling — how to profile Den and read the output
Quick Start
# Build Den (see Installation for prebuilt binaries / package managers)
zig build -Doptimize=ReleaseSmall
# Start an interactive shell
./zig-out/bin/den
# Run a script
./zig-out/bin/den script.sh
# Run a single command
./zig-out/bin/den -c 'echo "Hello from Den!"'A first interactive session:
➜ echo "Hello, World!"
Hello, World!
➜ export MY_VAR="test"
➜ echo $MY_VAR
test
➜ ls -la | grep zig
-rw-r--r-- 1 user staff 42627 build.zig
drwxr-xr-x 3 user staff 96 zig-outNew to Den? Start with the Introduction and the Quick Reference cheat sheet.
Installation
# Homebrew (macOS / Linux)
brew install stacksjs/tap/den
# Install script (downloads the latest release binary)
curl -fsSL https://raw.githubusercontent.com/stacksjs/den/main/scripts/install.sh | bash
# From source
zig build -Doptimize=ReleaseSmall && zig build install --prefix ~/.localDistribution packages are provided for Debian/Ubuntu (.deb), Fedora/RHEL (.rpm), Arch (PKGBUILD), and Nix (packaging/). To make Den your login shell, add it to /etc/shells and run chsh. Full details — prebuilt binaries, package managers, and login-shell setup — are in the Installation guide.
Already installed? Run den upgrade to install the latest verified GitHub release.
Configuration
Den reads two files at startup:
~/.denrc— a shell script sourced on startup (like.zshrc): set environment,$PATH, aliases, and run commands.~/.config/den.jsonc— declarative JSONC config for the prompt, history, completion, theme, aliases, and keybindings. A fully-commented example lives atden.jsonc.
Everything you can configure — prompt format, history behaviour, completion, colours/symbols, and keybindings — is documented in the Configuration reference. Prompt styling has its own deep-dive in Themes.
Features
Core Shell
| Feature | Description |
|---|---|
| Pipelines | Multi-stage cmd1 | cmd2 | cmd3 |
| I/O redirection | >, >>, <, 2>, 2>&1, here-docs, here-strings |
| Boolean operators | Short-circuit && and || |
| Command chaining | Sequential ; lists |
| Background jobs | &, jobs, fg, bg, wait, disown |
| Subshells & grouping | ( … ) and { …; } |
Expansion
| Feature | Description |
|---|---|
| Variable expansion | $VAR, ${VAR}, ${VAR:-default}, ${#VAR}, ${VAR#prefix}, special vars ($?, $$, $!, $_, $0–$9, $@, $*, $#) |
| Command substitution | $(command) (and backticks) |
| Arithmetic | $(( expr )) with + - * / % ** |
| Brace expansion | {1..10}, {a..z}, {foo,bar,baz} |
| Tilde expansion | ~, ~/path, ~user |
| Glob expansion | *.zig, **/*.txt, plus zsh glob qualifiers |
Interactive Experience
| Feature | Description |
|---|---|
| Line editor | Emacs & Vi keymaps, word motions, kill-ring, multi-line editing |
| Inline autosuggestions | fish-style suggestions from history as you type |
| Syntax highlighting | Live command highlighting in the prompt |
| Persistent history | Shared, de-duplicated, configurable history file |
| History substring search | Up/Down filters history by what you've typed |
| Prompt & themes | Two-line prompt, git status, runtime modules, colours/symbols |
Completion
| Feature | Description |
|---|---|
| Tab completion | Commands, files, options, and a navigable grid menu (arrow keys move by row/column) |
| Mid-word completion | Expand abbreviated paths like /u/l/b → /usr/local/bin |
| Git completion | Branches, remotes, files, and subcommands for git |
| Context-aware completion | Per-command argument/flag completion (npm, bun, docker, …) |
Built-in Commands
Den ships 58 built-in commands. The complete reference — flags, behaviour, and examples for each — is in Builtins (run help inside Den for a quick summary).
- Core:
exit,help,true,false - File system:
cd,pwd,pushd,popd,dirs,realpath - Environment:
env,export,set,unset - Introspection:
alias,unalias,type,which - Job control:
jobs,fg,bg,kill,wait,disown - History & completion:
history,complete - Scripting:
source/.,read,test/[,eval,shift,command,return,break,continue,local,declare,readonly,getopts - Path utilities:
basename,dirname - Output:
echo,printf - System:
time,sleep,umask,hash,clear,uname,whoami,times - Advanced execution:
exec,builtin,trap - zsh & extended:
setopt,unsetopt,ai,wasm
Den also provides fast built-in implementations of common coreutils (
grep,ls,find,date,seq,base64,tree, …). When invoked with options the builtin doesn't implement, Den transparently falls back to the real tool on$PATH, so advanced usage always works.
Scripting
Full POSIX scripting — if/then/else, for, while, until, case, and functions — plus here-documents and traps. See the Scripting guide.
#!/usr/bin/env den
export PROJECT="my-app"
if test -f README.md; then
echo "$PROJECT: README present"
fi
for file in *.zig; do
echo "compiling $(basename "$file")"
done
greet() { echo "hello, $1"; }
greet worldExtended Capabilities
| Feature | Description |
|---|---|
| zsh compatibility | setopt/unsetopt, %-prompt escapes, glob qualifiers, arrays, associative arrays, named directories, auto-cd |
| WASM plugins | wasm <module.wasm> <export> [args] via a built-in interpreter; write your own |
| AI-assisted completions | ai <describe a command> (OpenAI/Anthropic-compatible) |
| Distributed sessions | den --serve / den --connect (loopback-only by default) |
| Language Server | den --lsp for editor integration |
Compatibility & Migration
- Coming from bash? See the Bash Migration guide.
- Coming from zsh? See zsh Compatibility.
- Upgrading from an older Den / the TypeScript prototype? See the Migration guide.
- Stuck? The Troubleshooting guide covers common issues.
Documentation
Everything is under ./docs. Highlights by audience:
Get started
Use Den
- Features · Builtins · Scripting · Configuration · Themes
- Line Editing · Tab Completion · Autocompletion · Git Completion · Mid-word Completion · History Substring Search
- Advanced Usage · Extended Features · Custom Commands
Migrate
Performance
- Benchmarks · Algorithms · Data Structures · CPU Optimization · Memory Optimization · Concurrency · Profiling
Develop & extend
Building from Source
Requirements: Zig 0.17-dev or later; macOS, Linux, or BSD (Windows support planned).
zig build # debug build
zig build -Doptimize=ReleaseSmall # release build (~1.3MB, stripped — the default)
zig build -Doptimize=ReleaseFast # release tuned for max speed (larger)
zig build install --prefix ~/.local # install
zig build test # run the test suiteRelease builds are stripped automatically; pass -Dstrip=false to keep symbols.
See Architecture for the source layout and Testing for the test framework. The full feature roadmap is in ROADMAP.md.
Contributing
Contributions are welcome! Please read the Contributing guide to get started.
License
MIT License — see LICENSE.
Made with 💙 by the Stacks team.