Scrollback history for mosh. A lightweight terminal multiplexer that gives you the one thing mosh is missing — the ability to scroll back through your terminal output.
Unlike tmux or screen, mhist doesn't require switching to a "copy mode" to view history. Just use keyboard shortcuts to scroll, and copy/paste works normally at all times.
go install github.com/jaigner-hub/mhist@latestOr build from source:
git clone https://github.com/jaigner-hub/mhist.git
cd mhist
make buildProduces a single mhist binary with no runtime dependencies.
Requirements: Go 1.23+
# Start a new session
mhist
# Start a named session
mhist new -n work
# List sessions
mhist ls
# Attach to a session by name or ID prefix
mhist attach work
# Kill a session
mhist kill workAdd this to your ~/.bashrc on the server to automatically start mhist when you connect:
# Auto-start mhist
if [ -z "$MHIST_SESSION" ] && [ -n "$SSH_CONNECTION" ]; then
exec mhist
fiEach SSH/mosh connection gets its own session. Mosh reconnections reuse the existing session automatically. Use Ctrl+a s to switch between sessions.
| Key | Action |
|---|---|
| Ctrl+a d | Detach from session |
| Ctrl+a s | Switch between sessions |
| Ctrl+a Ctrl+a | Send literal Ctrl+a |
| Ctrl+s | Enter scroll mode |
| Page Up | Enter scroll mode (full page) |
| Key | Action |
|---|---|
| k / Arrow Up | Scroll up |
| j / Arrow Down | Scroll down |
| u | Half-page up |
| d | Half-page down |
| Page Up / Page Down | Full page up / down |
| q / Esc / Ctrl+s | Exit scroll mode |
| Any other key | Exit scroll mode |
A position indicator [line N/total] appears at the top-right while scrolling.
Copy/paste works normally in both modes — text selection is never intercepted.
Terminal --> mosh --> mhist (client) --> Unix socket --> mhist (session) --> PTY --> shell
Each session runs as an independent background process — no central daemon. Sessions persist after you detach and survive mosh reconnections.
- Scrollback buffer — ring buffer stores the last 10,000 lines of output
- Raw PTY replay — 64 KB circular buffer preserves exact terminal state (colors, cursor, prompt) for lossless screen redraw on reattach
- Session switching —
Ctrl+a slets you switch between sessions without disconnecting - Partial line tracking — your current shell prompt is preserved in scrollback
- Binary protocol — framed messages over Unix domain sockets for efficient client-session communication
Sessions are stored in $XDG_RUNTIME_DIR/mhist/ (falls back to /tmp/mhist-$UID/). Each session creates:
<id>.sock— Unix socket for client connections<id>.json— metadata (name, PID, creation time)
Stale sessions are automatically cleaned up when you run mhist ls. Connecting to a session with a dead client (e.g., from a dropped mosh connection) automatically takes over.
mhist works well over mosh from mobile terminals:
- Ctrl+s to enter scroll mode, then swipe (sends arrow keys) to scroll through history
- Copy/paste works normally — no mouse capture to interfere with text selection
Ctrl+a sto switch sessions
- creack/pty — PTY allocation
- x/term — terminal raw mode and size detection
MIT