Skip to content

Commit da75451

Browse files
MohsinHashmi-DataInnmohsin-wiserclaude
authored
fix: use claude_config_dir to store .claude.json inside .claude directory (#448)
Instead of mounting .claude.json as a separate file (which causes Docker to create it as a directory), we use CLAUDE_CONFIG_DIR environment variable to tell Claude Code to store .claude.json inside the .claude directory. This solves the problem permanently because: 1. We only mount one directory (.claude/) instead of a file + directory 2. Claude Code auto-creates .claude.json when needed inside .claude/ 3. Everything is persistent since .claude/ is mounted from host 4. No Docker file mount issues since we're not mounting a file Changes: - Add CLAUDE_CONFIG_DIR=/home/vscode/.claude environment variable - Remove .claude.json file mount (only mount .claude/ directory now) - Remove .claude.json file creation code (Claude creates it automatically) - Remove local_file resource (no longer needed) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Mohsin Hashmi <mhashmi@wiser.com> Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 3e7a86a commit da75451

2 files changed

Lines changed: 14 additions & 27 deletions

File tree

.coder/template.tf

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ provider "docker" {
4545
host = "unix:///var/run/docker.sock"
4646
}
4747

48-
# NOTE: .claude.json file is created by the host_directories provisioner script below
49-
# This ensures it's created on the host before Docker tries to mount it
48+
# NOTE: .claude.json is created inside .claude/ directory using CLAUDE_CONFIG_DIR env var
49+
# This avoids Docker file mount issues by keeping everything in one directory mount
5050

5151
# Create host directories for bind mounts before container starts
5252
resource "null_resource" "host_directories" {
@@ -74,15 +74,8 @@ resource "null_resource" "host_directories" {
7474
mkdir -p "$BASE_DIR/bash_history"
7575
mkdir -p "$BASE_DIR/gitconfig"
7676
77-
# Create .claude.json file (remove directory if it exists from previous workspace)
78-
if [ -d "$BASE_DIR/claude/.claude.json" ]; then
79-
rm -rf "$BASE_DIR/claude/.claude.json"
80-
echo "🗑️ Removed .claude.json directory"
81-
fi
82-
if [ ! -f "$BASE_DIR/claude/.claude.json" ]; then
83-
echo '{}' > "$BASE_DIR/claude/.claude.json"
84-
echo "✅ Created .claude.json file"
85-
fi
77+
# NOTE: .claude.json will be auto-created by Claude Code inside .claude/ directory
78+
# via CLAUDE_CONFIG_DIR environment variable
8679
8780
# Create .gemini/config.json if it doesn't exist
8881
if [ ! -f "$BASE_DIR/gemini/.gemini/config.json" ]; then
@@ -237,7 +230,7 @@ resource "coder_agent" "main" {
237230
fi
238231
239232
# Fix ownership of bind-mounted config files and directories
240-
for path in /home/vscode/.claude.json /home/vscode/.claude /home/vscode/.gemini \
233+
for path in /home/vscode/.claude /home/vscode/.gemini \
241234
/home/vscode/.config/gh /home/vscode/.bash_history_dir /home/vscode/.gitconfig_dir \
242235
/home/vscode/.ssh /home/vscode/.docker /home/vscode/.kube; do
243236
if [ -e "$path" ]; then
@@ -391,7 +384,9 @@ resource "docker_container" "workspace" {
391384
"JAVA_TOOL_OPTIONS=-XX:+UseContainerSupport -XX:MaxRAMPercentage=50.0",
392385
"NODE_OPTIONS=--max-old-space-size=2048",
393386
"HISTFILE=/home/vscode/.bash_history_dir/.bash_history",
394-
"GIT_CONFIG_GLOBAL=/home/vscode/.gitconfig_dir/.gitconfig"
387+
"GIT_CONFIG_GLOBAL=/home/vscode/.gitconfig_dir/.gitconfig",
388+
# Claude Code configuration directory (puts .claude.json inside .claude/ directory)
389+
"CLAUDE_CONFIG_DIR=/home/vscode/.claude"
395390
]
396391

397392
# Workspace directory (persistent Git repository)
@@ -416,14 +411,9 @@ resource "docker_container" "workspace" {
416411
container_path = "/home/vscode/.npm"
417412
}
418413

419-
# User credentials (persistent across host) - mount both file and directory
420-
# Claude config file
421-
volumes {
422-
host_path = "/home/coder/.coder-mount/${data.coder_workspace_owner.me.name}/claude/.claude.json"
423-
container_path = "/home/vscode/.claude.json"
424-
}
425-
426-
# Claude data directory (for cache, sessions, etc.)
414+
# User credentials (persistent across host)
415+
# Claude directory (contains .claude.json, settings.json, and cache)
416+
# CLAUDE_CONFIG_DIR env var tells Claude to look for .claude.json here
427417
volumes {
428418
host_path = "/home/coder/.coder-mount/${data.coder_workspace_owner.me.name}/claude/.claude"
429419
container_path = "/home/vscode/.claude"
@@ -518,7 +508,7 @@ resource "docker_container" "workspace" {
518508
depends_on = [
519509
docker_container.postgres,
520510
docker_container.redis,
521-
null_resource.host_directories # Ensures .claude.json is created before mounting
511+
null_resource.host_directories
522512
]
523513

524514
# Auto-restart on failure

.devcontainer/Dockerfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,10 @@ RUN . /usr/local/share/nvm/nvm.sh && (npm ci --legacy-peer-deps --ignore-scripts
151151
USER root
152152
RUN rm -rf /tmp/backend /tmp/root /tmp/frontend
153153

154-
# Pre-create user directories and files to avoid permission issues in post-create
154+
# Pre-create user directories to avoid permission issues in post-create
155155
USER vscode
156156
RUN mkdir -p ~/.m2/repository ~/.m2/wrapper/dists ~/.npm ~/.cache/ms-playwright \
157-
&& chmod -R 755 ~/.m2 ~/.npm ~/.cache \
158-
# Create .claude.json file to ensure it exists before volume mount
159-
&& echo '{}' > ~/.claude.json \
160-
&& echo "Created .claude.json file in container image"
157+
&& chmod -R 755 ~/.m2 ~/.npm ~/.cache
161158

162159
# Reset working directory and user
163160
USER root

0 commit comments

Comments
 (0)