Skip to content

Add zellij backend (real right-split + fork) - #2

Open
ultranity wants to merge 2 commits into
limin112:mainfrom
ultranity:zellij-backend
Open

Add zellij backend (real right-split + fork)#2
ultranity wants to merge 2 commits into
limin112:mainfrom
ultranity:zellij-backend

Conversation

@ultranity

Copy link
Copy Markdown

What

Add a zellij backend to branchnew, slotted between the tmux and iTerm2 backends.

When run inside a zellij session ($ZELLIJ set), it splits a new pane to the right and runs the forked Claude session there:

zellij run -d right -c -n <name> --cwd <pwd> -- \
  claude --continue --fork-session --name <name>
  • -d right — real right split, matching the tmux backend's semantics.
  • -c / --close-on-exit — close the pane when Claude exits (Ctrl-D), instead of leaving zellij's "press Enter to re-run / Ctrl-c to kill" prompt behind.
  • -n <name> — name the pane after the branch, so the fork is identifiable in zellij's UI (zellij's equivalent of the terminal title the other backends rely on).

Backend priority is now: tmux > zellij > iTerm2 > Apple Terminal > new window.

Why

zellij is a tmux-class multiplexer. Previously, users inside zellij fell through to the $TERM_PROGRAM path and got a new window instead of an in-place split.

Docs

  • README "supported terminals" tables (zh + en) gain a zellij row.
  • "How it works" / --help / --dry-run now mention $ZELLIJ.

Tested

zellij 0.44.3 on macOS — zsh -n clean; BRANCHNEW_DRYRUN=1 reports ZELLIJ=set; running branchnew inside a zellij session splits a pane to the right and forks the session into it. -c is the documented zellij flag for closing the pane on command exit.

Detect $ZELLIJ (like $TMUX) and open the fork via
`zellij run -d right -c -n <name> --cwd <pwd> -- claude --continue
--fork-session --name <name>`, slotted between the tmux and iTerm2
backends. -c (--close-on-exit) closes the pane when claude exits, so
Ctrl-D doesn't leave zellij's "press Enter to re-run / Ctrl-c to kill"
prompt behind.

Update README terminal tables (zh + en), "how it works", and the
--help / --dry-run output to mention zellij / $ZELLIJ.

~.O
- zellij: run the shared $cmd via `zsh -ic` so rc-installed PATH/alias
  resolve; --near-current-pane anchors the split to the invoking pane;
  hold the pane open on startup failure (with -c alone errors vanished
  with the closing pane); swallow the pane-id stdout
- resume: trust CLAUDE_CODE_SESSION_ID only when its transcript lives in
  this project's dir and was written in the last 10 min — long-lived
  processes born from a Claude Bash call inherit a stale id; otherwise
  fall back to --continue with a stderr notice
- one $cmd assembly for all four backends (kills ${=resume} and the
  per-backend cwd/quoting variants; dry-run now prints the real thing);
  ${(qq)} single-quoting keeps `!` inert under interactive histexpand
- check $ZELLIJ before $TMUX: zellij panes inherit the outer server's
  $TMUX when nested
- reject dash-leading names (typo'd options) with a clear error
- --record: skip inside zellij — every pane shares the server's
  ITERM_SESSION_ID, so mappings would overwrite each other
- README / HOTKEY-FORK / header: document resume-by-id inside a session
  vs --continue from a plain terminal

~.O
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant