AbstractThe objective of this paper is to study, by new formal methods, the notion of tree code introduced by Nivat in (Tree Automata and Languages, Elsevier, Amsterdam, 1992, pp. 1–19). In particular, we consider the notion of stability for sets of trees closed under concatenation. This allows us to give a characterization of tree codes which is very close to the algebraic characterization of word codes in terms of free monoids. We further define the stable hull of a set of trees and derive a defect theorem for trees, which generalizes the analogous result for words. As a consequence, we obtain some properties of tree codes having two elements. Moreover, we propose a new algorithm to test whether a finite set of trees is a tree code. The r...