Writing

Setting up Claude Code on the web for PHP, Laravel and Vite projects

Cloud sessions of Claude Code start without PHP 8.5, without vendor/, and behind a GitHub proxy that blocks Composer's downloads. Here is the setup that got a Laravel + Vite + pnpm repo from "six minutes of Composer and a pile of permission prompts" to a working checkout in about ten seconds.

Claude Code on the web runs each session on a fresh cloud VM with a clone of your repository. It is great for fanning work out in parallel. But it assumes a JavaScript- or Python-shaped world, and a Laravel app is neither. My first attempts went like this:

  • The environment setup script died on its way to installing PHP.
  • Once PHP was installed, Composer spent more than six minutes cloning packages one at a time.
  • In the real cloud, Composer failed completely. The agent then tried to fix it by asking me to approve access to dependency repositories on GitHub, one prompt per package.

This post covers what actually works. I tested it against several Laravel 13 apps that use Vite, React, TypeScript and pnpm.

TL;DR

  1. Use the environment setup script to install the toolchain: PHP 8.5, Node 24, pnpm and a small helper. Don't use add-apt-repository.
  2. Composer can't download packages in a cloud session. Build vendor/ in CI and publish it as an asset of a draft release in the same repository. A session can download its own repository's release assets.
  3. A SessionStart hook in the repo downloads the bundle that matches composer.lock, unpacks it, and runs composer install with the network disabled.
  4. Tell the agent, in AGENTS.md, never to "fix" Composer by requesting access to dependency repositories.

How a cloud session is put together

Three pieces matter, and they run at different times.

flowchart TD
  A[Environment setup script<br/>runs as root, no checkout] -->|filesystem snapshot,<br/>reused about 7 days| B[New session VM]
  B --> C[Repository cloned]
  C --> D[SessionStart hook<br/>from .claude/settings.json]
  D -->|download own release asset| E[vendor/ from bundle]
  D --> F[pnpm install]
  E --> G[Claude starts on the task]
  F --> G
  H[GitHub Actions<br/>on composer.lock change] -->|draft release asset| E
  • The setup script is pasted into the environment settings at claude.ai/code. It runs as root on Ubuntu 24.04 before Claude Code starts, and it isn't guaranteed a checkout. Anthropic then snapshots the filesystem and starts later sessions from that snapshot. The snapshot is rebuilt when you edit the script or change the allowed hosts, or after about seven days. A non-zero exit means the session doesn't start, and the script should finish in about five minutes.
  • A SessionStart hook comes from the repository's .claude/settings.json. It runs after the clone, on every start and resume. Its stdout is added to Claude's context. Cloud sessions set CLAUDE_CODE_REMOTE=true, so the same hook can do nothing on a laptop.
  • The GitHub proxy handles every GitHub request, at every network access level, and it is where Composer runs into trouble.

The split matters: the toolchain belongs in the setup script, and project dependencies belong in the hook. The setup script can't install vendor/, because there may be no repository yet, and one snapshot is shared by every repository that uses the environment.

Part 1: the setup script

PHP 8.5 without add-apt-repository

The base image ships an older PHP; the docs say 8.3, and I measured 8.4 in one session. Some of my lockfiles require >=8.5, and CI runs 8.5, so the script always installs 8.5 from the ondrej/php PPA.

The obvious approach fails:

File "/usr/bin/add-apt-repository", line 3, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

The image puts a python3 that has no apt_pkg ahead of the system one on PATH, and software-properties crashes when it imports the module. So write the apt source and signing key yourself. Three things to get right:

  • Use the right key. My first attempt used a wrong fingerprint. The keyserver answered 404, gpg --dearmor got empty input ("no valid OpenPGP data found"), and set -e stopped the script. Take the fingerprint from Launchpad (https://api.launchpad.net/1.0/~ondrej/+archive/ubuntu/php, field signing_key_fingerprint), and check the downloaded key against it.
  • Use ppa.launchpad.net, not ppa.launchpadcontent.net. Only the first is on the default "Trusted" allowlist, and both serve the same archive.
  • Put your PHP first on PATH. update-alternatives isn't enough when something else is earlier on PATH, so also link /usr/local/bin/php.
ONDREJ_FPR=B8DC7E53946656EFBCE4C1DD71DAEAAB4AD4CAB6

install -d -m 0755 /etc/apt/keyrings
curl -fsSL "https://keyserver.ubuntu.com/pks/lookup?op=get&options=mr&search=0x${ONDREJ_FPR}" \
  | gpg --dearmor --yes -o /etc/apt/keyrings/ondrej-php.gpg
gpg --show-keys --with-colons /etc/apt/keyrings/ondrej-php.gpg \
  | awk -F: '$1=="fpr"{print $10; exit}' | grep -qx "$ONDREJ_FPR" \
  || { echo "ondrej/php key fingerprint mismatch" >&2; exit 1; }

cat >/etc/apt/sources.list.d/ondrej-php.list <<'EOF'
deb [signed-by=/etc/apt/keyrings/ondrej-php.gpg] http://ppa.launchpad.net/ondrej/php/ubuntu noble main
EOF
apt-get update -q

PHP_EXTENSIONS=(bcmath bz2 cli common curl gd gmp imagick intl mbstring mysql redis soap sqlite3 tidy xml zip)
apt-get install -y -q --no-install-recommends "${PHP_EXTENSIONS[@]/#/php8.5-}"
update-alternatives --set php /usr/bin/php8.5
ln -sf /usr/bin/php8.5 /usr/local/bin/php

Node 24 when the image puts Node 22 on PATH

The image ships Node 20, 21 and 22 under /opt/nodeNN, and every session's PATH includes /opt/node22/bin. A setup script can't change a session's PATH. What it can do is change what that directory contains. So I install Node 24 from nodejs.org, which is on the Trusted list (NodeSource isn't), and point /opt/node22 at it:

mv /opt/node22 /opt/node22.image          # keep the original
ln -sfn /opt/node24 /opt/node22

It isn't pretty, but it works regardless of how the session builds its PATH. Then turn on pnpm through corepack, so each repository gets the pnpm version its packageManager field pins:

corepack enable pnpm
corepack install --global [email protected]

Fail loudly, because the snapshot is cached

The standard advice is to add || true to non-critical steps so a flaky install doesn't block sessions. That's right for optional tools. For the essentials it's wrong: a broken toolchain that still exits 0 gets snapshotted and reused for a week. My script ends with a check that exits non-zero if php isn't 8.5, if an extension is missing, or if node or pnpm is wrong.

missing="$(php -r '
  $need = ["bcmath","curl","dom","gd","intl","mbstring","pdo_sqlite","sodium","xml","zip" /* … */];
  echo implode(" ", array_diff($need, array_map("strtolower", get_loaded_extensions())));')"
[[ -z "$missing" ]] || { echo "FATAL: PHP extensions missing: $missing" >&2; exit 1; }

Two more things belong in the setup script: zstd and gh. The base image has neither, and part 2 needs zstd.

Test the whole script before pasting it in: docker run --rm -v "$PWD":/t ubuntu:24.04 bash /t/setup.sh runs it on a clean Ubuntu 24.04. The container isn't the cloud (see the lesson at the end), but it caught my ordering bugs in under a minute.

Part 2: Composer vs. the GitHub proxy

This is where I lost the most time, so here are the measurements from a real cloud session:

Request from inside the session Result
api.github.com/repos/<dep>/zipball/<sha>, Composer's --prefer-dist URL 403
codeload.github.com/<dep>/legacy.zip/<sha>, even for public laravel/framework 403
repo.packagist.org 200, but it's metadata only; the files it points to are on GitHub
REST API and release assets of the session's own repository, drafts included 200
git fetch --depth 1 of an unattached public repository works, no prompt

The 403 body reads:

{"message":"GitHub access to this repository is not enabled for this session. Use add_repo to request access. …"}

That last sentence is the trap. The agent reads "use add_repo" and does what it says, and each add_repo is a manual permission grant. A Laravel app has 150–200 packages. That's where my wall of permission prompts came from. (The upstream reports are anthropics/claude-code#78330 and #76248.)

--prefer-source looks like the way out, and the docs do say that cloning and fetching "work normally" through the proxy. It does, slowly: Composer mirrors each package's full history, one at a time, which took about 6½ minutes in my tests. In the real cloud it also died partway through, on a GitHub authentication error.

The fix: publish vendor/ as a release asset of your own repository

The Claude docs say that GitHub API and release-asset requests "reach only repositories attached to the session". The session's own repository is always attached. So CI builds vendor/ and uploads it as a release asset, named after the SHA-256 of composer.lock:

