diff --git a/setup b/setup index 9136bef0..9b287b08 100755 --- a/setup +++ b/setup @@ -296,11 +296,12 @@ link_claude_skill_dirs() { rm -f "$target" fi # Create real directory with symlinked SKILL.md (absolute path) - if [ ! -e "$target" ] || [ -d "$target" ]; then - mkdir -p "$target" - ln -snf "$gstack_dir/$dir_name/SKILL.md" "$target/SKILL.md" - linked+=("$link_name") - fi + # Use mkdir -p unconditionally (idempotent) to avoid TOCTOU race + mkdir -p "$target" + # Validate target isn't a symlink before creating the link + if [ -L "$target/SKILL.md" ]; then rm "$target/SKILL.md"; fi + ln -snf "$gstack_dir/$dir_name/SKILL.md" "$target/SKILL.md" + linked+=("$link_name") fi done if [ ${#linked[@]} -gt 0 ]; then