Skip to content

Instantly share code, notes, and snippets.

@bannzai
Last active January 26, 2026 12:29
Show Gist options
  • Select an option

  • Save bannzai/0b762d81d9d115bb1aa3b81037322478 to your computer and use it in GitHub Desktop.

Select an option

Save bannzai/0b762d81d9d115bb1aa3b81037322478 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# SessionStart hook: install Flutter SDK on Claude Code on the Web
LOG_PREFIX="[flutter-setup]"
log(){ echo "$LOG_PREFIX $*" >&2; }
# Only run in Claude Code on the Web
if [[ "${CLAUDE_CODE_REMOTE:-}" != "true" ]]; then
exit 0
fi
# Move to project root (safe)
if [ -n "${CLAUDE_PROJECT_DIR:-}" ] && [ -d "${CLAUDE_PROJECT_DIR}" ]; then
cd "${CLAUDE_PROJECT_DIR}"
fi
# Require jq
if ! command -v jq >/dev/null 2>&1; then
log "ERROR: jq is not installed in this environment."
exit 0
fi
INSTALL_DIR="${HOME}/.flutter-sdk"
FLUTTER_BIN="${INSTALL_DIR}/bin/flutter"
SHARED_SH="${INSTALL_DIR}/bin/internal/shared.sh"
RELEASES_JSON_URL="https://storage.googleapis.com/flutter_infra_release/releases/releases_linux.json"
log "start"
# Persist PATH for subsequent commands in the session
ensure_path() {
export FLUTTER_HOME="${INSTALL_DIR}"
export PATH="${PATH}:${INSTALL_DIR}/bin"
if [ -n "${CLAUDE_ENV_FILE:-}" ]; then
if ! grep -q 'export FLUTTER_HOME=' "$CLAUDE_ENV_FILE" 2>/dev/null; then
{
echo "export FLUTTER_HOME=\"${INSTALL_DIR}\""
echo "export PATH=\"\$PATH:${INSTALL_DIR}/bin\""
} >> "${CLAUDE_ENV_FILE}"
log "PATH persisted to CLAUDE_ENV_FILE"
fi
else
marker="# >>> claude-web-flutter >>>"
if ! grep -qF "${marker}" "${HOME}/.bashrc" 2>/dev/null; then
{
echo "${marker}"
echo "export FLUTTER_HOME=\"${INSTALL_DIR}\""
echo "export PATH=\"\$PATH:${INSTALL_DIR}/bin\""
echo "# <<< claude-web-flutter <<<"
} >> "${HOME}/.bashrc"
fi
fi
}
# Check if Flutter SDK is complete (not just binary exists)
needs_install=false
if [ ! -x "${FLUTTER_BIN}" ]; then
needs_install=true
log "Flutter binary not found"
elif [ ! -f "${SHARED_SH}" ]; then
needs_install=true
log "Flutter SDK incomplete, reinstalling..."
fi
if [ "${needs_install}" = true ]; then
log "Fetching Flutter stable bundle info..."
releases_json="$(curl -fsSL "${RELEASES_JSON_URL}")" || {
log "Failed to fetch releases JSON"
exit 0
}
base_url="$(printf '%s' "${releases_json}" | jq -r '.base_url')"
stable_hash="$(printf '%s' "${releases_json}" | jq -r '.current_release.stable')"
archive="$(printf '%s' "${releases_json}" | jq -r --arg h "${stable_hash}" '.releases[] | select(.hash == $h) | .archive' | head -n 1)"
if [ -z "${archive}" ] || [ "${archive}" = "null" ]; then
log "ERROR: Could not resolve stable archive from releases JSON."
exit 0
fi
if [[ "${archive}" =~ ^https?:// ]]; then
tar_url="${archive}"
else
tar_url="${base_url%/}/${archive#/}"
fi
log "Bundle: ${tar_url}"
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT
# Clean up any incomplete installation
rm -rf "${INSTALL_DIR}"
mkdir -p "${INSTALL_DIR}"
# Download and extract based on file extension
if [[ "${tar_url}" == *.tar.xz ]]; then
log "Downloading tar.xz..."
if ! curl -fsSL "${tar_url}" -o "${tmp_dir}/flutter.tar.xz"; then
log "Failed to download Flutter SDK"
exit 0
fi
log "Extracting..."
if ! tar -xJf "${tmp_dir}/flutter.tar.xz" -C "${INSTALL_DIR}" --strip-components=1 2>&1; then
log "ERROR: tar extraction failed"
exit 0
fi
elif [[ "${tar_url}" == *.zip ]]; then
log "Downloading zip..."
if ! curl -fsSL "${tar_url}" -o "${tmp_dir}/flutter.zip"; then
log "Failed to download Flutter SDK"
exit 0
fi
log "Extracting..."
if ! unzip -q "${tmp_dir}/flutter.zip" -d "${tmp_dir}"; then
log "Failed to extract Flutter SDK"
exit 0
fi
mv "${tmp_dir}"/flutter/* "${INSTALL_DIR}/"
else
log "ERROR: Unknown archive format: ${tar_url}"
exit 0
fi
# Verify installation
if [ ! -f "${SHARED_SH}" ]; then
log "ERROR: Installation failed - shared.sh not found"
exit 0
fi
log "Flutter SDK extracted to ${INSTALL_DIR}"
else
log "Flutter already installed"
fi
ensure_path
# Fix git ownership issue
git config --global --add safe.directory "${INSTALL_DIR}"
flutter config --no-analytics >/dev/null 2>&1 || true
log "flutter --version"
if ! flutter --version >&2; then
log "ERROR: flutter --version failed"
exit 0
fi
if [ -f "pubspec.yaml" ]; then
log "flutter pub get"
if ! flutter pub get >&2; then
log "flutter pub get failed"
exit 0
fi
else
log "pubspec.yaml not found, skipping pub get"
fi
log "done"
exit 0
@bannzai
Copy link
Author

bannzai commented Jan 26, 2026

timeoutは長くしましょう

          {
            "type": "command",
            "command": "[ \"$CLAUDE_CODE_REMOTE\" = \"true\" ] && curl -fsSL https://gist.githubusercontent.com/bannzai/0b762d81d9d115bb1aa3b81037322478/raw/ccweb-flutter-install.sh | bash",
            "timeout": 300
          }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment