diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md
index 8b59ddd..0a65acf 100644
--- a/.claude/memory/journal.md
+++ b/.claude/memory/journal.md
@@ -132,3 +132,6 @@ Done: `tmux.conf` J/L join-pane, S swap-pane, ( ) repeatable swap-pane -U/-D (AZ
## 2026-10-09 (3) — tmux status tabs centred + widened
Done: `status-justify absolute-centre`, separator ' ', window-status formats ` #I #W ` (current bold on light pill). Applied live via `tmux set`, deployed copy to ~/.config/tmux/tmux.conf (install.sh cp semantics). User picked "pastilles larges" over 2-line bar. feature/tmux-status-tabs finished into develop on user signal; manual push, user pushes.
+
+## 2026-10-09 (4) — tmux: any bare key leaves copy-mode after a mouse selection
+Done: `bin/tmux-copy-exit-keys` (wraps 120 copy-mode-vi keys behind `@mouse_sel`, idempotent, bash 3.2), tmux.conf marker on MouseDragEnd1Pane + pane-mode-changed hook + run-shell after tpm, install.sh chmod, README/CLAUDE.md/CHANGELOG. Chosen: mouse-only scope, key swallowed. 6 headless tests pass, full conf reload OK. LRN-017. Session 12 window 0 (zsh) vanished during the run, not targeted by any command, flagged to user. Merged on signal; manual push.
diff --git a/.claude/memory/learnings.md b/.claude/memory/learnings.md
index a6c2c11..462fe10 100644
--- a/.claude/memory/learnings.md
+++ b/.claude/memory/learnings.md
@@ -124,3 +124,14 @@ by plan-challenger reading `git log -L` on the call site. Apply: pass resolved v
render boundary; oracle greps the call site (Case H) and asserts `! grep '@(USER|EMAIL|AUTOPUSH)@'` on output;
reject placeholder-shaped values like empty ones. Bonus: `shopt -u patsub_replacement` before `${v//p/$r}` on
bash ≥ 5.2 (`&` expands to match).
+
+## LRN-017 — tmux: conf key names, list-keys, hooks, headless key tests
+2026-10-09. Found while building `bin/tmux-copy-exit-keys` (tmux 3.7c). (1) Key `~` in a sourced conf must be
+`\~`: parser tilde-expands bare `~` → key `/Users/x`, "unknown key". Same escape set as list-keys prints:
+`; { } # $ % " ' \ ~`. (2) `list-keys -T
` does not filter in 3.7 (prints nothing, or whole table
+when key is `;`): dump the table once, grep/awk the key token. (3) Hooks (`pane-mode-changed`) run with the
+triggering pane as target: `set -pu @opt` needs no `-t`; `#{hook_pane}` quoting inside nested strings broke.
+(4) `send-keys ` to a pane in copy-mode dispatches through the mode key table → key-binding behaviour is
+testable headless on a scratch pane (`new-window -d -P -F '#{pane_id}'`, assert `#{pane_in_mode}`); address
+by pane id, window-name plugin renames `-n` names. (5) `\;` inside tmux.conf '...' stays literal, then splits
+a bind's command list when the string is parsed by if-shell: works, no need to convert to `{ }` blocks.
diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md
index cf0a984..f7f63c2 100644
--- a/.claude/tasks/TODO.md
+++ b/.claude/tasks/TODO.md
@@ -148,3 +148,10 @@ Branch: feature/docker-rootless (off develop). Mirrors the manual setup done on
- [x] bash/bashrc-linux: DOCKER_HOST exported only when the rootless socket exists (no PATH line: /usr/bin already on PATH)
- [x] README.md: table row, step 2 packages, packages list, new offer step
- [x] shellcheck + bash -n; commit on the feature branch. No finish without explicit signal.
+
+## Feature — tmux: any bare key leaves copy-mode after a mouse selection (2026-10-09)
+Branch: feature/tmux-copy-exit-keys (off develop). Chosen in chat: only after a mouse drag (keyboard/wheel copy-mode keeps vi keys), key swallowed.
+- [x] bin/tmux-copy-exit-keys — wraps every unmodified copy-mode-vi key in `if -F '#{@mouse_sel}' {cancel} {orig}`, re-runnable, bash 3.2
+- [x] tmux.conf — MouseDragEnd1Pane sets `@mouse_sel` (both clipboard branches), pane-mode-changed hook clears it, run-shell after tpm
+- [x] install.sh chmod list + CLAUDE.md layout + README (bin table, step 8) + CHANGELOG
+- [x] Live test on the running server: marker → g exits; no marker → k stays, q exits; marker → C-u stays; script idempotent
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 24ff8cd..3f10249 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). Versioning: se
- `gitconfig`: fixed `core.hooksPath = ~/.claude/githooks`.
- `tmux.conf`: move panes between windows — `J`/`L` join the marked pane below/beside, `S` swaps it with the current one, `(`/`)` (repeatable) move the pane to the previous/next slot.
- `tmux.conf`: window tabs centred in the status bar (`absolute-centre`), with index, padding and a blank between tabs; the current tab bold on a light pill.
+- `bin/tmux-copy-exit-keys` + `tmux.conf`: after a mouse selection any bare key leaves copy-mode and returns to the prompt (key swallowed); ctrl/alt keys, and copy-mode opened from the keyboard or the wheel, keep their vi role.
### Changed
- `.githooks/post-commit` and `post-merge` fail closed on `gitflow.autopush`: an unreadable or non-boolean value means no push, with a named warning (was: silently treated as `true`).
diff --git a/CLAUDE.md b/CLAUDE.md
index 251e490..b5fafac 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -27,6 +27,7 @@ gitconfig user-scope ~/.gitconfig template, @USER@/@EMAIL
tmux.conf tmux config (vi keys, tpm plugins) → ~/.config/tmux/tmux.conf, both OSes (tmux ≥ 3.1)
zsh/{zshrc-osx,bchanot.zsh-theme} macOS zsh option: oh-my-zsh zshrc + theme porting the bash prompt
bin/{dt,dtach-router,claude-provider} CLI scripts deployed to ~/.local/bin
+bin/tmux-copy-exit-keys run by tmux.conf at load: after a mouse selection any bare key leaves copy-mode
bin/repo-sync multi-forge repo tree (gitlab/github/gitea/bitbucket cloud) → ~/repos, daily cache;
tokens in ~/.config/repos/forges.conf (0600, never tracked); `repo` fn in the rc files
etc/profile.d/disk-usage-warning.sh login-time low-disk warning → /etc/profile.d (Linux only)
diff --git a/README.md b/README.md
index d55837a..92078f0 100644
--- a/README.md
+++ b/README.md
@@ -36,6 +36,7 @@ curl -fsSL https://git.bchanot.fr/bchanot/config/raw/branch/main/remote-install.
| `bin/dt` | dtach session manager for claude-in-dtach sessions. |
| `bin/dtach-router` | Dashboard to resume dtach sessions, shown at the start of every interactive shell (wired into `~/.bashrc` by the installer). |
| `bin/claude-provider`| Switch Claude Code between Anthropic and OpenRouter. |
+| `bin/tmux-copy-exit-keys` | Run by `tmux.conf` at load: after a mouse selection, any bare key leaves copy-mode (ctrl/alt keys and keyboard copy-mode keep their vi role). |
| `bin/repo-sync` | One local tree (`~/repos`) for every repository reachable on your forges (GitLab, GitHub, Gitea/Forgejo, Bitbucket Cloud), daily cache, `repo ` shell function to jump into one. |
| `etc/profile.d/disk-usage-warning.sh` | Login-time warning (bold red) when `/` or `/home` cross 85% usage. Deployed to `/etc/profile.d/` on Linux. |
@@ -69,7 +70,7 @@ What it does:
5. Copies the tracked vim files into `~/.vim` and symlinks `~/.vimrc`.
6. Picks the bashrc by OS: macOS → `bashrc-osx` (falls back to `bashrc-linux` if missing), everything else → `bashrc-linux`. Renders it into `~/.bashrc` with the identity asked at the very start: a name and an email for git commits and vim headers. An `export USER=` / `export EMAIL=` already present in `~/.bashrc` or `~/.zshrc` is reused without asking, so a re-run never prompts twice; `IDENTITY_USER` / `IDENTITY_EMAIL` preset them; with no terminal attached it falls back to the login name and an empty email. The values live only in the deployed files, never in the repo. Then renders `gitconfig` into `~/.gitconfig` with the same name and email (skipped, push mode included, when the name or email is empty, e.g. a first install with no terminal and no `IDENTITY_EMAIL`). The installer asks once whether the gitflow hooks push every commit and merge (`true` or `false` exactly, Enter = `true`); a `true`/`false` already in `~/.gitconfig` is reused without asking and survives the redeploy; `DOTFILES_GITFLOW_AUTOPUSH=true|false` presets it for a non-interactive install, an existing `~/.gitconfig` value still winning (no terminal and no preset gives `true`; any other preset aborts the install); the render refuses to write a file where `@AUTOPUSH@` leaked, since a non-boolean value blocks every push. To switch later: `git config --global gitflow.autopush true|false`. A different existing `~/.gitconfig` is saved as `~/.gitconfig.backup-`; an identical one is left alone. It is the global level only: a repo's own `.git/config` still overrides it. `core.excludesfile` points at `~/.gitignore`, ignored by git when the file does not exist. `core.hooksPath` is fixed to `~/.claude/githooks`, the gitflow hooks created by `make link` in the claude-config repo; the installer neither creates nor checks that directory. Being global, it makes git ignore each repo's `.git/hooks/` unless that repo sets its own `core.hooksPath`. Then deploys `tmux.conf` to `~/.config/tmux/tmux.conf` (both OSes, tmux ≥ 3.1: Ubuntu 22.04+, brew), clones [tpm](https://github.com/tmux-plugins/tpm) and fetches the listed plugins headlessly; details under [macOS](#macos) step 6, the step is the same. On Linux, `y` copies into tmux's buffer and the terminal clipboard through OSC 52; macOS uses `pbcopy`/`pbpaste`.
7. Installs Python CLIs via `pipx` (`PyMuPDF` → `pymupdf`, `Markdown` → `markdown_py`) — skipped if `pipx` is absent.
-8. Copies the `bin/` scripts (`dt`, `dtach-router`, `claude-provider`) into `~/.local/bin`. The dtach session-resume menu ships in the deployed bashrc (both OSes), so every interactive shell offers it — including VS Code Remote-SSH terminals, which are non-login and never read `~/.profile`. The installer also strips any older dtach block left in `~/.profile` so a plain SSH login doesn't prompt twice.
+8. Copies the `bin/` scripts (`dt`, `dtach-router`, `claude-provider`, `repo-sync`, `tmux-copy-exit-keys`) into `~/.local/bin`. The dtach session-resume menu ships in the deployed bashrc (both OSes), so every interactive shell offers it — including VS Code Remote-SSH terminals, which are non-login and never read `~/.profile`. The installer also strips any older dtach block left in `~/.profile` so a plain SSH login doesn't prompt twice.
9. On Linux, installs `etc/profile.d/disk-usage-warning.sh` to `/etc/profile.d/` (needs `sudo`) so each login warns when `/` or `/home` cross 85% usage.
10. On Linux, installs **code-server** (VS Code in the browser) via its vendor script — skipped if already present — and enables the `code-server@` systemd service (login from `id -un`: the bashrc overrides `$USER`).
11. On Linux, installs **`ubuntu-desktop-minimal`** (GDM + GNOME Shell, ~1.5 GB): the RDP remote login below hands out a GNOME session, which a bare server install does not have. Then sets up **RDP remote login** via `gnome-remote-desktop` (Wayland-native): installs the daemon + `openssl`, generates a self-signed TLS cert once, and prompts interactively for shared "gate" credentials (skipped when no terminal is attached, or already set). Disables `xrdp` if present; opens UFW port `3389` only when UFW is already active. Finally, when `lspci` sees an NVIDIA GPU, runs `ubuntu-drivers install` to put on the driver the distro recommends for the card (no version pinned; loads at the next reboot). Skipped on machines without an NVIDIA GPU.
diff --git a/bin/tmux-copy-exit-keys b/bin/tmux-copy-exit-keys
new file mode 100755
index 0000000..e5b3fe6
--- /dev/null
+++ b/bin/tmux-copy-exit-keys
@@ -0,0 +1,77 @@
+#!/usr/bin/env bash
+# tmux-copy-exit-keys: after a mouse selection, any unmodified key leaves
+# copy-mode (back to the prompt; the key itself is swallowed).
+#
+# tmux.conf sets the pane option @mouse_sel when a mouse drag ends in
+# copy-mode and clears it when the pane leaves copy-mode (pane-mode-changed
+# hook). This script wraps every unmodified copy-mode-vi key: marker set, the
+# key cancels copy-mode; marker unset (copy-mode opened from the keyboard or
+# the wheel), the key keeps its vi role. Keys with ctrl/alt are untouched.
+# tmux.conf runs it (run-shell) after the copy-mode bindings and the plugins:
+# it wraps the bindings as they stand, so it must come last. Re-runnable:
+# a key already wrapped is left alone. Needs bash 3.2 (macOS /bin/bash).
+set -euo pipefail
+
+TABLE=copy-mode-vi
+GUARD='if-shell -F "#{@mouse_sel}"' # the wrapper as list-keys prints it
+
+# Every key a bare keypress can produce: letters, digits, ASCII punctuation,
+# the French AZERTY extras, named editing and navigation keys.
+plain_keys() {
+ printf '%s\n' {a..z} {A..Z} {0..9} \
+ '`' '~' '!' '@' '#' '$' '%' '^' '&' '*' '(' ')' '-' '_' '=' '+' \
+ '[' ']' '{' '}' "\\" '|' ';' ':' "'" '"' ',' '.' '<' '>' '/' '?' \
+ é è à ç ù § ° ² µ £ \
+ Space Enter Tab BSpace Escape Home End PPage NPage \
+ Up Down Left Right IC DC
+}
+
+# A key as the tmux config parser wants it (the form list-keys prints);
+# ~ included, else the parser expands it to $HOME.
+conf_key() {
+ case "$1" in
+ ';' | '{' | '}' | '#' | '$' | '%' | '"' | "'" | "\\" | '~') printf '\\%s\n' "$1" ;;
+ *) printf '%s\n' "$1" ;;
+ esac
+}
+
+# Current bindings of TABLE as "keycommand" lines, keys in conf form.
+# A -r (repeat) flag is dropped: no copy-mode key uses it.
+current_bindings() {
+ tmux list-keys -T "$TABLE" \
+ | sed -E "s/^bind-key +(-r +)?-T $TABLE +([^ ]+) +(.*)\$/\\2$(printf '\t')\\3/"
+}
+
+# The command bound to conf key $1 in the dump $2, empty when unbound.
+bound_command() {
+ awk -F '\t' -v k="$1" '$1 == k { print $2; exit }' "$2"
+}
+
+# One bind-key line per plain key: marker set, cancel; else the current role.
+emit_bindings() {
+ local dump="$1" key ck cmd
+ while IFS= read -r key; do
+ ck=$(conf_key "$key")
+ cmd=$(bound_command "$ck" "$dump")
+ case "$cmd" in "$GUARD"*) continue ;; esac
+ if [ -n "$cmd" ]; then
+ printf 'bind-key -T %s %s %s { send-keys -X cancel } { %s }\n' \
+ "$TABLE" "$ck" "$GUARD" "$cmd"
+ else
+ printf 'bind-key -T %s %s %s { send-keys -X cancel }\n' \
+ "$TABLE" "$ck" "$GUARD"
+ fi
+ done < <(plain_keys)
+}
+
+main() {
+ local dump fragment
+ dump=$(mktemp) && fragment=$(mktemp)
+ # shellcheck disable=SC2064 # expand now: the locals are gone at EXIT
+ trap "rm -f '$dump' '$fragment'" EXIT
+ current_bindings > "$dump"
+ emit_bindings "$dump" > "$fragment"
+ tmux source-file "$fragment"
+}
+
+main "$@"
diff --git a/install.sh b/install.sh
index acf070c..03a25b5 100755
--- a/install.sh
+++ b/install.sh
@@ -788,12 +788,14 @@ if command -v pipx >/dev/null 2>&1; then
pipx ensurepath >/dev/null
fi
-# Deploy personal CLI scripts to ~/.local/bin (dt, dtach-router, claude-provider, repo-sync).
+# Deploy personal CLI scripts to ~/.local/bin (dt, dtach-router, claude-provider, repo-sync,
+# tmux-copy-exit-keys).
echo "Deploying CLI scripts to ~/.local/bin"
mkdir -p "$HOME/.local/bin"
cp "$SCRIPT_DIR"/bin/* "$HOME/.local/bin/"
chmod +x "$HOME"/.local/bin/dt "$HOME"/.local/bin/dtach-router \
- "$HOME"/.local/bin/claude-provider "$HOME"/.local/bin/repo-sync
+ "$HOME"/.local/bin/claude-provider "$HOME"/.local/bin/repo-sync \
+ "$HOME"/.local/bin/tmux-copy-exit-keys
# Remove any stale dtach wiring from ~/.profile (the menu now ships in ~/.bashrc; see above).
diff --git a/tmux.conf b/tmux.conf
index 5755fbd..bcadd11 100644
--- a/tmux.conf
+++ b/tmux.conf
@@ -154,9 +154,11 @@ bind -Tcopy-mode-vi 'v' send -X begin-selection # bind vi-like visual mode
# Releasing a mouse drag copies too (selection kept on screen, copy-mode stays).
# alt+c (in a selection) = y, alt+v (anywhere, no prefix) = prefix p: cmd-less
# keyboards. GNOME Terminal: keep "Enable mnemonics" off or alt+v opens View.
+# A finished drag also marks the pane (@mouse_sel): from then on any bare key
+# leaves copy-mode, see the hook below and the run-shell at the end of file.
if-shell 'command -v pbcopy >/dev/null' \
- 'bind -Tcopy-mode-vi y send -X copy-pipe-and-cancel pbcopy ; bind -Tcopy-mode-vi M-c send -X copy-pipe-and-cancel pbcopy ; bind -Tcopy-mode-vi MouseDragEnd1Pane send -X copy-pipe-no-clear pbcopy ; bind p run "pbpaste | tmux load-buffer - ; tmux paste-buffer" ; bind -n M-v run "pbpaste | tmux load-buffer - ; tmux paste-buffer"' \
- 'bind -Tcopy-mode-vi y send -X copy-selection-and-cancel ; bind -Tcopy-mode-vi M-c send -X copy-selection-and-cancel ; bind -Tcopy-mode-vi MouseDragEnd1Pane send -X copy-selection-no-clear ; bind p paste-buffer ; bind -n M-v paste-buffer'
+ 'bind -Tcopy-mode-vi y send -X copy-pipe-and-cancel pbcopy ; bind -Tcopy-mode-vi M-c send -X copy-pipe-and-cancel pbcopy ; bind -Tcopy-mode-vi MouseDragEnd1Pane send -X copy-pipe-no-clear pbcopy \; set -p @mouse_sel 1 ; bind p run "pbpaste | tmux load-buffer - ; tmux paste-buffer" ; bind -n M-v run "pbpaste | tmux load-buffer - ; tmux paste-buffer"' \
+ 'bind -Tcopy-mode-vi y send -X copy-selection-and-cancel ; bind -Tcopy-mode-vi M-c send -X copy-selection-and-cancel ; bind -Tcopy-mode-vi MouseDragEnd1Pane send -X copy-selection-no-clear \; set -p @mouse_sel 1 ; bind p paste-buffer ; bind -n M-v paste-buffer'
bind-key -Tcopy-mode-vi Escape send -X cancel # cancel v mode
bind-key -Tcopy-mode-vi ^v send -X rectangle-toggle # cancel v mode
@@ -179,6 +181,9 @@ bind -n MouseDrag1Pane if -Ft= '#{mouse_any_flag}' 'if -Ft= "#{pane_in_mode}" "c
# Inner quotes stay plain: `\"` is literal inside '...' since tmux 3.0, and the
# mouse-app branch (claude, vim) then dies with "syntax error" on every drag.
# }}}
+# @mouse_sel (set by MouseDragEnd1Pane above) must not outlive the copy-mode
+# it was set in, whatever way that mode ends: cleared when the pane leaves it.
+set-hook -g pane-mode-changed 'if -F "#{!:#{pane_in_mode}}" "set -pu @mouse_sel"'
bind-key k "split-window -v -b -c '#{pane_current_path}'"
bind-key h "split-window -h -b -c '#{pane_current_path}'"
@@ -310,3 +315,8 @@ set-option -g message-command-style bg=default,fg=brightwhite
run '~/.config/tmux/plugins/tpm/tpm'
+# After a mouse selection any bare key leaves copy-mode (keyboard/wheel
+# copy-mode keeps its vi keys). Wraps the bindings as they stand, so it runs
+# last, after the plugins. Script deployed by install.sh with the other bins.
+run-shell '~/.local/bin/tmux-copy-exit-keys'
+