Godsmark - on loan from Newcastle - drilled the ball past Charlton goalkeeper Rob Elliot into the roof of the net from close range.
Hereford had the better of the first-half exchanges with winger Marc Pugh opening up the Charlton defence with a series of attacks from the left flank.
Pugh, who scored two goals against Morecambe in Hereford's opening fixture on Saturday, also drilled a shot against the Charlton post.
Charlton striker Andy Gray should have put the Londoners in front midway through the half but he headed wide with the goal met at his mercy.
Gray's strike partner Izale McLeod also had a shot turned away for a corner from Hereford keeper Adam Bartlett.
Winger Pugh had another chance early in the second period when he shot wide from close range but Charlton should have taken the lead in the 62nd minute when goalkeeper Bartlett saved a penalty from Gray after the striker had been brought down by Richard Rose.
Play continued to switch from end to end but it was Hereford who broke the deadlock eight minutes into extra time when Godsmark snatched the winner.