How can I add a custom context menu item on a text selection in the Terminal? When I am using the Terminal, I can select a URL in the text and open a context menu that lets me "Open URL". What I would like to do is customize the behavior of this "Open URL" action or add another alternative action that lets me run a custom bash script that takes the URL as an argument. Is this possible?
AFAIK no, but you can make an new Service with the Automator.app.

And the new service will appear in the "Services" submenu in the context menu.

Assuming than you're familiar with scripting and Automator - if not, enter more details what you want achieve with the URL... (for an example can check: https://apple.stackexchange.com/a/63362/6838)