@@ -45,6 +45,20 @@ provider "docker" {
4545 host = " unix:///var/run/docker.sock"
4646}
4747
48+ # Create .claude.json file using Terraform (ensures it exists before Docker mounts)
49+ resource "local_file" "claude_config" {
50+ filename = " /home/coder/.coder-mount/${ data . coder_workspace_owner . me . name } /claude/.claude.json"
51+ content = " {}"
52+
53+ # Only create if doesn't exist, don't overwrite user's config
54+ lifecycle {
55+ ignore_changes = [content ]
56+ }
57+
58+ # Ensure parent directory exists first
59+ depends_on = [null_resource. host_directories ]
60+ }
61+
4862# Create host directories for bind mounts before container starts
4963resource "null_resource" "host_directories" {
5064 # Re-run when workspace is rebuilt
@@ -71,24 +85,8 @@ resource "null_resource" "host_directories" {
7185 mkdir -p "$BASE_DIR/bash_history"
7286 mkdir -p "$BASE_DIR/gitconfig"
7387
74- # Create .claude.json as a file (not directory) - CRITICAL FIX
75- # Docker creates missing mount paths as directories, so we must ensure this exists as a file first
76- if [ -d "$BASE_DIR/claude/.claude.json" ]; then
77- rm -rf "$BASE_DIR/claude/.claude.json"
78- echo "⚠️ Removed .claude.json directory (was incorrectly created as directory)"
79- fi
80- # Always ensure it's a file, not a directory
81- if [ ! -f "$BASE_DIR/claude/.claude.json" ]; then
82- touch "$BASE_DIR/claude/.claude.json"
83- echo '{}' > "$BASE_DIR/claude/.claude.json"
84- chmod 644 "$BASE_DIR/claude/.claude.json"
85- echo "✅ Created .claude.json as file with proper permissions"
86- fi
87- # Verify it's a file (safety check)
88- if [ ! -f "$BASE_DIR/claude/.claude.json" ]; then
89- echo "❌ ERROR: .claude.json could not be created as file!"
90- exit 1
91- fi
88+ # NOTE: .claude.json is now created by Terraform local_file resource
89+ # This ensures it exists before Docker tries to mount it
9290
9391 # Create .gemini/config.json if it doesn't exist
9492 if [ ! -f "$BASE_DIR/gemini/.gemini/config.json" ]; then
@@ -524,7 +522,8 @@ resource "docker_container" "workspace" {
524522 depends_on = [
525523 docker_container . postgres ,
526524 docker_container . redis ,
527- null_resource. host_directories
525+ null_resource. host_directories ,
526+ local_file . claude_config # Ensure .claude.json exists before mounting
528527 ]
529528
530529 # Auto-restart on failure
0 commit comments