Skip to content

Add SessionStart hook installing Swift via swiftly for web sessions - #7

Open
leogdion wants to merge 6 commits into
mainfrom
claude/swift-dev-setup-linux-tjepkd
Open

Add SessionStart hook installing Swift via swiftly for web sessions#7
leogdion wants to merge 6 commits into
mainfrom
claude/swift-dev-setup-linux-tjepkd

Conversation

@leogdion

@leogdion leogdion commented Aug 7, 2026

Copy link
Copy Markdown
Member

Installs the swift.org Ubuntu 24.04 system deps, then swiftly and the
toolchain pinned by .swift-version, and persists the Swift PATH to
CLAUDE_ENV_FILE. Skips entirely when swift is already installed or the
session is not remote.

Not yet verified end-to-end: download.swift.org is currently blocked by
the environment network policy and must be allowlisted first.

Co-Authored-By: Claude Fable 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_012gBcWa6xeuaMwdvzSfruns

Summary by CodeRabbit

  • Chores

    • Added automatic setup for Swift and SwiftLint in remote development sessions.
    • Pinned Swift toolchains are reused when available, with fallback installation support.
    • Build and test workflows remain available if lint tooling cannot be installed.
    • SourceKit support is configured for Linux-based linting.
  • Bug Fixes

    • Prevented Periphery scans from running in CI and remote development sessions, reducing unnecessary failures and delays.
  • Documentation

    • Added guidance for remote Linux builds, toolchain setup, and linting differences.

claude added 6 commits August 7, 2026 07:39
Installs the swift.org Ubuntu 24.04 system deps, then swiftly and the
toolchain pinned by .swift-version, and persists the Swift PATH to
CLAUDE_ENV_FILE. Skips entirely when swift is already installed or the
session is not remote.

Not yet verified end-to-end: download.swift.org is currently blocked by
the environment network policy and must be allowlisted first.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012gBcWa6xeuaMwdvzSfruns
Adds a soft-failing mise section after the Swift install: installs mise
via mise.run, trusts the repo config, and runs mise install for the
pinned swift-format, SwiftLint, and periphery. Lint tooling failure
warns loudly but leaves the session able to build and test.

Not yet verified end-to-end: mise.run and mise.jdx.dev are blocked by
the environment network policy and must be allowlisted first.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012gBcWa6xeuaMwdvzSfruns
mise install cannot run in Claude Code web sessions: the session's
GitHub gateway scopes api.github.com to session-attached repos, so
mise's release lookups 403 on the tool repos. Install the same pinned
versions (parsed from mise.toml) via anonymous public git clones and
release-asset downloads instead: SwiftLint as a prebuilt binary,
swift-format and periphery built from source.

The hook now runs async so the session starts immediately; progress
logs to ~/.claude-session-setup.log and ~/.claude-session-setup.done
marks completion.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012gBcWa6xeuaMwdvzSfruns
SwiftLint dlopens libsourcekitdInProc.so from the Swift toolchain and
locates it via LINUX_SOURCEKIT_LIB_PATH; without it, swiftlint crashes
on Linux. Resolve the toolchain lib dir after install and persist the
export to the session env file.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012gBcWa6xeuaMwdvzSfruns
Stop compiling swift-format and periphery from source in the SessionStart
hook (~15 min of the cold start). SwiftLint stays eager via its prebuilt
release binary; swift-format now resolves to the binary bundled with the
Swift toolchain via the swiftly shims; the periphery scan is skipped in
web sessions by Scripts/lint.sh (CLAUDE_CODE_REMOTE guard) since it has
no Linux binaries and is not worth building there.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012gBcWa6xeuaMwdvzSfruns
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds a Claude Code session-start hook that configures Swift and SwiftLint tooling asynchronously. It registers the hook, documents Linux setup, and skips Periphery during remote Claude Code sessions.

Changes

Claude Code Swift setup

