|
| 1 | +# Project Brief: Code-Server Railway Template |
| 2 | + |
| 3 | +**Project:** VSCode Cloud IDE with Claude Code Integration |
| 4 | +**Repository:** `sphinxcode/code-server` |
| 5 | +**Railway Service:** `code-ajna` (claude.sphinx.codes) |
| 6 | +**Status:** In Progress |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## Executive Summary |
| 11 | + |
| 12 | +Create a production-ready, marketable Railway template that provides browser-based VS Code (code-server) with pre-installed Claude Code CLI, persistent extensions, and configurable user permissions. |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## Original Problems |
| 17 | + |
| 18 | +### 1. Root User Permission Issues |
| 19 | +- **Symptom:** code-server displayed security warnings about running as root |
| 20 | +- **Cause:** `RAILWAY_RUN_UID=0` was set, forcing container to run as root |
| 21 | +- **Impact:** Couldn't bypass certain settings, security warnings in UI |
| 22 | + |
| 23 | +### 2. Non-Persistent Tools |
| 24 | +- **Symptom:** npm, npx, extensions disappeared after redeployment |
| 25 | +- **Cause:** Container running as root with `HOME=/root` (ephemeral), while volume mounted at `/home/coder` |
| 26 | +- **Impact:** Users lost installed tools and configurations on each deploy |
| 27 | + |
| 28 | +### 3. Claude Code Not Pre-installed |
| 29 | +- **Request:** Template users should have Claude Code CLI available out-of-the-box |
| 30 | +- **Requirement:** Support for `claude --dangerously-skip-permissions` flag |
| 31 | + |
| 32 | +--- |
| 33 | + |
| 34 | +## Solution Architecture |
| 35 | + |
| 36 | +### Infrastructure |
| 37 | +| Component | Value | |
| 38 | +|-----------|-------| |
| 39 | +| Base Image | `codercom/code-server:latest` | |
| 40 | +| Volume Mount | `/home/coder` (Railway volume) | |
| 41 | +| Service URL | `claude.sphinx.codes` | |
| 42 | +| Project ID | `59ae99d7-dc99-4642-ae06-642cd8d8c83a` | |
| 43 | +| Service ID | `34522d52-ba69-4fcf-83b7-210a765a0a76` | |
| 44 | +| Environment ID | `a921a831-e480-451b-b9c7-04ce2f647c68` | |
| 45 | + |
| 46 | +### Key Files Modified |
| 47 | + |
| 48 | +#### [Dockerfile](file:///E:/AI-Terminal/sphinxcode/code-server/Dockerfile) |
| 49 | +- Installs `gosu` for proper user switching |
| 50 | +- Installs Node.js 20 LTS as fallback |
| 51 | +- Installs Claude Code CLI to `/usr/local/bin/claude` |
| 52 | +- Installs essential tools: ripgrep, jq, htop, vim, nano |
| 53 | +- Sets up XDG directories for persistence |
| 54 | +- PATH prioritizes volume paths over image paths |
| 55 | + |
| 56 | +#### [railway-entrypoint.sh](file:///E:/AI-Terminal/sphinxcode/code-server/railway-entrypoint.sh) |
| 57 | +- Configurable user via `RUN_AS_USER` variable |
| 58 | +- Shell profile setup (`.bashrc`, `.profile`) with PATH |
| 59 | +- Permission fixing via `chown` when switching users |
| 60 | +- User switching via `gosu` when `RUN_AS_USER=coder` |
| 61 | +- Root symlinks for persistence when staying as root |
| 62 | +- First-run initialization with welcome README |
| 63 | +- Environment verification logging |
| 64 | + |
| 65 | +#### [README.md](file:///E:/AI-Terminal/sphinxcode/code-server/README.md) |
| 66 | +- Documentation for all configuration variables |
| 67 | +- Quick start guide for Claude Code |
| 68 | +- Update behavior explanation |
| 69 | +- Troubleshooting guide |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +## Configuration Variables |
| 74 | + |
| 75 | +| Variable | Required | Default | Description | |
| 76 | +|----------|----------|---------|-------------| |
| 77 | +| `PASSWORD` | Yes | - | code-server login password | |
| 78 | +| `RUN_AS_USER` | No | `root` | Set to `coder` for non-root execution | |
| 79 | +| `CODER_HOME` | No | `/home/coder` | Volume mount path | |
| 80 | +| `CODER_UID` | No | `1000` | User ID when switching to coder | |
| 81 | +| `CODER_GID` | No | `1000` | Group ID when switching to coder | |
| 82 | +| `GIT_REPO` | No | - | Repository to auto-clone on startup | |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +## Persistence Strategy |
| 87 | + |
| 88 | +### Volume-First PATH Priority |
| 89 | +``` |
| 90 | +$HOME/.local/bin ← User-installed tools (Claude, etc.) |
| 91 | +$HOME/.local/node/bin ← User-installed Node.js |
| 92 | +$HOME/.claude/local ← Claude Code from volume |
| 93 | +/usr/local/bin ← Image fallback (Claude) |
| 94 | +/usr/bin ← Image fallback (Node.js) |
| 95 | +``` |
| 96 | + |
| 97 | +### What Persists (on volume) |
| 98 | +- Extensions: `~/.local/share/code-server/extensions/` |
| 99 | +- Claude Code: `~/.local/bin/claude` or `~/.claude/` |
| 100 | +- Claude auth: `~/.claude/` (API keys, settings) |
| 101 | +- Node.js: `~/.local/node/` (if user installs) |
| 102 | +- Shell config: `~/.bashrc`, `~/.profile` |
| 103 | +- Workspace: `~/workspace/` |
| 104 | + |
| 105 | +### What Auto-Updates (from image) |
| 106 | +- Node.js fallback in `/usr/bin/node` |
| 107 | +- Claude Code fallback in `/usr/local/bin/claude` |
| 108 | +- System packages (git, curl, etc.) |
| 109 | + |
| 110 | +--- |
| 111 | + |
| 112 | +## User Modes |
| 113 | + |
| 114 | +### Root Mode (Default) |
| 115 | +``` |
| 116 | +RUN_AS_USER=root (or not set) |
| 117 | +``` |
| 118 | +- Stays as root user |
| 119 | +- Creates symlinks from `/root/` → `/home/coder/` for persistence |
| 120 | +- Compatible with existing volumes owned by root |
| 121 | + |
| 122 | +### Coder Mode (Recommended for Claude) |
| 123 | +``` |
| 124 | +RUN_AS_USER=coder |
| 125 | +``` |
| 126 | +- Switches to coder user (UID 1000) via gosu |
| 127 | +- Fixes volume permissions before switching |
| 128 | +- No root warnings in code-server UI |
| 129 | +- Required for `claude --dangerously-skip-permissions` |
| 130 | + |
| 131 | +--- |
| 132 | + |
| 133 | +## Issues Encountered & Resolved |
| 134 | + |
| 135 | +### 1. Railway Start Command Override |
| 136 | +- **Problem:** Railway had a custom start command that bypassed our ENTRYPOINT |
| 137 | +- **Solution:** Cleared the start command via `mcp_railway_service_update` |
| 138 | + |
| 139 | +### 2. Docker Layer Caching |
| 140 | +- **Problem:** Railway used cached layers, ignoring our changes |
| 141 | +- **Solution:** Added cache-bust comments to force rebuild |
| 142 | + |
| 143 | +### 3. Claude Installs to ~/.local/bin |
| 144 | +- **Problem:** Assumed Claude installed to `~/.claude/local/` |
| 145 | +- **Solution:** Updated PATH to include `$HOME/.local/bin` first |
| 146 | + |
| 147 | +### 4. Shell Profile Not Configured |
| 148 | +- **Problem:** New terminals didn't have PATH set |
| 149 | +- **Solution:** Entrypoint now writes to `.bashrc` and `.profile` |
| 150 | + |
| 151 | +--- |
| 152 | + |
| 153 | +## Current Status |
| 154 | + |
| 155 | +### Completed ✅ |
| 156 | +- Dockerfile with gosu, Node.js, Claude Code |
| 157 | +- Entrypoint with RUN_AS_USER variable |
| 158 | +- Shell profile auto-configuration |
| 159 | +- PATH priority for volume-installed tools |
| 160 | +- README documentation |
| 161 | +- Removed conflicting `railway.json` |
| 162 | +- Cleared Railway start command override |
| 163 | +- Set `RUN_AS_USER=coder` on Railway |
| 164 | + |
| 165 | +### Pending Verification 🔄 |
| 166 | +- Confirm entrypoint output appears in Railway logs |
| 167 | +- Verify user switches to `coder` (not `root@xxx`) |
| 168 | +- Test `claude --dangerously-skip-permissions` works |
| 169 | +- Confirm Claude authentication persists |
| 170 | + |
| 171 | +--- |
| 172 | + |
| 173 | +## Expected Startup Logs |
| 174 | + |
| 175 | +``` |
| 176 | +╔══════════════════════════════════════════════════════════════════════════╗ |
| 177 | +║ VSCode Cloud IDE - Claude Code & Node.js Ready ║ |
| 178 | +╚══════════════════════════════════════════════════════════════════════════╝ |
| 179 | +
|
| 180 | +→ Initial user: root (UID: 0) |
| 181 | +→ RUN_AS_USER: coder |
| 182 | +→ HOME: /home/coder |
| 183 | +
|
| 184 | +→ Running setup as root... |
| 185 | +→ Setting up shell profile... |
| 186 | + ✓ Shell profile configured |
| 187 | +→ Fixing permissions for coder user (UID: 1000)... |
| 188 | + ✓ Permissions fixed |
| 189 | +→ Switching to coder user via gosu... |
| 190 | +
|
| 191 | +→ Running as: coder (UID: 1000) |
| 192 | +
|
| 193 | +Environment: |
| 194 | + → Node.js: v20.x.x [volume/image] |
| 195 | + → npm: x.x.x |
| 196 | + → git: x.x.x |
| 197 | + → claude: x.x.x [volume/image] |
| 198 | +
|
| 199 | +════════════════════════════════════════════════════════════════════════ |
| 200 | +Starting code-server as coder... |
| 201 | +════════════════════════════════════════════════════════════════════════ |
| 202 | +``` |
| 203 | + |
| 204 | +--- |
| 205 | + |
| 206 | +## Files Summary |
| 207 | + |
| 208 | +| File | Location | Purpose | |
| 209 | +|------|----------|---------| |
| 210 | +| `Dockerfile` | sphinxcode/code-server | Image build configuration | |
| 211 | +| `railway-entrypoint.sh` | sphinxcode/code-server | Container startup script | |
| 212 | +| `README.md` | sphinxcode/code-server | User documentation | |
| 213 | +| `railway.toml` | sphinxcode/code-server | Railway deployment config | |
| 214 | + |
| 215 | +--- |
| 216 | + |
| 217 | +## Next Steps |
| 218 | + |
| 219 | +1. **Verify Deployment** - Check if entrypoint runs and user switches properly |
| 220 | +2. **Test Claude** - Authenticate and run `claude --dangerously-skip-permissions` |
| 221 | +3. **Create Railway Template** - Make template public for others to deploy |
| 222 | +4. **Update Template Docs** - Include volume attachment instructions |
0 commit comments