diff --git a/README.md b/README.md index fdd496479fad0c518c7a5ed7a6aa32095159fad8..0b17482f8b5915effacecbc4929076e6211e96b1 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ Refer to [§ Token stats](#token-stats) for a detailed breakdown of each skill's - [scripting-with-go](skills/scripting-with-go/SKILL.md): Creates executable Go scripts with shebang-like behavior for long-lived automation. +- [working-with-tmux](skills/working-with-tmux/SKILL.md): Lets the LLM create, + manage, and capture output from tmux sessions/windows - [writing-roc-lang](skills/writing-roc-lang/SKILL.md): Writes Roc code with strong static types, helpful compiler errors, and functional programming. Covers both full applications and one-off scripts. @@ -330,14 +332,14 @@ Token breakdown: ─────────────────────────────────────────────── Total: 2108 tokens -=== tmux === +=== working-with-tmux === Token breakdown: - Name: 15 tokens + Name: 22 tokens Description: 84 tokens - Body: 1468 tokens (87 lines) + Body: 1465 tokens (87 lines) ─────────────────────────────────────────────── - Total: 1567 tokens + Total: 1571 tokens === writing-roc-lang === @@ -357,9 +359,9 @@ SUMMARY ============================================================ Skills: 17 -Metadata: 2360 tokens -Combined bodies: 38677 tokens -Overall: 151500 tokens +Metadata: 2367 tokens +Combined bodies: 38674 tokens +Overall: 151504 tokens Validation errors: 0 Largest skills (by total tokens): diff --git a/skills/working-with-tmux/SKILL.md b/skills/working-with-tmux/SKILL.md new file mode 100644 index 0000000000000000000000000000000000000000..f8b260936de8509609ad7c466b77e87f31b75361 --- /dev/null +++ b/skills/working-with-tmux/SKILL.md @@ -0,0 +1,94 @@ +--- +name: working-with-tmux +description: Instructions for using tmux to spawn multiple processes, inspect them, and capture their output. Useful for running servers or long-running tasks in the background. +metadata: + source: https://github.com/ampcode/amp-contrib +--- + +This skill lets you manage multiple concurrent processes (like servers, watchers, or long builds) using `tmux` directly from the `Bash` tool. + +Since you are likely already running inside a tmux session, you can spawn new windows or panes to handle these tasks without blocking your main communication channel. + +## 1. Verify Environment & Check Status + +First, verify you are running inside tmux: + +```bash +echo $TMUX +``` + +If this returns empty, you are not running inside tmux and these commands will not work as expected. + +Once verified, check your current windows: + +```bash +tmux list-windows +``` + +## 2. Spawn a Background Process + +To run a command (e.g., a dev server) in a way that persists and can be inspected: + +1. **Create a new detached window** with a specific name. This keeps it isolated and easy to reference. + + ```bash + tmux new-window -n "server-log" -d + ``` + + _(Replace "server-log" with a relevant name for your task)_ + +2. **Send the command** to that window. + ```bash + tmux send-keys -t "server-log" "npm start" C-m + ``` + _(`C-m` simulates the Enter key)_ + +## 3. Inspect Output (Read Logs) + +You can read the output of that pane at any time without switching your context. + +**Get the current visible screen:** + +```bash +tmux capture-pane -p -t "server-log" +``` + +**Get the entire history (scrollback):** + +```bash +tmux capture-pane -p -S - -t "server-log" +``` + +_Use this if the output might have scrolled off the screen._ + +## 4. Interact with the Process + +If you need to stop or restart the process: + +**Send Ctrl+C (Interrupt):** + +```bash +tmux send-keys -t "server-log" C-c +``` + +**Kill the window (Clean up):** + +```bash +tmux kill-window -t "server-log" +``` + +## 5. Advanced: Chaining Commands + +You can chain multiple tmux commands in a single invocation using `';'` (note the quotes to avoid interpretation by the shell). This is faster and cleaner than running multiple `tmux` commands. + +Example: Create window and start process in one go: + +```bash +tmux new-window -n "server-log" -d ';' send-keys -t "server-log" "npm start" C-m +``` + +## Summary of Pattern + +1. `tmux new-window -n "ID" -d` +2. `tmux send-keys -t "ID" "CMD" C-m` +3. `tmux capture-pane -p -t "ID"`