Skip to content

Commit 29f2e9a

Browse files
claudehyperpolymath
authored andcommitted
Add Claude Code on the web SessionStart hook for cargo warm-up
Web (cloud) sessions start from a fresh clone, so dependencies and the build cache are cold. This adds a cloud-only SessionStart hook that warms the Rust workspace before Claude starts working, so `cargo test`, `cargo clippy`, and `cargo fmt` are immediately usable. - .claude/hooks/session-start.sh: guarded on CLAUDE_CODE_REMOTE (no-op on local checkouts); runs `cargo fetch --locked` then `cargo build --workspace --all-targets`; logs verbose cargo output to a temp file to keep session context clean; best-effort so a transient failure never blocks session startup. - .claude/settings.json: registers the hook on startup|resume. - REUSE.toml: cover .claude/** under MPL-2.0 (settings.json carries no inline SPDX header; the shell script has one). Only the pre-installed cargo toolchain is exercised; the optional Idris2/Zig recipes are not required for the Rust test/lint path and are intentionally omitted. Validated in a cloud session: hook exits 0, local-skip is a no-op, `cargo clippy --workspace` and the integration tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017nyxs8RgqZa72PzrTu3L75
1 parent 1e20d0e commit 29f2e9a

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

.claude/hooks/session-start.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: MPL-2.0
3+
# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
4+
#
5+
# SessionStart hook for Claude Code on the web (cloud sessions).
6+
#
7+
# Prefetches workspace dependencies and warms the Rust build cache so that
8+
# `cargo test`, `cargo clippy`, and `cargo fmt` are ready immediately when a
9+
# cloud session starts. Local sessions are skipped — your own machine already
10+
# has the toolchain and dependencies, and this hook runs everywhere by design.
11+
#
12+
# Only the Rust toolchain (cargo) is exercised here: it is pre-installed in
13+
# cloud sessions and drives the canonical `cargo test` suite. The optional
14+
# Idris2/Zig pieces (idris-check, zig-build) are not pre-installed and are not
15+
# required for the Rust test/lint path, so they are intentionally left out.
16+
#
17+
# Docs: https://code.claude.com/docs/en/claude-code-on-the-web
18+
set -euo pipefail
19+
20+
# Cloud-only: do nothing on local checkouts.
21+
if [ "${CLAUDE_CODE_REMOTE:-}" != "true" ]; then
22+
exit 0
23+
fi
24+
25+
ROOT="${CLAUDE_PROJECT_DIR:-$PWD}"
26+
cd "$ROOT" || exit 0
27+
28+
# Keep verbose cargo output out of the session context; log to a temp file.
29+
LOG="${TMPDIR:-/tmp}/vcl-ut-session-start.log"
30+
echo "[vcl-ut] Warming Rust workspace (cargo fetch + build --all-targets). Log: $LOG"
31+
32+
# 1. Fetch all workspace dependencies. Cargo.lock is authoritative; fall back to
33+
# an unlocked fetch if the lockfile is ever out of date. Idempotent and fast
34+
# once the registry cache is populated.
35+
cargo fetch --locked >"$LOG" 2>&1 || cargo fetch >>"$LOG" 2>&1 || true
36+
37+
# 2. Warm the build cache for every target (lib + bins + tests + benches) so the
38+
# first `cargo test` / `cargo clippy` the agent runs is near-instant. Best
39+
# effort: a transient failure here must not block the session from starting.
40+
cargo build --workspace --all-targets >>"$LOG" 2>&1 || true
41+
42+
echo "[vcl-ut] Workspace ready."
43+
exit 0

.claude/settings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"hooks": {
3+
"SessionStart": [
4+
{
5+
"matcher": "startup|resume",
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/session-start.sh"
10+
}
11+
]
12+
}
13+
]
14+
}
15+
}

REUSE.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ SPDX-License-Identifier = "MPL-2.0"
8686

8787
[[annotations]]
8888
path = [
89+
".claude/**",
8990
".devcontainer/**",
9091
".github/**",
9192
".machine_readable/**",

0 commit comments

Comments
 (0)