fix: cache update-check result to avoid curl on every session start#15
fix: cache update-check result to avoid curl on every session start#15xiaolai wants to merge 1 commit into
Conversation
Previously, session-start.sh called the GitHub Releases API unconditionally on every Claude Code session startup, adding network latency to each session. Cache the latest-tag result in ~/.cache/supaconductor/last-update-check and skip the outbound request if the cache file is under 24 hours old. Co-Authored-By: Claude Code <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request implements a 24-hour caching mechanism for GitHub update checks in hooks/session-start.sh to improve performance and reduce API calls. Review feedback identifies an invalid -quiet flag in the find command that would cause the cache check to fail and suggests adhering to the XDG Base Directory Specification by using XDG_CACHE_HOME for the cache directory path.
| | sed 's/^v//' | head -1) || true | ||
| latest_tag="" | ||
| # Skip network call if cache is less than 24 hours old | ||
| if [ -f "$CACHE_FILE" ] && find "$CACHE_FILE" -mmin -1440 -quiet 2>/dev/null | grep -q .; then |
There was a problem hiding this comment.
The -quiet flag is not a standard option for the find command in most common implementations (GNU, BSD/macOS, etc.). Including it will cause the find command to fail with an error. Due to pipefail being set at the top of the script, the entire condition will evaluate to false, meaning the cache will never be used and the script will perform a network request on every session start, defeating the purpose of this change.
| if [ -f "$CACHE_FILE" ] && find "$CACHE_FILE" -mmin -1440 -quiet 2>/dev/null | grep -q .; then | |
| if [ -f "$CACHE_FILE" ] && find "$CACHE_FILE" -mmin -1440 2>/dev/null | grep -q .; then |
| # Check for latest release on GitHub (non-blocking, 3s timeout) | ||
| # Check for latest release on GitHub (non-blocking, 3s timeout, cached 24h) | ||
| REPO="Ibrahim-3d/orchestrator-supaconductor" | ||
| CACHE_DIR="${HOME}/.cache/supaconductor" |
There was a problem hiding this comment.
It is recommended to respect the XDG_CACHE_HOME environment variable if it is set, falling back to ~/.cache otherwise. This adheres better to the XDG Base Directory Specification followed by many Linux distributions and CLI tools.
| CACHE_DIR="${HOME}/.cache/supaconductor" | |
| CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/supaconductor" |
Bug:
hooks/session-start.shcalls the GitHub Releases API unconditionally on every Claude Code session start, adding network latency to each session with no caching.Evidence: Line 24:
curl -s --max-time 3 "https://api.github.com/repos/${REPO}/releases/latest"executes on everySessionStarthook invocation with no freshness check; confirmed by reading the file — no cache-file path, no age check, no skip logic.Fix: Reads the cached version from
~/.cache/supaconductor/last-update-checkwhen the file is under 24 hours old (find -mmin -1440); only runscurlwhen the cache is stale or absent, then writes the result back to the cache.