Repository navigation
Install Composer dependencies with a SessionStart hook in cloud sessions - #87
Draft
lisachenko wants to merge 1 commit into
Draft
lisachenko wants to merge 1 commit into
lisachenko wants to merge 1 commit into
Conversation
In Claude Code cloud sessions, anonymous requests to api.github.com hit the rate limit (HTTP 403). Composer then falls back to slow git clones for every package, and phpstan/phpstan, which has no git source, can't be installed. The hook resolves composer.lock from the Packagist metadata, builds each GitHub dist zip with a shallow git fetch and git archive (git through the session proxy isn't limited), puts the zips into Composer's cache, and runs composer install. From an empty cache it finishes in about 20 seconds. It runs only in cloud sessions and skips the install while composer.json and the script are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FxhC1Cr7rZzUgw16qS4vNV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every Claude Code cloud session starts with a slow and failing
composer install:api.github.comhit the rate limit (HTTP 403), so every dist zip download fails.phpstan/phpstanhas no git source, so it can't be installed at all, and the install fails with "Could not authenticate against github.com".Fix
.claude/hooks/session-start.sh, registered as a SessionStart hook in.claude/settings.json:composer.lockwithcomposer update --no-install. The lock file is not committed, and the Packagist metadata is not rate limited.git fetch --depth=1 <repo> <ref>andgit archive, 8 packages in parallel, and writes the zip to the file in Composer's cache that Composer would read (<package>/sha1(<dist url>).zip). Git through the session proxy is not limited. A package that can't be fetched this way is left to Composer.composer install, which now takes every package from the cache.Other behaviour:
CLAUDE_CODE_REMOTE=true, so local setups and CI are not affected.composer.jsonare unchanged. The hash file is in the ignoredvendor/directory.COMPOSER_ALLOW_SUPERUSER=1for the session, because the sandbox runs as root and Composer otherwise refuses to loadphpstan/extension-installer.AGENTS.md gets a short note about the hook.
Testing
vendor/and nocomposer.lock, the hook finishes in about 20 s with no 403 errors and no git-clone fallbacks. Without it, the install took more than 10 minutes and then failed on phpstan.composer.jsonmakes the hook run again. WithoutCLAUDE_CODE_REMOTEit does nothing.composer test(PHP-CS-Fixer, PHPStan level 10, 168 tests) andcomposer demopass.Generated by Claude Code