Is an exhaust fan required by code in a new basement half-bath?
I can't say for sure about code - it varies a lot by location. But generally either code requires or it is a good idea to have:


An exhaust fan
or
An operable window on an outer wall


so that you can vent hot/moist air, chemical fumes from cleaning, etc. A half-bath (normally that means no tub or shower) will not have as great a need for ventilation as a full bath, but it still needs a fan or window.

If you install an exhaust fan, you must vent it to the outside. If you vent it into an attic or other unfinished space then you will eventually get some combination of mold, mildew, damage to insulation, damage to wood and other problems. Venting to the outside is easiest if you can basically go "up" and put a hole (properly caulked/sealed) in the roof, but venting off to the side is acceptable. The total length of the ductwork can be an issue - check the specs on the fan for more information.

There is quite a variety of exhaust fans available, but the biggest criteria to consider are noise (typically measured in either sones or decibels) and speed (typically measured in CFM). You generally want the quietest fan you can afford that has at least the minimum speed for your bathroom - which will depend on the size of the bathroom.