name: Cloud vendor bundle

on:
  push:
    paths:
      - composer.lock
      - .github/workflows/cloud-vendor.yml
  workflow_dispatch:

permissions:
  contents: write

concurrency:
  group: cloud-vendor
  cancel-in-progress: false

jobs:
  bundle:
    runs-on: ubuntu-24.04   # x86_64, like the cloud VM
    timeout-minutes: 15
    env:
      GH_TOKEN: ${{ github.token }}
      REPO: ${{ github.repository }}
      TAG: cloud-vendor
      KEEP: 20
    steps:
      - uses: actions/checkout@v7

      - name: Find or create the draft release
        id: release
        run: |
          name="vendor-$(sha256sum composer.lock | cut -d' ' -f1).tar.zst"
          id="$(gh api "repos/$REPO/releases?per_page=100" --jq "[.[] | select(.draft and .tag_name == \"$TAG\")][0].id // empty")"
          if [[ -z "$id" ]]; then
            id="$(gh api -X POST "repos/$REPO/releases" \
              -f tag_name="$TAG" -F draft=true -F prerelease=true \
              -f name="cloud-vendor bundles (draft; never publish)" --jq .id)"
          fi
          exists="$(gh api "repos/$REPO/releases/$id/assets?per_page=100" --jq "any(.[]; .name == \"$name\")")"
          { echo "id=$id"; echo "name=$name"; echo "exists=$exists"; } >>"$GITHUB_OUTPUT"

      - uses: shivammathur/setup-php@v2
        if: steps.release.outputs.exists != 'true'
        with:
          php-version: '8.5'
          extensions: bcmath, curl, gd, intl, mbstring, sodium, zip
          tools: composer:v2
          coverage: none

      - name: Build vendor/
        if: steps.release.outputs.exists != 'true'
        run: composer install --no-interaction --prefer-dist --no-progress --no-scripts

      - name: Upload the bundle and prune old ones
        if: steps.release.outputs.exists != 'true'
        env:
          ID: ${{ steps.release.outputs.id }}
          NAME: ${{ steps.release.outputs.name }}
        run: |
          tar --exclude-vcs -cf - vendor | zstd -T0 -12 -q -o "$NAME"
          curl -fsS -X POST -H "Authorization: Bearer $GH_TOKEN" -H 'Content-Type: application/zstd' \
            --data-binary @"$NAME" \
            "https://uploads.github.com/repos/$REPO/releases/$ID/assets?name=$NAME" >/dev/null
          gh api "repos/$REPO/releases/$ID/assets?per_page=100" \
            --jq "sort_by(.created_at) | reverse | .[$KEEP:][] | .id" \
            | while read -r old; do gh api -X DELETE "repos/$REPO/releases/assets/$old"; done

A few details are deliberate:

  • It's a draft release. A draft creates no git tag and never fires release: published. One of my apps runs its release job on release: published, and a published "cloud-vendor" release would have set it off. Keep it a draft, and say so in the release title.
  • --no-scripts. Package discovery and friends run in the session after unpacking, where the checkout's .env exists.
  • Named by lockfile hash, so no cache invalidation is needed. A branch that changes composer.lock gets its own bundle on its first push.
  • Size. My bundles are 32–58 MB with zstd level 12, and the workflow keeps the newest 20.

The hook and the helper

The hook is one line of .claude/settings.json:

{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "startup|resume",
        "hooks": [
          {
            "type": "command",
            "command": "command -v cloud-repo-bootstrap >/dev/null 2>&1 && cloud-repo-bootstrap || true",
            "timeout": 600,
            "statusMessage": "Installing dependencies (cloud sessions only)..."
          }
        ]
      }
    ]
  }
}

The logic lives in cloud-repo-bootstrap, which the setup script writes to /usr/local/bin. That way it's shared by every repository instead of copied into each one. The core of it:

want="$(php -r 'echo hash_file("sha256", "composer.lock");')"
asset="vendor-${want}.tar.zst"

# GH_TOKEN reads "proxy-injected" inside a session; the proxy swaps in real
# credentials for requests to the session's own repository.
id="$(curl -fsSL -H "Authorization: Bearer $GH_TOKEN" \
  "https://api.github.com/repos/$slug/releases?per_page=100" \
  | php -r '/* find the cloud-vendor release, print the id of $asset */')"
