@anthropic-ai/claude-code 0.2.32 → 0.2.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/claude-restart.sh +85 -0
- package/{cli.mjs → cli.js} +705 -602
- package/package.json +2 -2
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
# Claude CLI Restart Wrapper
|
|
4
|
+
#
|
|
5
|
+
# This script acts as a wrapper around the main Claude CLI (cli.mjs) that:
|
|
6
|
+
# 1. Launches the CLI with the same arguments passed to this script
|
|
7
|
+
# 2. Monitors the CLI process for a special exit code (42)
|
|
8
|
+
# 3. If the special exit code is detected, it restarts the CLI with the same arguments
|
|
9
|
+
# 4. Prevents infinite restart loops by limiting restart attempts
|
|
10
|
+
|
|
11
|
+
# Get the directory where this script is located
|
|
12
|
+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
13
|
+
|
|
14
|
+
# Path to cli.mjs - look for it in the same directory as this script
|
|
15
|
+
CLI_PATH="$SCRIPT_DIR/cli.js"
|
|
16
|
+
|
|
17
|
+
# DO NOT change the current working directory
|
|
18
|
+
# The CLI needs to maintain the original working directory it was launched from
|
|
19
|
+
|
|
20
|
+
# Define the signal we'll use to indicate a restart is needed
|
|
21
|
+
# Using exit code 42 as our special signal
|
|
22
|
+
RESTART_EXIT_CODE=42
|
|
23
|
+
|
|
24
|
+
# Track restart attempts to prevent infinite restart loops
|
|
25
|
+
RESTART_COUNT=0
|
|
26
|
+
MAX_RESTARTS=5
|
|
27
|
+
RESTART_RESET_TIME=60 # 1 minute in seconds
|
|
28
|
+
|
|
29
|
+
# Check if cli.mjs exists
|
|
30
|
+
if [ ! -f "$CLI_PATH" ]; then
|
|
31
|
+
echo "Error: Could not find $CLI_PATH"
|
|
32
|
+
exit 1
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
# Function to start the CLI
|
|
36
|
+
start_cli() {
|
|
37
|
+
local is_restart="${2:-false}"
|
|
38
|
+
local args=("$@")
|
|
39
|
+
|
|
40
|
+
# Remove the is_restart parameter from args
|
|
41
|
+
if [ "$is_restart" = "true" ]; then
|
|
42
|
+
# If second parameter is "true", remove first two parameters
|
|
43
|
+
args=("${args[@]:2}")
|
|
44
|
+
else
|
|
45
|
+
# If second parameter is not "true", just remove first parameter
|
|
46
|
+
args=("${args[@]:1}")
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
# If we restart too many times in a short period, exit
|
|
50
|
+
if [ $RESTART_COUNT -ge $MAX_RESTARTS ]; then
|
|
51
|
+
echo "Too many restarts ($RESTART_COUNT) in a short period. Exiting."
|
|
52
|
+
exit 1
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
# If this is a restart and no args are provided, add 'resume 0' to restore the last conversation
|
|
56
|
+
if [ "$is_restart" = "true" ] && [ ${#args[@]} -eq 0 ]; then
|
|
57
|
+
args=("resume" "0")
|
|
58
|
+
fi
|
|
59
|
+
|
|
60
|
+
# Run cli.mjs with the provided arguments
|
|
61
|
+
"$CLI_PATH" "${args[@]}"
|
|
62
|
+
|
|
63
|
+
# Capture the exit code
|
|
64
|
+
EXIT_CODE=$?
|
|
65
|
+
|
|
66
|
+
# Check if we need to restart
|
|
67
|
+
if [ $EXIT_CODE -eq $RESTART_EXIT_CODE ]; then
|
|
68
|
+
RESTART_COUNT=$((RESTART_COUNT + 1))
|
|
69
|
+
|
|
70
|
+
# Reset restart counter after some time (in background)
|
|
71
|
+
(
|
|
72
|
+
sleep $RESTART_RESET_TIME
|
|
73
|
+
RESTART_COUNT=0
|
|
74
|
+
) &
|
|
75
|
+
|
|
76
|
+
# Restart with the same arguments
|
|
77
|
+
start_cli "true" "${args[@]}"
|
|
78
|
+
else
|
|
79
|
+
# Any other exit code - exit with the same code
|
|
80
|
+
exit $EXIT_CODE
|
|
81
|
+
fi
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# Start the CLI with all arguments passed to this script
|
|
85
|
+
start_cli "false" "$@"
|