-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_claude_code.sh
More file actions
60 lines (45 loc) · 1.88 KB
/
update_claude_code.sh
File metadata and controls
60 lines (45 loc) · 1.88 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
58
59
60
#!/bin/bash
set -euo pipefail
CHANGELOG_URL="https://raw.githubusercontent.com/anthropics/claude-code/main/CHANGELOG.md"
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
print_version_summary() {
local old_version="${1:-not installed}"
local new_version="${2:-unknown}"
echo "VERSION_SUMMARY|old=${old_version}|new=${new_version}"
}
version_gt() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"
}
echo -e "${YELLOW}Checking Claude Code version...${NC}"
if ! command -v claude >/dev/null 2>&1; then
echo -e "${RED}Error: 'claude' command not found. Visit https://code.claude.com/docs/en/quickstart for installation instructions.${NC}"
exit 1
fi
local_version="$(claude --version | awk '{print $1}')"
echo "Local version: $local_version"
latest_version="$(curl -sL "$CHANGELOG_URL" | grep -E "^##? \[?[0-9]+\.[0-9]+\.[0-9]+" | head -n 1 | grep -oE "[0-9]+\.[0-9]+\.[0-9]+")"
if [ -z "$latest_version" ]; then
echo -e "${RED}Error: failed to fetch the remote version. Check your network connection.${NC}"
exit 1
fi
echo "Latest version: $latest_version"
if [ "$local_version" = "$latest_version" ]; then
print_version_summary "$local_version" "$local_version"
echo -e "${GREEN}Claude Code is already up to date.${NC}"
exit 0
fi
if version_gt "$latest_version" "$local_version"; then
echo -e "${YELLOW}New version detected. Preparing update...${NC}"
echo "Running command: claude install $latest_version"
claude install "$latest_version"
new_ver="$(claude --version | awk '{print $1}')"
echo -e "${GREEN}Update completed successfully.${NC}"
echo "Current version: $new_ver"
print_version_summary "$local_version" "$new_ver"
exit 0
fi
print_version_summary "$local_version" "$local_version"
echo -e "${GREEN}Local version ($local_version) is newer than or equal to changelog version ($latest_version).${NC}"