curl -fsSL -H "Authorization: Bearer $GH_TOKEN" -H 'Accept: application/octet-stream' \
  "https://api.github.com/repos/$slug/releases/assets/$id" -o "$bundle"

rm -rf vendor
zstd -dcq "$bundle" | tar -xf -

# vendor/ already matches the lock, so this only regenerates the autoloader and
# runs package scripts. With the network disabled, a mismatch fails here
# instead of reaching for GitHub.
COMPOSER_DISABLE_NETWORK=1 composer install --no-interaction --no-progress

It also:

  • seeds .env from .env.example and runs php artisan key:generate;
  • runs pnpm install --frozen-lockfile --prefer-offline (the npm registry is outside the GitHub proxy, so pnpm just works);
  • stamps vendor/ with the lockfile hash, so a resumed session skips the whole thing;
  • serialises concurrent callers with flock (a worktree bootstrap and an MCP server launcher can race the hook);
  • prints a short report, which becomes the first thing the agent reads:
[cloud-repo-bootstrap] .env: seeded from .env.example
[cloud-repo-bootstrap] composer: installed from the c0a14ac96b3c vendor bundle in 6s
[cloud-repo-bootstrap] APP_KEY: generated
[cloud-repo-bootstrap] pnpm: installed in 17s
[cloud-repo-bootstrap] PHP 8.5.10, Node v24.21.0, pnpm 11.23.0. Log: /tmp/cloud-repo-bootstrap.app.log

A fallback that doesn't prompt

Sometimes there's no bundle yet: say a branch changed composer.lock and the workflow hasn't finished. Git reads of public repositories pass the proxy without a prompt, so the helper falls back to fetching only each package's locked commit, shallow and 16 at a time. It packs each commit into a local zip with git archive (which honours export-ignore, just like GitHub's own archives). Then it installs from a rewritten copy of the lock whose dist URLs point at those file:// zips, again with COMPOSER_DISABLE_NETWORK=1.

git init -q --bare "$repo"
git -C "$repo" fetch -q --depth 1 "$url" "$sha"
git -C "$repo" archive --format=zip --prefix=package/ -o "$zips/$key.zip" "$sha"

composer.lock itself is never touched. Composer derives the lock file's name from the COMPOSER environment variable, so COMPOSER=composer.cloud.json reads composer.cloud.lock. The content hash still matches, because the JSON is byte-identical. One wrinkle: some packages, such as phpstan/phpstan, have no source URL in the lock, only a dist URL. For those the helper takes the repository name from the dist URL.

Numbers

Path Composer time
--prefer-source (clean container) 382 s
Shallow-fetch fallback (clean container, 180 packages) 16 s
Bundle, 39 MB 6 s
Bundle, 58 MB 10 s

pnpm adds another 10–20 seconds.

Part 3: tell the agent

The last piece is prose. Put this in AGENTS.md or CLAUDE.md:

Claude Code cloud sessions: the SessionStart hook installs vendor/ from this repo's prebuilt bundle and prints a [cloud-repo-bootstrap] report. Trust that report. In the cloud never run composer install/update against the network and never call add_repo for a dependency repository: the GitHub proxy refuses those downloads, and each add_repo is a manual permission grant. If the report says there is no bundle for this lock, push composer.lock and rerun cloud-repo-bootstrap --force. Keep the cloud-vendor release a draft.

Without it, the agent will do what the 403 message suggests.

Things I'd tell myself at the start

  • A container isn't the cloud. My first version passed every test in a clean Ubuntu container, because the container has no GitHub proxy. I then wrote up "git clones work, just slowly" on the strength of a code comment and a container. Only a diagnostic run inside a real session (a few curls and one git fetch) showed what the proxy actually allows. Run that first.
  • Separate the toolchain from the dependencies. Anything that needs the checkout goes in the hook. Anything machine-wide goes in the setup script, including a shared helper, so each repository only needs one line of JSON.
  • Resuming doesn't re-run the setup script. After you edit it, start a new session.
  • Multi-repository sessions don't load any repository's hooks. Run cloud-repo-bootstrap --force <dir> for each checkout yourself.
  • You can't replace the base image on Anthropic-hosted environments. Self-hosted environments let you bring your own image, and they skip the GitHub proxy too. That's the heavier option if you already run build infrastructure.