Skip to content

Commit f59ea6f

Browse files
feat: add user memory support to claude-code module
- Add enable_user_memory variable to enable/disable user memory functionality - Add user_memory_content variable for initial memory content - Create ~/.claude/CLAUDE.md file for persistent user preferences - Add comprehensive documentation with examples - User memory persists outside workspace for cross-project preferences Co-authored-by: DevelopmentCats <176868952+DevelopmentCats@users.noreply.github.com>
1 parent 6d1e99d commit f59ea6f

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

registry/coder/modules/claude-code/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,41 @@ module "claude-code" {
117117
icon = "https://registry.npmmirror.com/@lobehub/icons-static-png/1.24.0/files/dark/claude-color.png"
118118
}
119119
```
120+
121+
## Enable user memory
122+
123+
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.
124+
125+
```tf
126+
module "claude-code" {
127+
source = "registry.coder.com/coder/claude-code/coder"
128+
version = "1.3.1"
129+
agent_id = coder_agent.example.id
130+
folder = "/home/coder"
131+
install_claude_code = true
132+
claude_code_version = "latest"
133+
134+
# Enable user memory
135+
enable_user_memory = true
136+
user_memory_content = <<-EOT
137+
# My Claude Code Preferences
138+
139+
## Coding Style
140+
- Always use descriptive variable names
141+
- Prefer explicit over implicit code
142+
- Add comments for complex logic
143+
144+
## Preferred Technologies
145+
- Use TypeScript for JavaScript projects
146+
- Prefer functional programming patterns
147+
- Use modern ES6+ syntax
148+
149+
## Testing
150+
- Write unit tests for all functions
151+
- Use descriptive test names
152+
- Aim for high test coverage
153+
EOT
154+
}
155+
```
156+
157+
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.

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,22 @@ variable "experiment_post_install_script" {
8484
default = null
8585
}
8686

87+
variable "enable_user_memory" {
88+
type = bool
89+
description = "Whether to enable user memory for Claude Code. This creates ~/.claude/CLAUDE.md for persistent user preferences."
90+
default = false
91+
}
92+
93+
variable "user_memory_content" {
94+
type = string
95+
description = "Initial content for the user memory file (~/.claude/CLAUDE.md). Only used if the file doesn't already exist."
96+
default = null
97+
}
98+
8799
locals {
88100
encoded_pre_install_script = var.experiment_pre_install_script != null ? base64encode(var.experiment_pre_install_script) : ""
89101
encoded_post_install_script = var.experiment_post_install_script != null ? base64encode(var.experiment_post_install_script) : ""
102+
encoded_user_memory_content = var.user_memory_content != null ? base64encode(var.user_memory_content) : ""
90103
}
91104

92105
# Install and Initialize Claude Code
@@ -113,6 +126,28 @@ resource "coder_script" "claude_code" {
113126
echo "Folder created successfully."
114127
fi
115128
129+
# Set up user memory if enabled
130+
if [ "${var.enable_user_memory}" = "true" ]; then
131+
echo "Setting up Claude Code user memory..."
132+
133+
# Create the .claude directory if it doesn't exist
134+
if [ ! -d "$HOME/.claude" ]; then
135+
echo "Creating ~/.claude directory..."
136+
mkdir -p "$HOME/.claude"
137+
fi
138+
139+
# Create the user memory file if it doesn't exist and content is provided
140+
if [ ! -f "$HOME/.claude/CLAUDE.md" ] && [ -n "${local.encoded_user_memory_content}" ]; then
141+
echo "Creating user memory file ~/.claude/CLAUDE.md..."
142+
echo "${local.encoded_user_memory_content}" | base64 -d > "$HOME/.claude/CLAUDE.md"
143+
echo "User memory file created successfully."
144+
elif [ -f "$HOME/.claude/CLAUDE.md" ]; then
145+
echo "User memory file ~/.claude/CLAUDE.md already exists, skipping creation."
146+
else
147+
echo "User memory enabled but no initial content provided. You can manually create ~/.claude/CLAUDE.md later."
148+
fi
149+
fi
150+
116151
# Run pre-install script if provided
117152
if [ -n "${local.encoded_pre_install_script}" ]; then
118153
echo "Running pre-install script..."

0 commit comments

Comments
 (0)