Spaces:
Paused

jodaro01 commited on
Commit
1e79bdd
·
verified ·
1 Parent(s): 3a29b38

Fix Claude Code Docker build

Browse files
Files changed (3) hide show
  1. Dockerfile +5 -6
  2. README.md +9 -9
  3. start.sh +3 -4
Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM debian:bookworm-slim
2
 
3
  ENV DEBIAN_FRONTEND=noninteractive \
4
  PORT=7860 \
@@ -13,8 +13,6 @@ RUN apt-get update \
13
  git \
14
  jq \
15
  less \
16
- nodejs \
17
- npm \
18
  procps \
19
  python3 \
20
  ripgrep \
@@ -28,10 +26,11 @@ RUN useradd --create-home --shell /bin/bash claude \
28
  && mkdir -p /workspace \
29
  && chown -R claude:claude /workspace /home/claude
30
 
31
- USER claude
32
- WORKDIR /home/claude
33
 
34
- RUN curl -fsSL https://claude.ai/install.sh | bash
 
35
 
36
  COPY --chown=claude:claude start.sh /home/claude/start.sh
37
  RUN chmod +x /home/claude/start.sh
 
1
+ FROM node:22-bookworm-slim
2
 
3
  ENV DEBIAN_FRONTEND=noninteractive \
4
  PORT=7860 \
 
13
  git \
14
  jq \
15
  less \
 
 
16
  procps \
17
  python3 \
18
  ripgrep \
 
26
  && mkdir -p /workspace \
27
  && chown -R claude:claude /workspace /home/claude
28
 
29
+ RUN curl -fsSL https://claude.ai/install.sh | bash \
30
+ || npm install -g @anthropic-ai/claude-code
31
 
32
+ USER claude
33
+ WORKDIR /workspace
34
 
35
  COPY --chown=claude:claude start.sh /home/claude/start.sh
36
  RUN chmod +x /home/claude/start.sh
README.md CHANGED
@@ -11,7 +11,7 @@ suggested_variables:
11
  - name: ACCESS_USERNAME
12
  description: "Browser terminal username. Defaults to claude."
13
  - name: WORKSPACE_GIT_REPO
14
- description: "Optional Git repository URL to clone into /workspace on first boot."
15
  suggested_secrets:
16
  - name: ANTHROPIC_API_KEY
17
  description: "Anthropic API key used by Claude Code."
@@ -21,17 +21,17 @@ suggested_secrets:
21
 
22
  # Claude Code on Hugging Face Spaces
23
 
24
- This Docker Space runs Anthropic Claude Code in a protected browser terminal.
25
 
26
- ## Required Secrets
27
 
28
- - `ANTHROPIC_API_KEY`: your Anthropic API key.
29
- - `ACCESS_TOKEN`: a strong password for the browser terminal.
30
 
31
- ## Optional Variables
32
 
33
- - `ACCESS_USERNAME`: terminal username, defaults to `claude`.
34
- - `WORKSPACE_GIT_REPO`: repository URL to clone into `/workspace/project` on first boot.
35
 
36
  Open the Space, sign in with `ACCESS_USERNAME` and `ACCESS_TOKEN`, then run:
37
 
@@ -39,4 +39,4 @@ Open the Space, sign in with `ACCESS_USERNAME` and `ACCESS_TOKEN`, then run:
39
  claude
40
  ```
41
 
42
- Claude Code is installed using Anthropic's official Linux installer from `https://claude.ai/install.sh`.
 
11
  - name: ACCESS_USERNAME
12
  description: "Browser terminal username. Defaults to claude."
13
  - name: WORKSPACE_GIT_REPO
14
+ description: "Optional Git repository URL to clone into /workspace/project on first boot."
15
  suggested_secrets:
16
  - name: ANTHROPIC_API_KEY
17
  description: "Anthropic API key used by Claude Code."
 
21
 
22
  # Claude Code on Hugging Face Spaces
23
 
24
+ This private Docker Space runs Anthropic Claude Code in a protected browser terminal.
25
 
26
+ Set these Space secrets before starting:
27
 
28
+ - `ANTHROPIC_API_KEY`
29
+ - `ACCESS_TOKEN`
30
 
31
+ Optional variables:
32
 
33
+ - `ACCESS_USERNAME`, defaults to `claude`
34
+ - `WORKSPACE_GIT_REPO`, clones into `/workspace/project` on first boot
35
 
36
  Open the Space, sign in with `ACCESS_USERNAME` and `ACCESS_TOKEN`, then run:
37
 
 
39
  claude
40
  ```
41
 
42
+ The image tries Anthropic's official Linux installer first and falls back to the npm package if the installer is unavailable during the Hugging Face Docker build.
start.sh CHANGED
@@ -1,7 +1,7 @@
1
  #!/usr/bin/env bash
2
  set -euo pipefail
3
 
4
- export PATH="$HOME/.local/bin:$HOME/.claude/local:$PATH"
5
  export ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY:-}"
6
  export ACCESS_USERNAME="${ACCESS_USERNAME:-claude}"
7
  export ACCESS_TOKEN="${ACCESS_TOKEN:-}"
@@ -12,7 +12,7 @@ export PORT="${PORT:-7860}"
12
  mkdir -p "$WORKSPACE_DIR"
13
 
14
  cat > "$HOME/.bashrc" <<'EOF'
15
- export PATH="$HOME/.local/bin:$HOME/.claude/local:$PATH"
16
  export WORKSPACE_DIR="${WORKSPACE_DIR:-/workspace}"
17
  cd "$WORKSPACE_DIR" 2>/dev/null || cd "$HOME"
18
  echo
@@ -30,12 +30,11 @@ cd "$WORKSPACE_DIR"
30
 
31
  if [ -z "$ACCESS_TOKEN" ]; then
32
  echo "ERROR: ACCESS_TOKEN secret is required for browser terminal access." >&2
33
- echo "Set a strong ACCESS_TOKEN in the Hugging Face Space secrets." >&2
34
  exit 1
35
  fi
36
 
37
  if [ -z "$ANTHROPIC_API_KEY" ]; then
38
- echo "WARNING: ANTHROPIC_API_KEY is not set. Claude Code will start, but API calls will fail until configured." >&2
39
  fi
40
 
41
  exec ttyd \
 
1
  #!/usr/bin/env bash
2
  set -euo pipefail
3
 
4
+ export PATH="$HOME/.local/bin:$HOME/.claude/local:/usr/local/bin:$PATH"
5
  export ANTHROPIC_API_KEY="${ANTHROPIC_API_KEY:-}"
6
  export ACCESS_USERNAME="${ACCESS_USERNAME:-claude}"
7
  export ACCESS_TOKEN="${ACCESS_TOKEN:-}"
 
12
  mkdir -p "$WORKSPACE_DIR"
13
 
14
  cat > "$HOME/.bashrc" <<'EOF'
15
+ export PATH="$HOME/.local/bin:$HOME/.claude/local:/usr/local/bin:$PATH"
16
  export WORKSPACE_DIR="${WORKSPACE_DIR:-/workspace}"
17
  cd "$WORKSPACE_DIR" 2>/dev/null || cd "$HOME"
18
  echo
 
30
 
31
  if [ -z "$ACCESS_TOKEN" ]; then
32
  echo "ERROR: ACCESS_TOKEN secret is required for browser terminal access." >&2
 
33
  exit 1
34
  fi
35
 
36
  if [ -z "$ANTHROPIC_API_KEY" ]; then
37
+ echo "WARNING: ANTHROPIC_API_KEY is not set. Claude Code API calls will fail until configured." >&2
38
  fi
39
 
40
  exec ttyd \