Skip to content

Commit bf8334a

Browse files
committed
refactor: auth system and environment handling
- auth: unified --auth-with pattern, proper model handling - env: add -e flag support and custom config dir - docker: move to /home/claude, fix permissions - security: controlled mounts, proper RO handling - cleanup: standardize env vars CLAUDE_YOLO_* → CCYOLO_*
1 parent 2b84520 commit bf8334a

7 files changed

Lines changed: 419 additions & 153 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,6 @@ dist
142142
.svelte-kit
143143

144144
# End of https://www.toptal.com/developers/gitignore/api/node
145+
146+
# Claude YOLO Pro - Private build directory
147+
claude-yolo-pro/

DEV-LOGS.md

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,130 @@
11
# Development Logs
2-
- Prepend new entries with `## Issue Analysis: YYYY-MM-DD`.
2+
- Prepend new entries with `## Dev Log: YYYY-MM-DD`.
3+
- Reference issue numbers in the format `#<issue-number>` for easy linking.
34
- We write or explain to the damn point. Be clear, be super concise - no fluff, no hand-holding, no repeating.
45
- Minimal markdown markers, no unnecessary formatting, minimal unicode emojis.
56

7+
## Dev Log: 2025-07-09
8+
9+
### [enhancement-completed] Auth system overhaul and environment handling
10+
11+
**Problem**: Messy auth flags, poor environment handling, inconsistent Docker mounts.
12+
13+
**Solution**:
14+
- Unified auth with `--auth-with` pattern (claude|api-key|bedrock|vertex)
15+
- Proper environment var handling with `-e` flag
16+
- Controlled auth directory mounting with explicit permissions
17+
- Smart model name handling for each auth mode
18+
19+
**Technical**:
20+
- Freed -v for Docker volume mounts (was conflicting with --vertex)
21+
- Added model name translation for API key mode
22+
- Implemented proper ARN generation for Bedrock
23+
- Added environment detection for tools and auth status
24+
25+
**Result**: Clean auth system, proper env handling, secure mounts.
26+
27+
---
28+
29+
## Dev Log: 2025-07-08
30+
31+
### [enhancement-completed] Custom config directory and environment variable support
32+
33+
**Problem**: Users needed separate auth sessions for different projects and better environment variable handling.
34+
35+
**Root Cause**: Fixed path mounting made multi-project auth management difficult, no env var support in Docker mode.
36+
37+
**Solution**: Added `--config` flag for custom Claude config home and `-e` flag for environment variables.
38+
39+
**Implementation**:
40+
- `--config ~/work-claude` creates and mounts custom config directory
41+
- `-e NODE_ENV=dev` or `-e DEBUG` passes environment variables
42+
- Fixed npm-global path handling for claude user
43+
- Standardized mount paths to `/home/claude` instead of `/root`
44+
- Environment variable naming: `CLAUDE_YOLO_*``CCYOLO_*`
45+
- Auth isolation: unset conflicting auth variables per mode
46+
47+
**Benefits**:
48+
-**Project isolation**: Separate auth sessions per project
49+
-**Environment control**: Full env var support in Docker mode
50+
-**Path consistency**: All mounts to `/home/claude`
51+
-**Auth reliability**: No cross-contamination between auth modes
52+
53+
**Related**: Issues #46, #45 (configuration management)
54+
55+
**Status**: ✅ **COMPLETED**
56+
57+
---
58+
59+
## Issue Analysis: 2025-07-04
60+
61+
### [enhancement-analysis] Docker Compose configuration support
62+
63+
**Problem**: Command line arguments become unmanageable for complex setups with multiple volumes and environment variables.
64+
65+
**Current Pain Point**:
66+
```bash
67+
claude-yolo -v ~/.ssh:/root/.ssh:ro -v ~/Desktop/claude:/home/claude/.claude/ -v ~/.config/git:/home/claude/.config/git -v ../yolo-tools/scripts/barkme.sh:/home/claude/.local/bin/barkme.sh --continue
68+
```
69+
70+
**Root Cause Analysis**:
71+
1. **CLI limitations**: Long command lines are hard to edit, share, version control
72+
2. **Multi-container needs**: Users want playwright services, MCP servers, other tools
73+
3. **Team collaboration**: Complex setups need to be shared across team members
74+
4. **Missing configuration hierarchy**: No project vs user vs local settings distinction
75+
76+
**Proposed Solution**: Docker Compose integration following Claude Code's settings pattern
77+
78+
**Configuration Hierarchy** (mirrors Claude Code's approach):
79+
```
80+
.claude/
81+
├── claude-yolo.local.yml # Project-local (gitignored)
82+
├── claude-yolo.yml # Project-shared (version controlled)
83+
└── ~/.claude/claude-yolo.yml # User global
84+
```
85+
86+
**Multi-container Support**:
87+
```yaml
88+
# .claude/claude-yolo.yml
89+
version: '3.8'
90+
services:
91+
claude:
92+
image: ghcr.io/lroolle/claude-code-yolo:latest
93+
volumes:
94+
- ~/.ssh:/root/.ssh:ro
95+
- ${PWD}:${PWD}
96+
depends_on:
97+
- playwright
98+
- mcp-server
99+
100+
playwright:
101+
image: mcr.microsoft.com/playwright:v1.40.0-focal
102+
ports: ["3000:3000"]
103+
104+
mcp-server:
105+
image: custom/mcp-server:latest
106+
ports: ["8080:8080"]
107+
```
108+
109+
**Implementation Requirements**:
110+
1. **Auto-detection**: Check for compose files in precedence order
111+
2. **Backward compatibility**: Keep CLI args for simple cases
112+
3. **Multi-container orchestration**: Full Docker Compose integration
113+
4. **Settings coexistence**: Respect existing `.claude/settings.json` handling
114+
115+
**Benefits**:
116+
- ✅ **Manageable configs**: No more insane command lines
117+
- ✅ **Team collaboration**: Share service definitions via git
118+
- ✅ **Multi-container**: Enable complex development environments
119+
- ✅ **Familiar patterns**: Follow Claude Code's settings hierarchy
120+
- ✅ **Version control**: Compose files are easily tracked
121+
122+
**Related Issues**:
123+
- Issue #24: Environment variable support (partially addresses)
124+
- Issue #33: DevContainer support question (compose provides better solution)
125+
126+
**Status**: Analysis complete, ready for implementation
127+
6128
## Issue Analysis: 2025-06-23
7129

8130
### [bug-fixed] Root user (UID 0) handling in docker-entrypoint.sh

Dockerfile

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ENV DEBIAN_FRONTEND=noninteractive \
1515
LANGUAGE=en_US:en \
1616
LC_ALL=en_US.UTF-8 \
1717
TZ=UTC \
18-
PATH=/root/.local/bin:/usr/local/go/bin:/usr/local/share/npm-global/bin:$PATH
18+
PATH=/root/.local/bin:/usr/local/go/bin:$PATH
1919

2020
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
2121
--mount=type=cache,target=/var/lib/apt,sharing=locked \
@@ -29,7 +29,8 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
2929
python3-dev libffi-dev \
3030
jq ripgrep lsof tree make gcc g++ \
3131
openssh-client rsync \
32-
shellcheck bat fd-find \
32+
shellcheck bat fd-find silversearcher-ag \
33+
vim \
3334
git procps psmisc zsh && \
3435
add-apt-repository ppa:deadsnakes/ppa && \
3536
apt-get update && \
@@ -49,9 +50,6 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
4950
apt-get install -y --no-install-recommends nodejs && \
5051
apt-get -y clean && rm -rf /var/lib/apt/lists/*
5152

52-
RUN mkdir -p /usr/local/share/npm-global
53-
ENV NPM_CONFIG_PREFIX=/usr/local/share/npm-global
54-
5553
RUN --mount=type=cache,target=/root/.npm,sharing=locked \
5654
npm install -g npm@latest pnpm && \
5755
npm cache clean --force
@@ -114,15 +112,8 @@ ENV NPM_CONFIG_FETCH_RETRIES=5 \
114112
NPM_CONFIG_FETCH_RETRY_FACTOR=2 \
115113
NPM_CONFIG_FETCH_RETRY_MINTIMEOUT=10000
116114

117-
# Claude Code installation - separate layer for easier version management
118-
FROM tools AS claude-tools
119-
ARG CLAUDE_CODE_VERSION=1.0.41
120-
RUN --mount=type=cache,target=/root/.npm,sharing=locked \
121-
npm install -g @anthropic-ai/claude-code@${CLAUDE_CODE_VERSION} @mariozechner/claude-trace && \
122-
npm cache clean --force
123-
124115
# Final stage with shell setup
125-
FROM claude-tools AS final
116+
FROM tools AS final
126117

127118
# Create non-root user for Claude execution
128119
# Using 1001 as default to avoid conflicts with ubuntu user (usually 1000)
@@ -137,13 +128,29 @@ RUN groupadd -g "$CLAUDE_GID" "$CLAUDE_USER" && \
137128
echo "$CLAUDE_USER ALL=(ALL) NOPASSWD: ALL" > "/etc/sudoers.d/$CLAUDE_USER" && \
138129
chmod 440 "/etc/sudoers.d/$CLAUDE_USER"
139130

140-
# Give claude user ownership of npm-global directory
141-
RUN chown -R "$CLAUDE_UID:$CLAUDE_GID" /usr/local/share/npm-global
131+
# Configure npm-global directory for claude user
132+
RUN mkdir -p "$CLAUDE_HOME/.npm-global" && \
133+
chown -R "$CLAUDE_UID:$CLAUDE_GID" "$CLAUDE_HOME/.npm-global"
134+
135+
# Set npm configuration for claude user and install Claude CLI
136+
USER $CLAUDE_USER
137+
ARG CLAUDE_CODE_VERSION=1.0.41
138+
RUN npm config set prefix "$CLAUDE_HOME/.npm-global" && \
139+
npm install -g @anthropic-ai/claude-code@${CLAUDE_CODE_VERSION} @mariozechner/claude-trace && \
140+
npm cache clean --force
141+
142+
RUN git clone --depth=1 https://github.com/ohmyzsh/ohmyzsh "$CLAUDE_HOME/.oh-my-zsh" && \
143+
git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions "$CLAUDE_HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions" && \
144+
git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git "$CLAUDE_HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting"
145+
146+
# Create .zshrc for claude user
147+
RUN echo 'export ZSH="$HOME/.oh-my-zsh"' > "$CLAUDE_HOME/.zshrc" && \
148+
echo 'ZSH_THEME="robbyrussell"' >> "$CLAUDE_HOME/.zshrc" && \
149+
echo 'plugins=(git docker python golang node npm aws zsh-autosuggestions zsh-syntax-highlighting)' >> "$CLAUDE_HOME/.zshrc" && \
150+
echo 'source $ZSH/oh-my-zsh.sh' >> "$CLAUDE_HOME/.zshrc" && \
151+
echo 'export PATH=$HOME/.local/bin:$HOME/.npm-global/bin:/usr/local/go/bin:$PATH' >> "$CLAUDE_HOME/.zshrc"
142152

143-
# Simple zsh setup
144-
RUN echo 'export PATH=/root/.local/bin:/usr/local/go/bin:/usr/local/share/npm-global/bin:$PATH' >> ~/.zshrc
145-
RUN echo 'export PATH=$HOME/.local/bin:/usr/local/go/bin:/usr/local/share/npm-global/bin:$PATH' >> "$CLAUDE_HOME/.zshrc" && \
146-
chown "$CLAUDE_USER:$CLAUDE_USER" "$CLAUDE_HOME/.zshrc"
153+
USER root
147154

148155
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
149156

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ claude.sh --help # Show all options
7070
- **AWS Bedrock**: Uses `~/.aws` credentials - `--auth-with bedrock`
7171
- **Google Vertex**: Uses `~/.config/gcloud` credentials - `--auth-with vertex`
7272

73+
### Custom Configuration Directory
74+
75+
Use a custom Claude config home instead of the default `~/.claude` and `~/.claude.json`:
76+
77+
```bash
78+
# Use custom config directory home, should contains both ~/.claude.json and ~/.claude
79+
claude-yolo --config ~/work-claude
80+
```
81+
82+
This is useful for:
83+
- Separate auth sessions for different projects
84+
- Isolating Claude configurations
85+
7386
## GitHub CLI Authentication
7487

7588
For GitHub operations (creating PRs, managing repos), set the `GH_TOKEN` environment variable:
@@ -115,7 +128,7 @@ claude-yolo -v ~/.terraform.d:/root/.terraform.d
115128
- **Proxy Support**: Automatic `localhost``host.docker.internal` translation
116129
- **Model Selection**: Use any Claude model via `ANTHROPIC_MODEL` env var
117130
- **Request Tracing**: Debug with `--trace` flag using claude-trace
118-
- **Docker Socket**: Optional mounting with `CLAUDE_YOLO_DOCKER_SOCKET=true`
131+
- **Docker Socket**: Optional mounting with `CCYOLO_DOCKER_SOCKET=true`
119132

120133

121134
### Request Tracing by @badlogic `claude-trace`
@@ -134,7 +147,7 @@ docker pull ghcr.io/lroolle/claude-code-yolo:latest
134147
docker pull lroolle/claude-code-yolo:latest
135148

136149
# Use specific registry
137-
DOCKER_IMAGE=lroolle/claude-code-yolo claude-yolo
150+
CCYOLO_DOCKER_IMAGE=lroolle/claude-code-yolo claude-yolo
138151
```
139152

140153
## Manual Setup

claude-yolo

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ parse_args() {
8181
claude_args+=("-v" "$2")
8282
shift 2
8383
;;
84+
-e)
85+
if [ -z "$2" ]; then
86+
echo "Error: -e requires an argument" >&2
87+
exit 1
88+
fi
89+
claude_args+=("-e" "$2")
90+
shift 2
91+
;;
8492
--inspect)
8593
inspect_container
8694
# inspect_container calls exec, but add shift for safety
@@ -90,6 +98,14 @@ parse_args() {
9098
list_containers
9199
exit 0
92100
;;
101+
--config | -c)
102+
if [ -z "$2" ]; then
103+
echo "Error: --config requires an argument" >&2
104+
exit 1
105+
fi
106+
claude_args+=("--config" "$2")
107+
shift 2
108+
;;
93109
--help | -h)
94110
echo "Claude YOLO - Container Shortcuts"
95111
echo ""
@@ -99,17 +115,30 @@ parse_args() {
99115
echo " --inspect Enter running container as claude user"
100116
echo " --ps List containers for this project"
101117
echo ""
118+
echo "Configuration:"
119+
echo " --config DIR Use custom Claude config home instead of ~/.claude, ~/.claude.json "
120+
echo " -c DIR Creates directory and .claude.json if they don't exist"
121+
echo ""
102122
echo "Volume Mounting:"
103123
echo " -v Mount volume (Docker syntax: source:target[:options])"
104124
echo " Can be used multiple times"
105125
echo ""
126+
echo "Environment Variables:"
127+
echo " -e VAR=value Set environment variable explicitly"
128+
echo " -e VAR Pass environment variable from shell"
129+
echo " Can be used multiple times"
130+
echo ""
106131
echo "Examples:"
107-
echo " claude-yolo # Run Claude in YOLO mode"
108-
echo " claude-yolo --inspect # Quick access to running container"
109-
echo " claude-yolo --ps # See project containers"
110-
echo " claude-yolo -v ~/.gitconfig:/root/.gitconfig # Mount git config"
111-
echo " claude-yolo -v ~/.ssh:/root/.ssh:ro # Mount SSH keys read-only"
132+
echo " claude-yolo # Run Claude in YOLO mode"
133+
echo " CCYOLO_DOCKER_IMAGE=custom-image claude-yolo # Use custom image"
134+
echo " claude-yolo --inspect # Quick access to running container"
135+
echo " claude-yolo --ps # See project containers"
136+
echo " claude-yolo -v ~/.gitconfig:/home/claude/.gitconfig # Mount git config"
137+
echo " claude-yolo -v ~/.ssh:/home/claude/.ssh:ro # Mount SSH keys read-only"
112138
echo " claude-yolo -v ~/tools:/tools -v ~/data:/data # Multiple mounts"
139+
echo " claude-yolo --config ~/work-claude # Custom config home"
140+
echo " claude-yolo -e NODE_ENV=dev -e DEBUG # Set env vars"
141+
echo " export API_KEY=xyz; claude-yolo -e API_KEY # Pass from shell"
113142
exit 0
114143
;;
115144
*)
@@ -122,5 +151,4 @@ parse_args() {
122151
exec "$CLAUDE_SH" --yolo "${claude_args[@]}"
123152
}
124153

125-
# All argument parsing handled by parse_args
126154
parse_args "$@"

0 commit comments

Comments
 (0)