diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-18 21:53:37 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-18 21:53:37 -0500 |
| commit | 9d804cdb4cdb14787e928a1d45c3f2023d739e41 (patch) | |
| tree | da9488c3ea5da203cd6455012dcf2aedccac1dbc | |
| parent | 3e46a6fa95e0518f837c2f5e3ee601d84ddc666a (diff) | |
| download | rulesets-9d804cdb4cdb14787e928a1d45c3f2023d739e41.tar.gz rulesets-9d804cdb4cdb14787e928a1d45c3f2023d739e41.zip | |
feat(ai): per-project opening line with host and project name
The ai launcher used to send claude a fixed instruction string ('Read .ai/protocols.org and follow all instructions.'). Every window opened the same way, with no signal in the conversation about which machine or project it belonged to. That's fine when there's one window, less fine when an ai-session has 5+ windows across two machines.
The new build_instructions helper formats the opener per project: "This is <host> <name> project. Follow all instructions in .ai/protocols.org." Host comes from uname -n (POSIX, no dependency on the hostname binary which isn't installed by default on Arch). The project name distinguishes windows; the .ai/ prefix on the path stays so claude resolves the file reliably on first read.
The three send-keys call sites all use the helper now (create_window, single_mode new-session, multi_mode first-window). Smoke-tested with rulesets, .emacs.d, jr-estate basenames.
Also fixes the stale Source/Install header comments. They still pointed at ~/projects/claude-templates/bin/ai, the pre-fold path the subtree merge replaced.
| -rwxr-xr-x | claude-templates/bin/ai | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/claude-templates/bin/ai b/claude-templates/bin/ai index 45cc56a..a167174 100755 --- a/claude-templates/bin/ai +++ b/claude-templates/bin/ai @@ -15,8 +15,8 @@ # # ai -h | --help Show this help. # -# Source: ~/projects/claude-templates/bin/ai -# Install: make -C ~/projects/claude-templates install +# Source: ~/code/rulesets/claude-templates/bin/ai +# Install: make -C ~/code/rulesets install # # NOTE: do not enable `set -e`. Several helper functions use # `[ test ] && action` patterns that legitimately return non-zero when @@ -26,7 +26,17 @@ SESSION="ai" CLAUDE_CMD="claude" -CLAUDE_INSTRUCTIONS='Read .ai/protocols.org and follow all instructions.' + +# Format the per-project opening line passed to claude. Takes the project +# directory's basename; returns a string of the form +# "This is <host> <name> project. Follow all instructions in .ai/protocols.org." +# Uses uname -n for the host (POSIX, no dependency on the hostname binary +# which isn't installed by default on every distro). The project name +# disambiguates windows when multiple projects share an ai-session. +build_instructions() { + local name="$1" + printf 'This is %s %s project. Follow all instructions in .ai/protocols.org.' "$(uname -n)" "$name" +} usage() { sed -n '2,20p' "$0" | sed 's|^# \?||' @@ -52,10 +62,11 @@ attach_session() { # Create a window in the ai session, launch claude, return window id. create_window() { - local dir="$1" name="$2" wid + local dir="$1" name="$2" wid instructions wid=$(tmux new-window -t "$SESSION" -n "$name" -c "$dir" -P -F '#{window_id}') sleep 0.1 - tmux send-keys -t "$wid" "$CLAUDE_CMD \"$CLAUDE_INSTRUCTIONS\"" Enter + instructions=$(build_instructions "$name") + tmux send-keys -t "$wid" "$CLAUDE_CMD \"$instructions\"" Enter echo "$wid" } @@ -297,8 +308,10 @@ single_mode() { if tmux has-session -t "$SESSION" 2>/dev/null; then wid=$(create_window "$dir" "$name") else + local instructions wid=$(tmux new-session -d -s "$SESSION" -n "$name" -c "$dir" -P -F '#{window_id}') - tmux send-keys -t "$wid" "$CLAUDE_CMD \"$CLAUDE_INSTRUCTIONS\"" Enter + instructions=$(build_instructions "$name") + tmux send-keys -t "$wid" "$CLAUDE_CMD \"$instructions\"" Enter fi sort_windows @@ -355,8 +368,10 @@ multi_mode() { dir="${first/#\~/$HOME}" name="$(basename "$dir")" auto_pull_if_clean "$dir" + local instructions first_wid=$(tmux new-session -d -s "$SESSION" -n "$name" -c "$dir" -P -F '#{window_id}') - tmux send-keys -t "$first_wid" "$CLAUDE_CMD \"$CLAUDE_INSTRUCTIONS\"" Enter + instructions=$(build_instructions "$name") + tmux send-keys -t "$first_wid" "$CLAUDE_CMD \"$instructions\"" Enter for entry in "${selected[@]:1}"; do dir="${entry/#\~/$HOME}" name="$(basename "$dir")" |
