-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.sh
More file actions
57 lines (49 loc) · 2.72 KB
/
env.sh
File metadata and controls
57 lines (49 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash
# ~/.config/claude/env.sh — Thin bootstrap for Claude Code environment
#
# This file fetches and caches the full configuration from a central URL.
# DO NOT put configuration logic here — edit the remote source instead.
#
# Install: curl -fsSL https://raw.githubusercontent.com/aproorg/claude-wrapper/main/install.js | node
# Update: rm ~/.cache/claude/env-remote.sh (or wait for TTL expiry)
# Debug: CLAUDE_DEBUG=1 claude
# ── Remote source URL ─────────────────────────────────────────────────────────
# Override with CLAUDE_ENV_URL environment variable if needed.
CLAUDE_ENV_REMOTE_URL="${CLAUDE_ENV_URL:-https://raw.githubusercontent.com/aproorg/claude-wrapper/main/claude-env.sh}"
# ── Cache settings ────────────────────────────────────────────────────────────
_CLAUDE_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/claude"
_CLAUDE_CACHE_FILE="$_CLAUDE_CACHE_DIR/env-remote.sh"
_CLAUDE_UPDATE_TTL="${CLAUDE_ENV_UPDATE_TTL:-300}" # check every 5 minutes
# ── Helpers ───────────────────────────────────────────────────────────────────
_claude_needs_update() {
[[ ! -f "$_CLAUDE_CACHE_FILE" ]] && return 0
local age
age=$(($(date +%s) - $(stat -f %m "$_CLAUDE_CACHE_FILE" 2>/dev/null || stat -c %Y "$_CLAUDE_CACHE_FILE" 2>/dev/null || echo 0)))
[[ $age -ge $_CLAUDE_UPDATE_TTL ]]
}
_claude_fetch_env() {
(umask 077; mkdir -p "$_CLAUDE_CACHE_DIR")
local tmp="$_CLAUDE_CACHE_FILE.tmp.$$"
if (umask 077; curl -fsSL --connect-timeout 3 --max-time 10 "$CLAUDE_ENV_REMOTE_URL" -o "$tmp") 2>/dev/null; then
mv "$tmp" "$_CLAUDE_CACHE_FILE"
else
rm -f "$tmp"
# No cached copy at all — hard fail
if [[ ! -f "$_CLAUDE_CACHE_FILE" ]]; then
echo "ERROR: Cannot fetch Claude env from $CLAUDE_ENV_REMOTE_URL (no cache)" >&2
return 1
fi
# Stale cache exists — use it silently
fi
}
# ── Main ──────────────────────────────────────────────────────────────────────
if _claude_needs_update; then
_claude_fetch_env
fi
if [[ -f "$_CLAUDE_CACHE_FILE" ]]; then
# shellcheck disable=SC1090
source "$_CLAUDE_CACHE_FILE" "$@"
fi
# Cleanup helper names from the shell namespace
unset -f _claude_needs_update _claude_fetch_env
unset _CLAUDE_CACHE_DIR _CLAUDE_CACHE_FILE _CLAUDE_UPDATE_TTL