We introduce the optimization-based method for the design of thermo-mechanical metamaterials and, particularly, for the elastostatic cloaking under thermal loads. It consists of solving a large-scale, nonlinear constrained optimization problem, where the objective function is the error in the cloaking task accomplishment. The design variables define the required metamaterial distribution. In this way, the cloaking task is accomplished, if not exactly, optimally. Further, the design variables dictate how to fabricate the metamaterial, avoiding the uncertainty of simultaneously mimicking several thermal and mechanical effective properties, as required by transformation-based metamaterial design methods.