Skip to content

Commit 72a9027

Browse files
fix: improve tmux session management in claude-code module
- Added configuration to save bash history and ensure tmux sessions are created only when they do not already exist. - Streamlined the logic for starting Claude within existing sessions, enhancing user experience and session handling.
1 parent 0ef820c commit 72a9027

File tree

1 file changed

+8
-7
lines changed
  • registry/coder/modules/claude-code

1 file changed

+8
-7
lines changed

registry/coder/modules/claude-code/main.tf

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,11 @@ set -g @plugin 'tmux-plugins/tmux-continuum'
239239
# Configure session persistence
240240
set -g @resurrect-processes ':all:'
241241
set -g @resurrect-capture-pane-contents 'on'
242+
set -g @resurrect-save-bash-history 'on'
242243
set -g @continuum-restore 'on'
243244
set -g @continuum-save-interval '${var.experiment_tmux_session_save_interval}'
244245
set -g @continuum-boot 'on'
246+
set -g @continuum-save-on 'on'
245247
246248
# Initialize plugin manager
247249
run '~/.tmux/plugins/tpm/tpm'
@@ -258,13 +260,8 @@ EOF
258260
if [ "${var.experiment_tmux_session_persistence}" = "true" ]; then
259261
sleep 3
260262
261-
if tmux has-session -t claude-code 2>/dev/null; then
262-
# Existing session - only start Claude if not running (no prompt)
263-
if ! tmux list-panes -t claude-code -F '#{pane_current_command}' | grep -q "claude"; then
264-
tmux send-keys -t claude-code "cd ${var.folder} && claude --dangerously-skip-permissions" C-m
265-
fi
266-
else
267-
# New session - include prompt
263+
if ! tmux has-session -t claude-code 2>/dev/null; then
264+
# Only create a new session if one doesn't exist
268265
tmux new-session -d -s claude-code -c ${var.folder} "claude --dangerously-skip-permissions \"$CODER_MCP_CLAUDE_TASK_PROMPT\""
269266
fi
270267
else
@@ -329,6 +326,10 @@ resource "coder_app" "claude_code" {
329326
if [ "${var.experiment_use_tmux}" = "true" ]; then
330327
if tmux has-session -t claude-code 2>/dev/null; then
331328
echo "Attaching to existing Claude Code tmux session." | tee -a "$HOME/.claude-code.log"
329+
# If Claude isn't running in the session, start it without the prompt
330+
if ! tmux list-panes -t claude-code -F '#{pane_current_command}' | grep -q "claude"; then
331+
tmux send-keys -t claude-code "cd ${var.folder} && claude-code -c --dangerously-skip-permissions" C-m
332+
fi
332333
tmux attach-session -t claude-code
333334
else
334335
echo "Starting a new Claude Code tmux session." | tee -a "$HOME/.claude-code.log"

0 commit comments

Comments
 (0)