Skip to content

Instantly share code, notes, and snippets.

@popstas
Created February 7, 2026 15:19
Show Gist options
  • Select an option

  • Save popstas/05ffc5461add112bb33dfeb684475283 to your computer and use it in GitHub Desktop.

Select an option

Save popstas/05ffc5461add112bb33dfeb684475283 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# agents2claude
# Walks the current directory tree, respects .gitignore, finds AGENTS.md (via fdfind),
# and creates sibling symlinks: CLAUDE.md -> AGENTS.md
# requires fdfind
set -euo pipefail
created=0
skipped=0
updated=0
errors=0
agents_files=()
mapfile -d '' -t agents_files < <(fdfind -t f -p -0 '\/AGENTS\.md$' .)
# -t f : files only
# -p : full path
# -0 : NUL-delimited output (safe for spaces/newlines)
for agents_file in "${agents_files[@]}"; do
dir="$(dirname "$agents_file")"
link_path="$dir/CLAUDE.md"
if [[ -e "$link_path" || -L "$link_path" ]]; then
if [[ -L "$link_path" ]]; then
target="$(readlink "$link_path" || true)"
if [[ "$target" == "AGENTS.md" || "$target" == "./AGENTS.md" ]]; then
((skipped+=1))
continue
fi
rm -f "$link_path"
ln -s "./AGENTS.md" "$link_path"
((updated+=1))
continue
fi
echo "WARN: skipped, non-symlink already exists: $link_path" >&2
((errors+=1))
continue
fi
ln -s "./AGENTS.md" "$link_path"
((created+=1))
done
echo "Done:"
echo " Created: $created"
echo " Updated: $updated"
echo " Skipped: $skipped"
echo " Errors: $errors"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment