Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@ show_no_slots_menu() {
exit 1
}

# Show menu when all slots are currently in use
show_all_slots_running_menu() {
logo_small
echo
cecho "All slots are currently in use" "$YELLOW"
echo
printf "All your container slots are currently running.\n"
echo
printf " ${CYAN}claudebox slots${NC} - View all running slots\n"
printf " ${CYAN}claudebox slot <n>${NC} - Connect to specific slot\n"
printf " ${CYAN}claudebox create${NC} - Create an additional slot\n"
echo
printf " ${DIM}Tip: Multiple slots let you run parallel Claude sessions.${NC}\n"
echo
exit 1
}

# Show menu when no ready slots are available
show_no_ready_slots_menu() {
logo_small
Expand Down
33 changes: 32 additions & 1 deletion lib/project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ determine_next_start_container() {
dir="$parent/$name"
# Skip non-existent slots - they haven't been created yet
[ -d "$dir" ] || continue

# Check if a container with this slot name is running
if ! docker ps --format "{{.Names}}" | grep -q "^claudebox-.*-${name}$"; then
echo "$name"
Expand All @@ -196,6 +196,37 @@ determine_next_start_container() {
return 1
}

# Check if all slots are currently running (returns 0 if true)
all_slots_running() {
local path="$1" parent max idx name dir
parent=$(get_parent_dir "$path")
max=$(read_counter "$parent")

# If no slots created yet, return false
[ "$max" -eq 0 ] && return 1

local slot_count=0
local running_count=0

for ((idx=1; idx<=max; idx++)); do
name=$(generate_container_name "$path" "$idx")
dir="$parent/$name"

# Skip non-existent slots
[ -d "$dir" ] || continue

((slot_count++))

# Check if this slot is running
if docker ps --format "{{.Names}}" | grep -q "^claudebox-.*-${name}$"; then
((running_count++))
fi
done

# Return 0 (true) if we have slots and all are running
[ "$slot_count" -gt 0 ] && [ "$slot_count" -eq "$running_count" ]
}

# Find the first authenticated and inactive slot
find_ready_slot() {
local path="$1" parent max idx name dir
Expand Down
13 changes: 10 additions & 3 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,18 @@ main() {

# Get the slot to use (might be empty)
project_folder_name=$(get_project_folder_name "$PROJECT_DIR")

# Early exit if command needs Docker but no slots exist
if [[ "$project_folder_name" == "NONE" ]] && [[ "$cmd_requirements" == "docker" ]]; then
show_no_slots_menu
exit 1
# Check if slots exist but are all running
if all_slots_running "$PROJECT_DIR"; then
show_all_slots_running_menu
exit 1
else
# No slots exist at all
show_no_slots_menu
exit 1
fi
fi

# Always set IMAGE_NAME based on parent folder
Expand Down