In 2018, Hammer co-starred in Boots Riley's dark comedy Sorry to Bother You alongside Lakeith Stanfield, Steven Yeun, and Tessa Thompson. The film premiered at the Sundance Film Festival in January 20. The film won The 2019 National Board of Review's Top Ten Independent Films award. It also won Best Screenplay and Best First Feature at the 2019 Independent Spirit Awards. He then appeared as David in the thriller Hotel Mumbai, about the 2008 Mumbai attacks. The film had its world premiere at the Toronto International Film Festival on September 7, 2018. In the same year, Hammer starred alongside Felicity Jones, playing taxation law expert Martin D. Ginsburg, the spouse of Supreme Court Justice Ruth Bader Ginsburg, in On the Basis of Sex, a biographical legal drama film based on the life and early cases of Supreme Court Justice Ruth Bader Ginsburg, directed by Mimi Leder. It had its world premiere at the AFI Fest on November 8, 2018. In June 2018, Hammer led as Drew in Straight White Men at Second Stage Theater on Broadway.