Skip to content

Commit b3e4314

Browse files
MrFlounderclaude
andcommitted
refactor(team): always enable team mode, fix restart layout
Changes: - Team mode is now always enabled (instructions in CLAUDE.md) - Removed --team flag (no longer needed) - `crab restart` now kills and recreates the full window layout - Fixes issue where closed panes weren't restored - Updated help text Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 9b78410 commit b3e4314

File tree

1 file changed

+30
-108
lines changed

1 file changed

+30
-108
lines changed

src/crabcode

Lines changed: 30 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ WIP_BASE="$CONFIG_DIR/wip"
3434
PROJECTS_DIR="$CONFIG_DIR/projects"
3535
GLOBAL_CONFIG="$CONFIG_DIR/config.yaml"
3636
PROJECT_ALIAS=""
37-
TEAM_PROMPT=""
38-
39-
# Default team prompt (used when --team is passed without a custom prompt)
40-
DEFAULT_TEAM_PROMPT="Create an agent team to help with this task. You are the team lead working in a crabcode workspace. Spawn teammates as needed for parallel work - research, implementation, review, or debugging. Coordinate the team, assign tasks, and synthesize results. The shared codebase is in this directory."
4137

4238
# Colors
4339
RED='\033[0;31m'
@@ -1301,38 +1297,18 @@ open_workspace() {
13011297
local dev_cmd=$(get_pane_command "server")
13021298
local claude_cmd=$(get_pane_command "main")
13031299

1304-
# Handle team mode: add or remove team section from CLAUDE.md
1300+
# Always ensure team context exists in CLAUDE.md
13051301
local team_file="$dir/.claude/CLAUDE.md"
1306-
if [ -n "${TEAM_PROMPT:-}" ]; then
1307-
# Team mode ON: add team section
1308-
mkdir -p "$dir/.claude"
1309-
1310-
# Remove existing team section if present, then append new one
1311-
if [ -f "$team_file" ]; then
1312-
# Remove team section (from ## Team Mode to next ## or end of file)
1313-
sed -i '' '/^## Team Mode$/,/^## [^T]/{ /^## Team Mode$/d; /^## [^T]/!d; }' "$team_file" 2>/dev/null || true
1314-
# Also handle if Team Mode is last section (no following ##)
1315-
sed -i '' '/^## Team Mode$/,$d' "$team_file" 2>/dev/null || true
1316-
fi
1302+
mkdir -p "$dir/.claude"
13171303

1318-
cat >> "$team_file" << EOF
1304+
# Add team section if not present
1305+
if ! grep -q "^## Team Mode$" "$team_file" 2>/dev/null; then
1306+
cat >> "$team_file" << 'EOF'
13191307
13201308
## Team Mode
13211309
1322-
$TEAM_PROMPT
1323-
1324-
When the user provides a task, spawn teammates as needed using the Task tool.
1310+
You can spawn agent teammates for complex tasks. Use the Task tool to create specialized agents (researcher, implementer, reviewer, debugger) that work in parallel. Coordinate the team, assign tasks, and synthesize results. Only spawn teams when the task benefits from parallel work.
13251311
EOF
1326-
echo -e "${MAGENTA}Team mode enabled${NC}"
1327-
else
1328-
# Team mode OFF: remove team section if it exists
1329-
if [ -f "$team_file" ]; then
1330-
# Remove team section
1331-
sed -i '' '/^## Team Mode$/,/^## [^T]/{ /^## Team Mode$/d; /^## [^T]/!d; }' "$team_file" 2>/dev/null || true
1332-
sed -i '' '/^## Team Mode$/,$d' "$team_file" 2>/dev/null || true
1333-
# Clean up trailing whitespace
1334-
sed -i '' -e :a -e '/^\n*$/{$d;N;ba' -e '}' "$team_file" 2>/dev/null || true
1335-
fi
13361312
fi
13371313

13381314
# Port override if needed
@@ -1356,17 +1332,7 @@ EOF
13561332
else
13571333
# Session exists
13581334
if tmux list-windows -t "$SESSION_NAME" -F "#{window_name}" 2>/dev/null | grep -q "^$window_name$"; then
1359-
# If team mode and window exists, restart the main pane so Claude sees new context
1360-
if [ -n "${TEAM_PROMPT:-}" ]; then
1361-
echo -e "${CYAN}Team mode: restarting Claude in workspace $num...${NC}"
1362-
# Find the main pane (usually pane 2) and restart Claude
1363-
local main_pane="${SESSION_NAME}:${window_name}.2"
1364-
tmux send-keys -t "$main_pane" C-c 2>/dev/null || true
1365-
sleep 0.5
1366-
tmux send-keys -t "$main_pane" "$claude_cmd" Enter 2>/dev/null || true
1367-
else
1368-
echo -e "${CYAN}Switching to workspace $num...${NC}"
1369-
fi
1335+
echo -e "${CYAN}Switching to workspace $num...${NC}"
13701336
if [ -n "$TMUX" ]; then
13711337
tmux select-window -t "$SESSION_NAME:$window_name"
13721338
else
@@ -1702,25 +1668,13 @@ restart_workspace() {
17021668

17031669
success "Git reset complete (on branch: $branch_name)"
17041670

1705-
# If we're in tmux, restart the panes
1706-
# Use current window if we're in the workspace dir, otherwise look for ws$num
1671+
# Rebuild the tmux window with full layout
17071672
if [ -n "$TMUX" ]; then
1708-
local current_window=$(tmux display-message -p '#{window_name}' 2>/dev/null)
1709-
local current_dir=$(pwd)
1710-
local use_current_window=false
1711-
1712-
# If we're in the workspace directory, use current window (even if renamed)
1713-
if [[ "$current_dir" == "$dir"* ]]; then
1714-
use_current_window=true
1715-
window_name="$current_window"
1716-
fi
1717-
1718-
# Check if we can use current window or if ws$num exists
1719-
if [ "$use_current_window" = true ] || tmux list-windows -t "$SESSION_NAME" -F "#{window_name}" 2>/dev/null | grep -q "^$window_name$"; then
17201673
local port_info=$(get_workspace_ports "$num" "$dir")
17211674
local api_port=$(echo "$port_info" | cut -d: -f1)
17221675
local app_port=$(echo "$port_info" | cut -d: -f2)
17231676
local need_override=$(echo "$port_info" | cut -d: -f3)
1677+
local env_api_port=$(echo "$port_info" | cut -d: -f4)
17241678

17251679
local dev_cmd=$(get_pane_command "server")
17261680
local claude_cmd=$(get_pane_command "main")
@@ -1729,32 +1683,30 @@ restart_workspace() {
17291683
dev_cmd="PORT=$api_port APP_PORT=$app_port $dev_cmd"
17301684
fi
17311685

1732-
# Get pane indices
1733-
local pane_indices=$(get_pane_indices)
1734-
local p_terminal=$(echo "$pane_indices" | cut -d: -f1)
1735-
local p_main=$(echo "$pane_indices" | cut -d: -f2)
1736-
local p_server=$(echo "$pane_indices" | cut -d: -f3)
1686+
local port_msg="Using port $env_api_port"
1687+
[ "$need_override" = "true" ] && port_msg="Port $env_api_port in use → using $api_port"
17371688

1738-
echo " Clearing terminal pane..."
1739-
tmux send-keys -t "$SESSION_NAME:$window_name.$p_terminal" "clear" C-m
1689+
# Kill existing window if it exists (to recreate full layout)
1690+
local current_window=$(tmux display-message -p '#{window_name}' 2>/dev/null)
1691+
if tmux list-windows -t "$SESSION_NAME" -F "#{window_name}" 2>/dev/null | grep -q "^$window_name$"; then
1692+
echo " Killing existing window to recreate layout..."
1693+
tmux kill-window -t "$SESSION_NAME:$window_name" 2>/dev/null || true
1694+
elif [[ "$(pwd)" == "$dir"* ]] && [ -n "$current_window" ]; then
1695+
# We're in the workspace dir but window has different name - kill current
1696+
echo " Killing current window to recreate layout..."
1697+
tmux kill-window -t "$SESSION_NAME:$current_window" 2>/dev/null || true
1698+
fi
17401699

1741-
echo " Restarting server pane..."
1742-
tmux respawn-pane -k -t "$SESSION_NAME:$window_name.$p_server" -c "$dir"
1743-
sleep 0.5
1744-
[ -n "$dev_cmd" ] && tmux send-keys -t "$SESSION_NAME:$window_name.$p_server" "clear && $dev_cmd" C-m
1700+
sleep 0.3
17451701

1746-
echo " Restarting main pane..."
1747-
tmux respawn-pane -k -t "$SESSION_NAME:$window_name.$p_main" -c "$dir"
1748-
sleep 0.5
1749-
[ -n "$claude_cmd" ] && tmux send-keys -t "$SESSION_NAME:$window_name.$p_main" "clear && $claude_cmd" C-m
1702+
echo " Recreating workspace layout..."
1703+
create_workspace_layout "$window_name" "$dir" "$dev_cmd" "$claude_cmd" "$port_msg" "add"
17501704

17511705
# Record mood event
17521706
mood_record_event "restart" "workspace $num"
17531707

1754-
success "Workspace $num restarted!"
1755-
else
1756-
echo -e "${YELLOW} Window 'ws$num' not found and not in workspace dir${NC}"
1757-
fi
1708+
success "Workspace $num restarted with fresh layout!"
1709+
tmux select-window -t "$SESSION_NAME:$window_name"
17581710
else
17591711
echo -e "${YELLOW} Not in tmux session - run 'crabcode $num' to start${NC}"
17601712
fi
@@ -6155,9 +6107,7 @@ show_cheat() {
61556107
║ crab ws new Create next available workspace ║
61566108
║ crab ws <N> Open/create workspace N ║
61576109
║ crab ws <N> --separate Open in new terminal window ║
6158-
║ crab ws <N> --team Start with agent team (Claude spawns teammates) ║
6159-
║ crab ws <N> -t "prompt" Start team with custom prompt ║
6160-
║ crab ws <N> restart Reset git + restart panes ║
6110+
║ crab ws <N> restart Reset git + restart panes (recreates full layout) ║
61616111
║ crab ws <N> cleanup Kill window + reset to origin/main ║
61626112
║ crab ws <N> destroy Completely remove workspace (worktree + files) ║
61636113
║ crab destroy <N> Shorthand for above ║
@@ -6293,11 +6243,10 @@ show_help() {
62936243
echo " ws List all workspaces"
62946244
echo " ws new Create next available workspace"
62956245
echo " ws <N> Open/create workspace N"
6296-
echo " ws <N> restart Reset git + restart panes"
6246+
echo " ws <N> restart Reset git + restart panes (recreates layout)"
62976247
echo " ws <N> cleanup Kill window + reset to origin/main"
62986248
echo " ws <N> continue Resume with --continue flag"
62996249
echo " ws <N> --separate Open in new terminal window"
6300-
echo " ws <N> --team Start with agent team"
63016250
echo ""
63026251
echo "Shortcuts (auto-detect workspace):"
63036252
echo " <N> Shorthand for: ws <N>"
@@ -6360,28 +6309,6 @@ handle_ws_command() {
63606309
*)
63616310
if [[ "$arg" =~ ^[0-9]+$ ]]; then
63626311
local num="$arg"
6363-
local team_prompt=""
6364-
6365-
# Parse remaining args for --team flag
6366-
local remaining_args=()
6367-
while [ $# -gt 0 ]; do
6368-
case "$1" in
6369-
--team|-t)
6370-
if [ -n "${2:-}" ] && [[ "${2:-}" != -* ]]; then
6371-
team_prompt="$2"
6372-
shift 2
6373-
else
6374-
team_prompt="$DEFAULT_TEAM_PROMPT"
6375-
shift
6376-
fi
6377-
;;
6378-
*)
6379-
remaining_args+=("$1")
6380-
shift
6381-
;;
6382-
esac
6383-
done
6384-
set -- "${remaining_args[@]}"
63856312

63866313
case "${1:-}" in
63876314
"cleanup"|"clean")
@@ -6403,16 +6330,11 @@ handle_ws_command() {
64036330
handle_wip_for_workspace "$num" "${@:2}"
64046331
;;
64056332
"")
6406-
if [ -n "$team_prompt" ]; then
6407-
TEAM_PROMPT="$team_prompt"
6408-
open_workspace "$num"
6409-
else
6410-
open_workspace "$num"
6411-
fi
6333+
open_workspace "$num"
64126334
;;
64136335
*)
64146336
error "Unknown command: crab ws $num $1"
6415-
echo "Try: crab ws $num restart|cleanup|continue|wip|--team"
6337+
echo "Try: crab ws $num restart|cleanup|continue|wip"
64166338
exit 1
64176339
;;
64186340
esac

0 commit comments

Comments
 (0)