Layer / File(s) Summary
Session-start hook wiring
.claude/settings.json, .claude/hooks/session-start.sh
Claude Code runs the session-start script. The script initializes asynchronous setup and exports Swiftly and tool paths.
Swift and SwiftLint setup
.claude/hooks/session-start.sh
The script installs or reuses pinned Swift and SwiftLint versions, falls back to the latest Swift toolchain when needed, and exports SourceKit settings.
Remote lint behavior and guidance
Scripts/lint.sh, CLAUDE.md
Remote Claude Code sessions skip Periphery. The documentation describes Linux toolchain setup and remote lint behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ClaudeCode
  participant session_start_sh
  participant Swiftly
  participant SwiftLint
  participant Scripts_lint_sh
  ClaudeCode->>session_start_sh: Run SessionStart hook
  session_start_sh->>Swiftly: Load or install Swift toolchain
  session_start_sh->>SwiftLint: Reuse or install pinned release
  session_start_sh-->>ClaudeCode: Export environment and mark setup complete
  ClaudeCode->>Scripts_lint_sh: Run lint script
  Scripts_lint_sh-->>ClaudeCode: Skip Periphery in remote sessions
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a SessionStart hook that installs Swift with swiftly for web sessions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/swift-dev-setup-linux-tjepkd

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.claude/hooks/session-start.sh:
- Around line 105-110: Add trusted SHA-256 verification to the SwiftLint
download flow in the session-start script: define the expected digest for the
selected swiftlint_version release asset, validate swiftlint.zip before
unzip/install, and abort on mismatch. Keep installation through the verified
archive, or switch to a supported distribution path if the asset cannot be
reliably verified.

In @.claude/settings.json:
- Line 8: Quote the CLAUDE_PROJECT_DIR-based hook command in the SessionStart
configuration so paths containing whitespace remain a single shell argument;
update the command value without changing the hook script or surrounding
configuration.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2f047745-a6fa-44aa-b672-b70778bcf23e

📥 Commits

Reviewing files that changed from the base of the PR and between 6949abb and e39698a.

📒 Files selected for processing (4)
  • .claude/hooks/session-start.sh
  • .claude/settings.json
  • CLAUDE.md
  • Scripts/lint.sh

Comment on lines +105 to +110
workdir="$(mktemp -d)"
curl -fsSL -o "$workdir/swiftlint.zip" \
"https://github.com/realm/SwiftLint/releases/download/$swiftlint_version/swiftlint_linux_amd64.zip"
unzip -q -o "$workdir/swiftlint.zip" -d "$workdir"
install -m 755 "$workdir/swiftlint" "$TOOLS_BIN/swiftlint"
rm -rf "$workdir"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== files =="
git ls-files | rg '(^|/)(session-start\.sh|package\.json|Package\.swif|README\.md|\.claude)?' || true

echo "== target lines =="
if [ -f .claude/hooks/session-start.sh ]; then
  nl -ba .claude/hooks/session-start.sh | sed -n '90,120p'
else
  echo "missing .claude/hooks/session-start.sh"
fi

echo "== swiftlint occurrences =="
rg -n "swiftlint|SwiftLint|SWIFTLINT|realm/SwiftLint" . -S || true

echo "== diff summary =="
git diff --stat || true
git diff -- .claude/hooks/session-start.sh | sed -n '1,220p' || true

echo "== package manifests with swiftlint =="
rg -n '"swiftlint"|swiftlint|SwiftLint' -g 'package.json' -g 'Package.swift' . || true

Repository: brightdigit/ConfigKeyKit

Length of output: 2772


🌐 Web query:

SwiftLint official GitHub releases SHA-256 manifest swiftlint_linux_amd64.zip checksum signatures

💡 Result:

The official SwiftLint GitHub releases do not currently provide a dedicated, separate SHA-256 manifest file for the swiftlint_linux_amd64.zip artifact [1][2]. While SwiftLint provides checksums for some Bazel-related files (e.g., bazel.tar.gz.sha256) within their release assets, they do not publish an equivalent file for the Linux binary zip archives [2][3][4]. To verify the integrity of the swiftlint_linux_amd64.zip file, you must compute the SHA-256 checksum manually after downloading and compare it against the expected hash, if available from other trusted infrastructure-as-code or packaging sources that reference these binaries [5][6]. If you are using SwiftLint in an automated environment, the recommended practice for verifying downloaded binaries is to compute the checksum locally using the sha256sum utility [7][8]: sha256sum swiftlint_linux_amd64.zip Note that because the maintainers do not provide an official manifest file for the Linux zip, you cannot verify the file against an official SwiftLint-hosted checksum file [2][3][4]. Some third-party integrations (such as package managers or CI tools) maintain their own lists of known-good hashes for SwiftLint versions [5]. If you are relying on these, you should ensure those sources are trusted. {top_results: [2][3][4][5]}

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== target lines =="
python3 - <<'PY' path=.claude/hooks/session-start.sh 120 95 lin=106-110
import sys
path=sys.argv[1]
with open(path, 'r') as f:
    lines=f.read().splitlines()
print(f"file {path} line count {len(lines)}")
for i in range(max(1,len(lines)-125), min(len(lines),130)+1):
    if 90 <= i <= 120:
        print(f"{i:5d}\t{lines[i-1]}")
PY

echo "== swiftlint occurrences =="
rg -n "swiftlint|SwiftLint|SWIFTLINT|realm/SwiftLint|swiftlint_version" . -S || true

echo "== package manifests with swiftlint =="
rg -n '"swiftlint"|SwiftLint|SwiftLint\.Tools|swiftlint' -g 'package.json' -g 'Package.swift' . || true

echo "== tools setup snippets =="
if [ -f .github/actions/setup-tools/action.yml ]; then
  sed -n '1,220p' .github/tasks || sed -n '1,220p' .github/actions/setup-tools/action.yml
fi

echo "== behavioral/static extraction =="
python3 - <<'PY'
import re, pathlib
p=pathlib.Path('.claude/hooks/session-start.sh')
text=p.read_text()
m=re.search(r'swiftlint_version\s*=\s*["'\'']([^"'\'']+)["'\'']', text)
print("swiftlint_version", m.group(1) if m else "NOT FOUND")
asset='swiftlint_linux_amd64.zip'
checksum_tokens=[x for x in ['sha256sum','shasum','sha256']]
found=[]
for tok in checksum_tokens:
    if tok in text.lower():
        found.append(tok)
print("checksum/token", found if found else "NONE")
print("curl asset present", 'curl' in text and asset.replace('_','_') in text)
PY

Repository: brightdigit/ConfigKeyKit

Length of output: 348


Verify the SwiftLint release asset before installation.

The script installs swiftlint_linux_amd64.zip without a checksum or signature check. Add a trusted SHA-256 digest for this release asset and validate the archive before install. If SwiftLint only supports another distribution path, use that path instead of the direct release asset.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.claude/hooks/session-start.sh around lines 105 - 110, Add trusted SHA-256
verification to the SwiftLint download flow in the session-start script: define
the expected digest for the selected swiftlint_version release asset, validate
swiftlint.zip before unzip/install, and abort on mismatch. Keep installation
through the verified archive, or switch to a supported distribution path if the
asset cannot be reliably verified.

Comment thread .claude/settings.json
"hooks": [
{
"type": "command",
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/session-start.sh"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Quote the hook path.

Line 8 expands CLAUDE_PROJECT_DIR without quotes. If the project path contains whitespace, the shell splits the command and the SessionStart hook fails.

Proposed fix
-            "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/session-start.sh"
+            "command": "\"$CLAUDE_PROJECT_DIR/.claude/hooks/session-start.sh\""
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/session-start.sh"
"command": "\"$CLAUDE_PROJECT_DIR/.claude/hooks/session-start.sh\""
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.claude/settings.json at line 8, Quote the CLAUDE_PROJECT_DIR-based hook
command in the SessionStart configuration so paths containing whitespace remain
a single shell argument; update the command value without changing the hook
script or surrounding configuration.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants