cc-self
Self-control for Claude Code sessions running in tmux: the session types
into its own TUI. Slash commands, dialog navigation, screen observation, and
full in-place self-restart — no extra daemons, just tmux primitives.
How it works
The session's Bash tool runs inside the same tmux pane as the Claude Code TUI.
tmux send-keys to $TMUX_PANE is literally typing into the session's own
input box; capture-pane lets it see its own screen; run-shell -b gives it
a process that survives its own death (used for restart).
Install
/plugin marketplace add Dev-Jahn/cc-self # or a local path
/plugin install cc-self@cc-self-marketplace
What you get
self-control skill (auto-triggers): teaches the session to run
user-side slash commands on itself (/reload-plugins, /effort, /model,
/plugin install …), answer its own confirmation dialogs (peek → key), and
verify its own state via the statusline.
/cc-self:restart command: the session restarts itself in place —
a driver delegated to the tmux server waits for the turn to end, types
/exit, relaunches claude --resume <session-id> in the same pane, and
wakes the resumed session with a message so it reports back. The wake
waits for the resumed TUI to draw its own (framed) input box and settle —
the shell prompt that launched claude is not that box. Conversation
history is fully preserved. Downtime ≈ 15 seconds. The session's current
model and effort are captured before exit and pinned onto the resume
command (--model/--effort) so effort survives the restart and the
prompt cache stays warm; restart <sid> -- <flags> appends extra resume
flags verbatim (replacing the pinned ones they name, e.g. -- --effort max).
CC_SELF_BASELINE / CC_SELF_GUARD_DISABLED from the session's environment
are carried onto the relaunch (own session only), so per-session
declarations survive it.
model-recovery skill + model-guard hook + cc-self recover:
deterministic recovery from model safety-fallbacks. The bundled hook
re-flags on every run while the session's runtime model differs from its
declared baseline (CC_SELF_BASELINE in the session's environment, else model in
~/.claude/settings.json; nothing declared means no baseline, so the guard
then only reports model transitions and instructs nothing — there is no
built-in default; ids, dated snapshots and aliases such as sonnet compare
by model family). A fallback only ever goes down, so a session above its
baseline is never flagged, though a downward move from a model the session
ran on is reported once. A /model the user types in the session, once the
first assistant record after it confirms it, is the newest declaration and
becomes the session's baseline (over CC_SELF_BASELINE when typed after
this launch; over settings.json unless that was written later), so a later
fallback recovers to the chosen model. A /model that cc-self itself typed
is a switch, never a declaration. Every note names the
baseline's source and whether the guard ever saw the session on it, and
embeds the exact recovery step (in full on every prompt and every 10th tool
call, one line in between). The model's
only job is writing a compact instruction file (preserve context, abstract
the trigger content); cc-self recover then submits /compact and a
detached driver waits out the compaction (transcript truth: the
compact_boundary record), switches /model back — approving the confirm
dialog only if one appears; post-compaction switches are dialog-free —
wakes the session, and verifies the live model from the session transcript
(statuslines are user-configurable, so screen checks are advisory only).
A state machine with per-session state and driver pid in
~/.cc-self/state/recover-<sid>.json, no blind keypress at any step, one
driver per session (a second arm is refused), failures recorded with a
screen dump. Sessions with an always-blocking Stop hook integrate via the
yield-valve flag (~/.cc-self/state/yield-<sid>, see the model-recovery
skill). If an external copy of the guard also runs, keep only one enabled
(~/.cc-self/state/guard-disabled disables the bundled one).
scripts/cc-self: the underlying CLI, usable directly from Bash.
Requirements
- The Claude Code session must run inside tmux (
$TMUX_PANE set)
- macOS or Linux,
bash, tmux
Safety design