From 293f5792ea90f6ea879444529254ea795b8455bb Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Thu, 12 Jun 2025 02:32:01 +0000 Subject: [PATCH 01/13] feat: add tmux session persistence configuration to claude-code module --- registry/coder/modules/claude-code/main.tf | 74 +++++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/registry/coder/modules/claude-code/main.tf b/registry/coder/modules/claude-code/main.tf index 1435a2f3..d488c180 100644 --- a/registry/coder/modules/claude-code/main.tf +++ b/registry/coder/modules/claude-code/main.tf @@ -84,6 +84,18 @@ variable "experiment_post_install_script" { default = null } +variable "experiment_tmux_session_persistence" { + type = bool + description = "Whether to enable tmux session persistence across workspace restarts." + default = false +} + +variable "experiment_tmux_session_save_interval" { + type = string + description = "How often to save tmux sessions in minutes." + default = "15" +} + locals { encoded_pre_install_script = var.experiment_pre_install_script != null ? base64encode(var.experiment_pre_install_script) : "" encoded_post_install_script = var.experiment_post_install_script != null ? base64encode(var.experiment_post_install_script) : "" @@ -151,6 +163,62 @@ resource "coder_script" "claude_code" { exit 1 fi + # Configure tmux session persistence if enabled + if [ "${var.experiment_tmux_session_persistence}" = "true" ] && [ "${var.experiment_use_tmux}" = "true" ]; then + echo "Setting up tmux session persistence..." + + # Check and install git if needed + if ! command_exists git; then + echo "Git not found, installing git..." + if command_exists apt-get; then + apt-get update && apt-get install -y git + elif command_exists yum; then + yum install -y git + elif command_exists dnf; then + dnf install -y git + elif command_exists pacman; then + pacman -S --noconfirm git + elif command_exists apk; then + apk add git + else + echo "Error: Unable to install git automatically. Package manager not recognized." + echo "Please install git manually to enable session persistence." + exit 1 + fi + fi + + # Install TPM and plugins + mkdir -p ~/.tmux/plugins + if [ ! -d ~/.tmux/plugins/tpm ]; then + git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm + fi + + # Configure .tmux.conf for persistence + cat > ~/.tmux.conf << EOF +# Claude Code tmux persistence configuration +set -g @plugin 'tmux-plugins/tmux-resurrect' +set -g @plugin 'tmux-plugins/tmux-continuum' + +# Configure session persistence +set -g @resurrect-processes 'claude' +set -g @continuum-restore 'on' +set -g @continuum-save-interval '${var.experiment_tmux_session_save_interval}' + +# Initialize plugin manager +run '~/.tmux/plugins/tpm/tpm' +EOF + + # Install plugins + ~/.tmux/plugins/tpm/scripts/install_plugins.sh + fi + + # Validate session persistence requirements + if [ "${var.experiment_tmux_session_persistence}" = "true" ] && [ "${var.experiment_use_tmux}" != "true" ]; then + echo "Error: Session persistence requires tmux to be enabled." + echo "Please set experiment_use_tmux = true when using session persistence." + exit 1 + fi + # Run with tmux if enabled if [ "${var.experiment_use_tmux}" = "true" ]; then echo "Running Claude Code in the background with tmux..." @@ -166,8 +234,10 @@ resource "coder_script" "claude_code" { export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 - # Create a new tmux session in detached mode - tmux new-session -d -s claude-code -c ${var.folder} "claude --dangerously-skip-permissions \"$CODER_MCP_CLAUDE_TASK_PROMPT\"" + # Create or attach to session (persistence handles restoration automatically) + if ! tmux has-session -t claude-code 2>/dev/null; then + tmux new-session -d -s claude-code -c ${var.folder} "claude --dangerously-skip-permissions \"$CODER_MCP_CLAUDE_TASK_PROMPT\"" + fi fi From 65320bef0e4b923b09a702f424df755380f2a4ea Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Thu, 12 Jun 2025 02:32:13 +0000 Subject: [PATCH 02/13] docs: add session persistence section to claude-code README --- registry/coder/modules/claude-code/README.md | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/registry/coder/modules/claude-code/README.md b/registry/coder/modules/claude-code/README.md index 5056ce71..f39d40fd 100644 --- a/registry/coder/modules/claude-code/README.md +++ b/registry/coder/modules/claude-code/README.md @@ -100,6 +100,29 @@ module "claude-code" { } ``` +## Session Persistence (Experimental) + +Enable automatic session persistence to maintain Claude Code sessions across workspace restarts: + +```tf +module "claude-code" { + count = data.coder_workspace.me.start_count + source = "registry.coder.com/coder/claude-code/coder" + version = "1.4.0" + agent_id = coder_agent.example.id + folder = "/home/coder" + install_claude_code = true + + # Enable tmux with session persistence + experiment_use_tmux = true + experiment_tmux_session_persistence = true + experiment_tmux_session_save_interval = "10" # Save every 10 minutes + experiment_report_tasks = true +} +``` + +Session persistence automatically saves and restores your Claude Code environment, including working directory and command history. + ## Run standalone Run Claude Code as a standalone app in your workspace. This will install Claude Code and run it directly without using screen or any task reporting to the Coder UI. From 54b97374b40a176f63bd260b7bdfeecd8e385cd9 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Fri, 13 Jun 2025 00:50:31 +0000 Subject: [PATCH 03/13] feat: enhance Claude Code installation process with npm check including new node install via nvm if not present --- registry/coder/modules/claude-code/main.tf | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/registry/coder/modules/claude-code/main.tf b/registry/coder/modules/claude-code/main.tf index d488c180..4d8b45db 100644 --- a/registry/coder/modules/claude-code/main.tf +++ b/registry/coder/modules/claude-code/main.tf @@ -135,9 +135,32 @@ resource "coder_script" "claude_code" { # Install Claude Code if enabled if [ "${var.install_claude_code}" = "true" ]; then + # Check if npm is available, if not try to install Node.js using NVM if ! command_exists npm; then - echo "Error: npm is not installed. Please install Node.js and npm first." - exit 1 + echo "npm not found, checking for Node.js installation..." + if ! command_exists node; then + echo "Node.js not found, installing Node.js via NVM..." + # Install NVM + export NVM_DIR="$HOME/.nvm" + if [ ! -d "$NVM_DIR" ]; then + mkdir -p "$NVM_DIR" + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + else + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + fi + + # Install Node.js LTS version + nvm install --lts + nvm use --lts + nvm alias default node + + echo "Node.js installed: $(node --version)" + echo "npm installed: $(npm --version)" + else + echo "Node.js is installed but npm is not available. Please install npm manually." + exit 1 + fi fi echo "Installing Claude Code..." npm install -g @anthropic-ai/claude-code@${var.claude_code_version} From 1ae124722cd18d60b79f388486e70d03188e7fde Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Fri, 13 Jun 2025 01:04:42 +0000 Subject: [PATCH 04/13] feat: enhance tmux installation and session persistence configuration in claude-code module - Added a function to install tmux using various package managers if not already present. - Improved validation for session persistence requirements, ensuring tmux is enabled when persistence is requested. - Streamlined the installation process for git and tmux plugins within the tmux session configuration. --- registry/coder/modules/claude-code/main.tf | 120 ++++++++++++--------- 1 file changed, 68 insertions(+), 52 deletions(-) diff --git a/registry/coder/modules/claude-code/main.tf b/registry/coder/modules/claude-code/main.tf index 4d8b45db..c60afab4 100644 --- a/registry/coder/modules/claude-code/main.tf +++ b/registry/coder/modules/claude-code/main.tf @@ -115,6 +115,25 @@ resource "coder_script" "claude_code" { command -v "$1" >/dev/null 2>&1 } + # Function to install tmux if needed + install_tmux() { + echo "Installing tmux..." + if command_exists apt-get; then + apt-get update && apt-get install -y tmux + elif command_exists yum; then + yum install -y tmux + elif command_exists dnf; then + dnf install -y tmux + elif command_exists pacman; then + pacman -S --noconfirm tmux + elif command_exists apk; then + apk add tmux + else + echo "Error: Unable to install tmux automatically. Package manager not recognized." + exit 1 + fi + } + # Check if the specified folder exists if [ ! -d "${var.folder}" ]; then echo "Warning: The specified folder '${var.folder}' does not exist." @@ -186,38 +205,52 @@ resource "coder_script" "claude_code" { exit 1 fi - # Configure tmux session persistence if enabled - if [ "${var.experiment_tmux_session_persistence}" = "true" ] && [ "${var.experiment_use_tmux}" = "true" ]; then - echo "Setting up tmux session persistence..." - - # Check and install git if needed - if ! command_exists git; then - echo "Git not found, installing git..." - if command_exists apt-get; then - apt-get update && apt-get install -y git - elif command_exists yum; then - yum install -y git - elif command_exists dnf; then - dnf install -y git - elif command_exists pacman; then - pacman -S --noconfirm git - elif command_exists apk; then - apk add git - else - echo "Error: Unable to install git automatically. Package manager not recognized." - echo "Please install git manually to enable session persistence." - exit 1 - fi - fi - - # Install TPM and plugins - mkdir -p ~/.tmux/plugins - if [ ! -d ~/.tmux/plugins/tpm ]; then - git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm + # Validate session persistence requirements + if [ "${var.experiment_tmux_session_persistence}" = "true" ] && [ "${var.experiment_use_tmux}" != "true" ]; then + echo "Error: Session persistence requires tmux to be enabled." + echo "Please set experiment_use_tmux = true when using session persistence." + exit 1 + fi + + # Install and configure tmux if enabled + if [ "${var.experiment_use_tmux}" = "true" ]; then + # Install tmux if not present + if ! command_exists tmux; then + install_tmux fi - - # Configure .tmux.conf for persistence - cat > ~/.tmux.conf << EOF + + # Configure tmux session persistence if enabled + if [ "${var.experiment_tmux_session_persistence}" = "true" ]; then + echo "Setting up tmux session persistence..." + + # Check and install git if needed + if ! command_exists git; then + echo "Git not found, installing git..." + if command_exists apt-get; then + apt-get update && apt-get install -y git + elif command_exists yum; then + yum install -y git + elif command_exists dnf; then + dnf install -y git + elif command_exists pacman; then + pacman -S --noconfirm git + elif command_exists apk; then + apk add git + else + echo "Error: Unable to install git automatically. Package manager not recognized." + echo "Please install git manually to enable session persistence." + exit 1 + fi + fi + + # Install TPM and plugins + mkdir -p ~/.tmux/plugins + if [ ! -d ~/.tmux/plugins/tpm ]; then + git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm + fi + + # Configure .tmux.conf for persistence + cat > ~/.tmux.conf << EOF # Claude Code tmux persistence configuration set -g @plugin 'tmux-plugins/tmux-resurrect' set -g @plugin 'tmux-plugins/tmux-continuum' @@ -231,29 +264,12 @@ set -g @continuum-save-interval '${var.experiment_tmux_session_save_interval}' run '~/.tmux/plugins/tpm/tpm' EOF - # Install plugins - ~/.tmux/plugins/tpm/scripts/install_plugins.sh - fi - - # Validate session persistence requirements - if [ "${var.experiment_tmux_session_persistence}" = "true" ] && [ "${var.experiment_use_tmux}" != "true" ]; then - echo "Error: Session persistence requires tmux to be enabled." - echo "Please set experiment_use_tmux = true when using session persistence." - exit 1 - fi - - # Run with tmux if enabled - if [ "${var.experiment_use_tmux}" = "true" ]; then - echo "Running Claude Code in the background with tmux..." - - # Check if tmux is installed - if ! command_exists tmux; then - echo "Error: tmux is not installed. Please install tmux manually." - exit 1 + # Install plugins + ~/.tmux/plugins/tpm/scripts/install_plugins.sh fi + echo "Running Claude Code in the background with tmux..." touch "$HOME/.claude-code.log" - export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 @@ -261,7 +277,6 @@ EOF if ! tmux has-session -t claude-code 2>/dev/null; then tmux new-session -d -s claude-code -c ${var.folder} "claude --dangerously-skip-permissions \"$CODER_MCP_CLAUDE_TASK_PROMPT\"" fi - fi # Run with screen if enabled @@ -291,6 +306,7 @@ EOF echo "Adding 'acladd $(whoami)' to ~/.screenrc..." | tee -a "$HOME/.claude-code.log" echo "acladd $(whoami)" >> "$HOME/.screenrc" fi + export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 From a981c3ce2b2c9b4a6b0a4acc5a38f359a81974b3 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Fri, 13 Jun 2025 01:09:16 +0000 Subject: [PATCH 05/13] fix: add sudo to package manager commands for tmux and git installation in claude-code module --- registry/coder/modules/claude-code/main.tf | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/registry/coder/modules/claude-code/main.tf b/registry/coder/modules/claude-code/main.tf index c60afab4..d9251679 100644 --- a/registry/coder/modules/claude-code/main.tf +++ b/registry/coder/modules/claude-code/main.tf @@ -119,15 +119,15 @@ resource "coder_script" "claude_code" { install_tmux() { echo "Installing tmux..." if command_exists apt-get; then - apt-get update && apt-get install -y tmux + sudo apt-get update && sudo apt-get install -y tmux elif command_exists yum; then - yum install -y tmux + sudo yum install -y tmux elif command_exists dnf; then - dnf install -y tmux + sudo dnf install -y tmux elif command_exists pacman; then - pacman -S --noconfirm tmux + sudo pacman -S --noconfirm tmux elif command_exists apk; then - apk add tmux + sudo apk add tmux else echo "Error: Unable to install tmux automatically. Package manager not recognized." exit 1 @@ -227,15 +227,15 @@ resource "coder_script" "claude_code" { if ! command_exists git; then echo "Git not found, installing git..." if command_exists apt-get; then - apt-get update && apt-get install -y git + sudo apt-get update && sudo apt-get install -y git elif command_exists yum; then - yum install -y git + sudo yum install -y git elif command_exists dnf; then - dnf install -y git + sudo dnf install -y git elif command_exists pacman; then - pacman -S --noconfirm git + sudo pacman -S --noconfirm git elif command_exists apk; then - apk add git + sudo apk add git else echo "Error: Unable to install git automatically. Package manager not recognized." echo "Please install git manually to enable session persistence." From 662208a69cec3c6b3f40425ab565f1a15b92f19c Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Tue, 17 Jun 2025 20:07:24 +0000 Subject: [PATCH 06/13] fix: streamline installation and session management in claude-code module - Removed redundant comments and improved script clarity. - Enhanced session management for tmux, ensuring proper handling of existing sessions. --- registry/coder/modules/claude-code/main.tf | 53 ++++++++++------------ 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/registry/coder/modules/claude-code/main.tf b/registry/coder/modules/claude-code/main.tf index d9251679..fdcea285 100644 --- a/registry/coder/modules/claude-code/main.tf +++ b/registry/coder/modules/claude-code/main.tf @@ -110,12 +110,10 @@ resource "coder_script" "claude_code" { #!/bin/bash set -e - # Function to check if a command exists command_exists() { command -v "$1" >/dev/null 2>&1 } - # Function to install tmux if needed install_tmux() { echo "Installing tmux..." if command_exists apt-get; then @@ -134,7 +132,6 @@ resource "coder_script" "claude_code" { fi } - # Check if the specified folder exists if [ ! -d "${var.folder}" ]; then echo "Warning: The specified folder '${var.folder}' does not exist." echo "Creating the folder..." @@ -143,8 +140,6 @@ resource "coder_script" "claude_code" { mkdir -p "${var.folder}" echo "Folder created successfully." fi - - # Run pre-install script if provided if [ -n "${local.encoded_pre_install_script}" ]; then echo "Running pre-install script..." echo "${local.encoded_pre_install_script}" | base64 -d > /tmp/pre_install.sh @@ -152,14 +147,11 @@ resource "coder_script" "claude_code" { /tmp/pre_install.sh fi - # Install Claude Code if enabled if [ "${var.install_claude_code}" = "true" ]; then - # Check if npm is available, if not try to install Node.js using NVM if ! command_exists npm; then echo "npm not found, checking for Node.js installation..." if ! command_exists node; then echo "Node.js not found, installing Node.js via NVM..." - # Install NVM export NVM_DIR="$HOME/.nvm" if [ ! -d "$NVM_DIR" ]; then mkdir -p "$NVM_DIR" @@ -169,7 +161,6 @@ resource "coder_script" "claude_code" { [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" fi - # Install Node.js LTS version nvm install --lts nvm use --lts nvm alias default node @@ -190,7 +181,6 @@ resource "coder_script" "claude_code" { coder exp mcp configure claude-code ${var.folder} fi - # Run post-install script if provided if [ -n "${local.encoded_post_install_script}" ]; then echo "Running post-install script..." echo "${local.encoded_post_install_script}" | base64 -d > /tmp/post_install.sh @@ -198,32 +188,25 @@ resource "coder_script" "claude_code" { /tmp/post_install.sh fi - # Handle terminal multiplexer selection (tmux or screen) if [ "${var.experiment_use_tmux}" = "true" ] && [ "${var.experiment_use_screen}" = "true" ]; then echo "Error: Both experiment_use_tmux and experiment_use_screen cannot be true simultaneously." echo "Please set only one of them to true." exit 1 fi - # Validate session persistence requirements if [ "${var.experiment_tmux_session_persistence}" = "true" ] && [ "${var.experiment_use_tmux}" != "true" ]; then echo "Error: Session persistence requires tmux to be enabled." echo "Please set experiment_use_tmux = true when using session persistence." exit 1 fi - # Install and configure tmux if enabled if [ "${var.experiment_use_tmux}" = "true" ]; then - # Install tmux if not present if ! command_exists tmux; then install_tmux fi - # Configure tmux session persistence if enabled if [ "${var.experiment_tmux_session_persistence}" = "true" ]; then echo "Setting up tmux session persistence..." - - # Check and install git if needed if ! command_exists git; then echo "Git not found, installing git..." if command_exists apt-get; then @@ -243,13 +226,11 @@ resource "coder_script" "claude_code" { fi fi - # Install TPM and plugins mkdir -p ~/.tmux/plugins if [ ! -d ~/.tmux/plugins/tpm ]; then git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm fi - # Configure .tmux.conf for persistence cat > ~/.tmux.conf << EOF # Claude Code tmux persistence configuration set -g @plugin 'tmux-plugins/tmux-resurrect' @@ -257,14 +238,15 @@ set -g @plugin 'tmux-plugins/tmux-continuum' # Configure session persistence set -g @resurrect-processes 'claude' +set -g @resurrect-capture-pane-contents 'on' set -g @continuum-restore 'on' set -g @continuum-save-interval '${var.experiment_tmux_session_save_interval}' +set -g @continuum-boot 'on' # Initialize plugin manager run '~/.tmux/plugins/tpm/tpm' EOF - # Install plugins ~/.tmux/plugins/tpm/scripts/install_plugins.sh fi @@ -273,25 +255,33 @@ EOF export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8 - # Create or attach to session (persistence handles restoration automatically) - if ! tmux has-session -t claude-code 2>/dev/null; then - tmux new-session -d -s claude-code -c ${var.folder} "claude --dangerously-skip-permissions \"$CODER_MCP_CLAUDE_TASK_PROMPT\"" + if [ "${var.experiment_tmux_session_persistence}" = "true" ]; then + sleep 3 + + if tmux has-session -t claude-code 2>/dev/null; then + # Existing session - only start Claude if not running (no prompt) + if ! tmux list-panes -t claude-code -F '#{pane_current_command}' | grep -q "claude"; then + tmux send-keys -t claude-code "cd ${var.folder} && claude --dangerously-skip-permissions" C-m + fi + else + # New session - include prompt + tmux new-session -d -s claude-code -c ${var.folder} "claude --dangerously-skip-permissions \"$CODER_MCP_CLAUDE_TASK_PROMPT\"" + fi + else + if ! tmux has-session -t claude-code 2>/dev/null; then + tmux new-session -d -s claude-code -c ${var.folder} "claude --dangerously-skip-permissions \"$CODER_MCP_CLAUDE_TASK_PROMPT\"" + fi fi fi - # Run with screen if enabled if [ "${var.experiment_use_screen}" = "true" ]; then echo "Running Claude Code in the background..." - - # Check if screen is installed if ! command_exists screen; then echo "Error: screen is not installed. Please install screen manually." exit 1 fi touch "$HOME/.claude-code.log" - - # Ensure the screenrc exists if [ ! -f "$HOME/.screenrc" ]; then echo "Creating ~/.screenrc and adding multiuser settings..." | tee -a "$HOME/.claude-code.log" echo -e "multiuser on\nacladd $(whoami)" > "$HOME/.screenrc" @@ -316,7 +306,6 @@ EOF exec bash ' else - # Check if claude is installed before running if ! command_exists claude; then echo "Error: Claude Code is not installed. Please enable install_claude_code or install it manually." exit 1 @@ -343,7 +332,11 @@ resource "coder_app" "claude_code" { tmux attach-session -t claude-code else echo "Starting a new Claude Code tmux session." | tee -a "$HOME/.claude-code.log" - tmux new-session -s claude-code -c ${var.folder} "claude --dangerously-skip-permissions | tee -a \"$HOME/.claude-code.log\"; exec bash" + if [ -n "$CODER_MCP_CLAUDE_TASK_PROMPT" ]; then + tmux new-session -s claude-code -c ${var.folder} "claude --dangerously-skip-permissions \"$CODER_MCP_CLAUDE_TASK_PROMPT\" | tee -a \"$HOME/.claude-code.log\"; exec bash" + else + tmux new-session -s claude-code -c ${var.folder} "claude --dangerously-skip-permissions | tee -a \"$HOME/.claude-code.log\"; exec bash" + fi fi elif [ "${var.experiment_use_screen}" = "true" ]; then if screen -list | grep -q "claude-code"; then From 451fa0938822f19de22f45d16a05e06d099dfbb2 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Tue, 17 Jun 2025 20:07:41 +0000 Subject: [PATCH 07/13] chore(README): run bun fmt --- registry/coder/modules/claude-code/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/registry/coder/modules/claude-code/README.md b/registry/coder/modules/claude-code/README.md index f39d40fd..65a8f819 100644 --- a/registry/coder/modules/claude-code/README.md +++ b/registry/coder/modules/claude-code/README.md @@ -114,10 +114,10 @@ module "claude-code" { install_claude_code = true # Enable tmux with session persistence - experiment_use_tmux = true - experiment_tmux_session_persistence = true - experiment_tmux_session_save_interval = "10" # Save every 10 minutes - experiment_report_tasks = true + experiment_use_tmux = true + experiment_tmux_session_persistence = true + experiment_tmux_session_save_interval = "10" # Save every 10 minutes + experiment_report_tasks = true } ``` From 0ef820ce5ecd1d3c6345cba819315c8fefc1fbfd Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 18 Jun 2025 01:37:48 +0000 Subject: [PATCH 08/13] fix: update tmux session persistence configuration in claude-code module to save all processes. --- registry/coder/modules/claude-code/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/coder/modules/claude-code/main.tf b/registry/coder/modules/claude-code/main.tf index fdcea285..adb15eab 100644 --- a/registry/coder/modules/claude-code/main.tf +++ b/registry/coder/modules/claude-code/main.tf @@ -237,7 +237,7 @@ set -g @plugin 'tmux-plugins/tmux-resurrect' set -g @plugin 'tmux-plugins/tmux-continuum' # Configure session persistence -set -g @resurrect-processes 'claude' +set -g @resurrect-processes ':all:' set -g @resurrect-capture-pane-contents 'on' set -g @continuum-restore 'on' set -g @continuum-save-interval '${var.experiment_tmux_session_save_interval}' From 72a902767ad3fc6ee51cb9dbaff3c02fa101a3cf Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 18 Jun 2025 02:15:31 +0000 Subject: [PATCH 09/13] 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. --- registry/coder/modules/claude-code/main.tf | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/registry/coder/modules/claude-code/main.tf b/registry/coder/modules/claude-code/main.tf index adb15eab..95d2f913 100644 --- a/registry/coder/modules/claude-code/main.tf +++ b/registry/coder/modules/claude-code/main.tf @@ -239,9 +239,11 @@ set -g @plugin 'tmux-plugins/tmux-continuum' # Configure session persistence set -g @resurrect-processes ':all:' set -g @resurrect-capture-pane-contents 'on' +set -g @resurrect-save-bash-history 'on' set -g @continuum-restore 'on' set -g @continuum-save-interval '${var.experiment_tmux_session_save_interval}' set -g @continuum-boot 'on' +set -g @continuum-save-on 'on' # Initialize plugin manager run '~/.tmux/plugins/tpm/tpm' @@ -258,13 +260,8 @@ EOF if [ "${var.experiment_tmux_session_persistence}" = "true" ]; then sleep 3 - if tmux has-session -t claude-code 2>/dev/null; then - # Existing session - only start Claude if not running (no prompt) - if ! tmux list-panes -t claude-code -F '#{pane_current_command}' | grep -q "claude"; then - tmux send-keys -t claude-code "cd ${var.folder} && claude --dangerously-skip-permissions" C-m - fi - else - # New session - include prompt + if ! tmux has-session -t claude-code 2>/dev/null; then + # Only create a new session if one doesn't exist tmux new-session -d -s claude-code -c ${var.folder} "claude --dangerously-skip-permissions \"$CODER_MCP_CLAUDE_TASK_PROMPT\"" fi else @@ -329,6 +326,10 @@ resource "coder_app" "claude_code" { if [ "${var.experiment_use_tmux}" = "true" ]; then if tmux has-session -t claude-code 2>/dev/null; then echo "Attaching to existing Claude Code tmux session." | tee -a "$HOME/.claude-code.log" + # If Claude isn't running in the session, start it without the prompt + if ! tmux list-panes -t claude-code -F '#{pane_current_command}' | grep -q "claude"; then + tmux send-keys -t claude-code "cd ${var.folder} && claude-code -c --dangerously-skip-permissions" C-m + fi tmux attach-session -t claude-code else echo "Starting a new Claude Code tmux session." | tee -a "$HOME/.claude-code.log" From 0bf7ff26a88b04e70979c34abdae1fdbe0cd4291 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 18 Jun 2025 02:29:16 +0000 Subject: [PATCH 10/13] fix: correct command for starting Claude in tmux session within claude-code module --- registry/coder/modules/claude-code/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/coder/modules/claude-code/main.tf b/registry/coder/modules/claude-code/main.tf index 95d2f913..c6454179 100644 --- a/registry/coder/modules/claude-code/main.tf +++ b/registry/coder/modules/claude-code/main.tf @@ -328,7 +328,7 @@ resource "coder_app" "claude_code" { echo "Attaching to existing Claude Code tmux session." | tee -a "$HOME/.claude-code.log" # If Claude isn't running in the session, start it without the prompt if ! tmux list-panes -t claude-code -F '#{pane_current_command}' | grep -q "claude"; then - tmux send-keys -t claude-code "cd ${var.folder} && claude-code -c --dangerously-skip-permissions" C-m + tmux send-keys -t claude-code "cd ${var.folder} && claude -c --dangerously-skip-permissions" C-m fi tmux attach-session -t claude-code else From 98d94de799d89d5d553aad5fb5ac55d5e34adcf3 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 18 Jun 2025 13:06:11 +0000 Subject: [PATCH 11/13] chore(README): update version to 1.4.0 for claude-code module --- registry/coder/modules/claude-code/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/registry/coder/modules/claude-code/README.md b/registry/coder/modules/claude-code/README.md index 65a8f819..a9d61ee3 100644 --- a/registry/coder/modules/claude-code/README.md +++ b/registry/coder/modules/claude-code/README.md @@ -14,7 +14,7 @@ Run the [Claude Code](https://docs.anthropic.com/en/docs/agents-and-tools/claude ```tf module "claude-code" { source = "registry.coder.com/coder/claude-code/coder" - version = "1.3.1" + version = "1.4.0" agent_id = coder_agent.example.id folder = "/home/coder" install_claude_code = true @@ -88,7 +88,7 @@ resource "coder_agent" "main" { module "claude-code" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/claude-code/coder" - version = "1.3.1" + version = "1.4.0" agent_id = coder_agent.example.id folder = "/home/coder" install_claude_code = true @@ -108,7 +108,7 @@ Enable automatic session persistence to maintain Claude Code sessions across wor module "claude-code" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/claude-code/coder" - version = "1.4.0" + version = "1.4.0" agent_id = coder_agent.example.id folder = "/home/coder" install_claude_code = true @@ -130,7 +130,7 @@ Run Claude Code as a standalone app in your workspace. This will install Claude ```tf module "claude-code" { source = "registry.coder.com/coder/claude-code/coder" - version = "1.3.1" + version = "1.4.0" agent_id = coder_agent.example.id folder = "/home/coder" install_claude_code = true From c1e57455b90cfd498fb7c7b5b2ad99052b23149c Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 18 Jun 2025 13:17:40 +0000 Subject: [PATCH 12/13] fix: restore original logic for coder app since it should not inject the prompt --- registry/coder/modules/claude-code/main.tf | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/registry/coder/modules/claude-code/main.tf b/registry/coder/modules/claude-code/main.tf index c6454179..d699b4f1 100644 --- a/registry/coder/modules/claude-code/main.tf +++ b/registry/coder/modules/claude-code/main.tf @@ -333,11 +333,7 @@ resource "coder_app" "claude_code" { tmux attach-session -t claude-code else echo "Starting a new Claude Code tmux session." | tee -a "$HOME/.claude-code.log" - if [ -n "$CODER_MCP_CLAUDE_TASK_PROMPT" ]; then - tmux new-session -s claude-code -c ${var.folder} "claude --dangerously-skip-permissions \"$CODER_MCP_CLAUDE_TASK_PROMPT\" | tee -a \"$HOME/.claude-code.log\"; exec bash" - else - tmux new-session -s claude-code -c ${var.folder} "claude --dangerously-skip-permissions | tee -a \"$HOME/.claude-code.log\"; exec bash" - fi + tmux new-session -s claude-code -c ${var.folder} "claude --dangerously-skip-permissions | tee -a \"$HOME/.claude-code.log\"; exec bash" fi elif [ "${var.experiment_use_screen}" = "true" ]; then if screen -list | grep -q "claude-code"; then From 96a4492a79e1f642d9d45de38f351cb8894908f2 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 18 Jun 2025 13:27:51 +0000 Subject: [PATCH 13/13] chore: bun fmt --- registry/coder/modules/claude-code/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/registry/coder/modules/claude-code/README.md b/registry/coder/modules/claude-code/README.md index a9d61ee3..21ff81f2 100644 --- a/registry/coder/modules/claude-code/README.md +++ b/registry/coder/modules/claude-code/README.md @@ -14,7 +14,7 @@ Run the [Claude Code](https://docs.anthropic.com/en/docs/agents-and-tools/claude ```tf module "claude-code" { source = "registry.coder.com/coder/claude-code/coder" - version = "1.4.0" + version = "1.4.0" agent_id = coder_agent.example.id folder = "/home/coder" install_claude_code = true @@ -88,7 +88,7 @@ resource "coder_agent" "main" { module "claude-code" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/claude-code/coder" - version = "1.4.0" + version = "1.4.0" agent_id = coder_agent.example.id folder = "/home/coder" install_claude_code = true @@ -108,7 +108,7 @@ Enable automatic session persistence to maintain Claude Code sessions across wor module "claude-code" { count = data.coder_workspace.me.start_count source = "registry.coder.com/coder/claude-code/coder" - version = "1.4.0" + version = "1.4.0" agent_id = coder_agent.example.id folder = "/home/coder" install_claude_code = true @@ -130,7 +130,7 @@ Run Claude Code as a standalone app in your workspace. This will install Claude ```tf module "claude-code" { source = "registry.coder.com/coder/claude-code/coder" - version = "1.4.0" + version = "1.4.0" agent_id = coder_agent.example.id folder = "/home/coder" install_claude_code = true