I have a Sage Dual Boiler coffee machine, using the stock portafilter and baskets. Should I tamp the coffee in the basket and then insert into the portafilter, or insert the basket first into portafilter and then tamp?
My rule of thumb is to tamp after inserting the basket into the portafilter for one main reason; after the tamp, I want the coffee puck to remain as undisturbed as possible before pulling the shot. If you have already inserted the basket in the portafilter then dose and tamp, the only required action after tamping is inserting it into the machine's group head. If on the other hand, you dose and tamp into the basket first, then you have to next insert the basket into the portafilter which has the chance to deform the puck (you do have to exert a bit of pressure to insert the basket into the portafilter!). This just becomes yet another variable you must control for to gain repeat-ability in your preparation process, and great espresso is all about process.
I am unaware if this specific machine has specific requirements. If this is the case, please mention.
I mostly prefer to tamp the coffee after I put it in the portafilter. It's harder to carry the basket with coffee in it. Also it's harder to tamp the basket without easily holding it in place.