forked from Zeeno-atl/claude-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclaude-wrapper.sh
More file actions
54 lines (46 loc) · 1.46 KB
/
claude-wrapper.sh
File metadata and controls
54 lines (46 loc) · 1.46 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
#!/usr/bin/env bash
#
# Unofficial Claude Code CLI Wrapper
# Installs and runs the Claude Code CLI as the current user
# This is not an official Anthropic product
#
# Exit on errors
set -e
set -o pipefail
# Log function for better visibility
log() {
echo "$(date +'%Y-%m-%d %H:%M:%S') - $1"
}
# Configure npm to use user-specific directory (outside of /app)
export npm_config_prefix="/home/npm-global"
export PATH="/home/npm-global/bin:$PATH"
# Maximum number of install attempts
MAX_ATTEMPTS=3
ATTEMPT=1
# Install with retry logic
install_claude_cli() {
while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do
log "Installing Claude Code CLI as user (attempt $ATTEMPT of $MAX_ATTEMPTS)..."
if npm install -g @anthropic-ai/claude-code; then
log "Successfully installed Claude Code CLI as user"
return 0
else
if [ $ATTEMPT -lt $MAX_ATTEMPTS ]; then
log "Installation failed, retrying in 5 seconds..."
sleep 5
ATTEMPT=$((ATTEMPT+1))
else
log "ERROR: Failed to install Claude Code CLI after $MAX_ATTEMPTS attempts"
log "Try setting ANTHROPIC_API_KEY environment variable if authentication is failing"
log "Or check your internet connection and try again"
return 1
fi
fi
done
}
# Check if Claude is already installed in the user's space
if [ ! -f "/home/npm-global/bin/claude" ]; then
install_claude_cli || exit 1
fi
# Pass all arguments to Claude CLI
exec /home/npm-global/bin/claude "$@"