forked from EvanCarroll/claude-podman
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclaude
More file actions
executable file
·94 lines (87 loc) · 2.12 KB
/
Copy pathclaude
File metadata and controls
executable file
·94 lines (87 loc) · 2.12 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# GH Repo - Replace to run a fork
REPO_NAME=evancarroll/claude-podman
# Default image
IMAGE="ghcr.io/$REPO_NAME/claude-code:latest"
NAME="claudecode-$(uuidgen -r | cut -d- -f1)"
INIT_SCRIPT=""
APK_PACKAGES=""
PODMAN_ARGS=""
# Process arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--help)
cat <<-'EOT'
Usage: claude [OPTIONS]
Run Claude Code in a Podman container
Options:
--local Use local image 'claude-code:latest' instead of remote
--init-script FILE Execute initialization script
--apk-packages LIST Install additional Alpine packages (comma or space separated)
--podman-arg ARG Pass additional argument to podman
--version Show the Claude Code version in the image
--help Display this help message
EOT
exit 0
;;
--self-update)
curl --proto '=https' --tlsv1.2 -sSf \
"https://raw.githubusercontent.com/$REPO_NAME/refs/heads/main/bin/claude" |
sed "s|^REPO_NAME=.*|REPO_NAME=$REPO_NAME|" |
sudo tee /usr/local/bin/claude-podman >/dev/null
sudo chmod a+x /usr/local/bin/claude-podman
echo "Updated"
exit 0
;;
--local)
IMAGE="localhost/claude-code:latest"
shift
;;
--init-script)
INIT_SCRIPT="$2"
shift 2
;;
--apk-packages)
APK_PACKAGES="$2"
shift 2
;;
--podman-arg)
PODMAN_ARGS="$PODMAN_ARGS $2"
shift 2
;;
--version)
podman run \
--rm \
--user claude \
--userns=keep-id:uid=1001,gid=1001 \
$PODMAN_ARGS \
"$IMAGE" --version
exit 0
;;
*)
break
;;
esac
done
podman run \
-v "${HOME}/.claude:/home/claude/.claude" \
-v "${HOME}/.claude.json:/home/claude/.claude.json" \
-v "${PWD}:${PWD}" \
-w "$PWD" \
--rm \
--name "$NAME" \
-ti \
--detach \
--user claude \
--userns=keep-id:uid=1000,gid=1000 \
$PODMAN_ARGS \
"$IMAGE" "$@"
if [ -n "$APK_PACKAGES" ]; then
APK_PACKAGES=$(echo $APK_PACKAGES | tr -s ', ' ' ')
podman exec --user root:root "$NAME" /bin/bash -c "apk update; apk add $APK_PACKAGES"
fi
if [ -n "$INIT_SCRIPT" ]; then
podman cp "$INIT_SCRIPT" "$NAME:/root/init.sh"
podman exec --user root:root "$NAME" bash /root/init.sh
fi
podman container attach "$NAME"