When should a shareholder agreement be signed?

Ideally, a shareholder agreement should be executed at the time of incorporation or prior to the issuance of equity to new shareholders.