Skip to content

Instantly share code, notes, and snippets.

@olinguyen
Created January 8, 2026 15:03
Show Gist options
  • Select an option

  • Save olinguyen/f7dadc644b9f47012d2a7f79beef553a to your computer and use it in GitHub Desktop.

Select an option

Save olinguyen/f7dadc644b9f47012d2a7f79beef553a to your computer and use it in GitHub Desktop.
Custom Claude Code File Suggestion
#!/bin/bash
# {
# "fileSuggestion": {
# "type": "command",
# "command": ".claude/file-suggestion.sh"
# }
# }
query=$(cat | jq -r '.query')
cd "$CLAUDE_PROJECT_DIR" && fd -t f -p "$query" . | sed 's|^\./||' | head -15
@dir
Copy link
Copy Markdown

dir commented Mar 26, 2026

Stumbled upon this earlier this evening, wanted to give you a heads up that you can simplify this script a ton using fd's built-in options.

You can replace:

  • cd "$CLAUDE_PROJECT_DIR" with the -C|--base-directory <path> option
  • sed 's|^\./||' with the fd option --strip-cwd-prefix=always
  • head -15 with the fd option --max-results=15

Putting it all together:

#!/bin/bash

query=$(cat | jq -r '.query')
fd -t f -p \
    --strip-cwd-prefix=always \
    --max-results=15 \
    -C "$CLAUDE_PROJECT_DIR" \
    "$query"

It is worth mentioning that with these changes, fd is no longer being piped into another command, so still outputs with color/decorations. Depending on how Claude Code calls this bash script, that could cause issues (but it's unlikely). If it does though, they can be disabled with options as well (--color=never, --hyperlink=never).

@olinguyen
Copy link
Copy Markdown
Author

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment