diff --git a/registry/coder/modules/claude-code/README.md b/registry/coder/modules/claude-code/README.md index 5056ce71..86a8e522 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 @@ -107,7 +107,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 @@ -117,3 +117,41 @@ module "claude-code" { icon = "https://registry.npmmirror.com/@lobehub/icons-static-png/1.24.0/files/dark/claude-color.png" } ``` + +## Enable user memory + +Claude Code supports [user memory](https://docs.anthropic.com/en/docs/claude-code/memory-management) that persists across all projects. This memory is stored in `~/.claude/CLAUDE.md` and contains personal preferences, coding standards, and instructions that apply to all your work. + +```tf +module "claude-code" { + 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 + claude_code_version = "latest" + + # Enable user memory + enable_user_memory = true + user_memory_content = <<-EOT + # My Claude Code Preferences + + ## Coding Style + - Always use descriptive variable names + - Prefer explicit over implicit code + - Add comments for complex logic + + ## Preferred Technologies + - Use TypeScript for JavaScript projects + - Prefer functional programming patterns + - Use modern ES6+ syntax + + ## Testing + - Write unit tests for all functions + - Use descriptive test names + - Aim for high test coverage + EOT +} +``` + +The `user_memory_content` is only used to create the initial `~/.claude/CLAUDE.md` file if it doesn't already exist. Once created, you can edit this file directly to update your preferences, and they will persist across workspace rebuilds since the file lives in the user's home directory outside the workspace. diff --git a/registry/coder/modules/claude-code/main.tf b/registry/coder/modules/claude-code/main.tf index 1435a2f3..45f5d887 100644 --- a/registry/coder/modules/claude-code/main.tf +++ b/registry/coder/modules/claude-code/main.tf @@ -84,9 +84,22 @@ variable "experiment_post_install_script" { default = null } +variable "enable_user_memory" { + type = bool + description = "Whether to enable user memory for Claude Code. This creates ~/.claude/CLAUDE.md for persistent user preferences." + default = false +} + +variable "user_memory_content" { + type = string + description = "Initial content for the user memory file (~/.claude/CLAUDE.md). Only used if the file doesn't already exist." + default = null +} + 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) : "" + encoded_user_memory_content = var.user_memory_content != null ? base64encode(var.user_memory_content) : "" } # Install and Initialize Claude Code @@ -113,6 +126,28 @@ resource "coder_script" "claude_code" { echo "Folder created successfully." fi + # Set up user memory if enabled + if [ "${var.enable_user_memory}" = "true" ]; then + echo "Setting up Claude Code user memory..." + + # Create the .claude directory if it doesn't exist + if [ ! -d "$HOME/.claude" ]; then + echo "Creating ~/.claude directory..." + mkdir -p "$HOME/.claude" + fi + + # Create the user memory file if it doesn't exist and content is provided + if [ ! -f "$HOME/.claude/CLAUDE.md" ] && [ -n "${local.encoded_user_memory_content}" ]; then + echo "Creating user memory file ~/.claude/CLAUDE.md..." + echo "${local.encoded_user_memory_content}" | base64 -d > "$HOME/.claude/CLAUDE.md" + echo "User memory file created successfully." + elif [ -f "$HOME/.claude/CLAUDE.md" ]; then + echo "User memory file ~/.claude/CLAUDE.md already exists, skipping creation." + else + echo "User memory enabled but no initial content provided. You can manually create ~/.claude/CLAUDE.md later." + fi + fi + # Run pre-install script if provided if [ -n "${local.encoded_pre_install_script}" ]; then echo "Running pre-install script..."