Let A be an arbitrary alphabet and let θ be an (anti-)automorphism of A * (by definition, such a correspondence is determinated by a permutation of the alphabet). This paper deals with sets which are invariant under θ (θ-invariant for short) that is, languages L satisfying θ(L) ⊆ L. We establish an extension of the famous defect theorem. With regard to the socalled notion of completeness, we provide a series of examples of finite complete θ-invariant codes. Moreover, we establish a formula which allows to embed any non-complete θ-invariant code into a complete one. As a consequence, in the family of the so-called thin θ-invariant codes, maximality and completeness are two equivalent notions. collection of unknown words, say Z. We assume that a (minimum) positive integer k (i.e. the so-called order of θ) exists such that θ k = id A * . This condition is particularly satisfied by every (anti-)automorphism whenever A is finite. In view of making the present forward more easily readable, in the first instance let us take θ as an involutive (anti-)automorphism (that is, θ 2 = id A * ). We assign that the words in Z and their images by θ to satisfy a given equation, and we ask for the computation of a finite set of words, say Y , such that all the words of Z can be expressed as a concatenation of words in Y . Actually, such a question appears more complex than in the classical configuration, where θ does not interfer: in this classical case, according to the famous defect theorem [18, Theorem 1.2.5], it is well known that at most |Z| − 1 words allow to compute the words in Z. At the contrary, due to the interference of (anti-)automorphisms, in [16], examples where |Y | = |Z| are provided by the authors.Along the way, for solving our problem, applying the defect theorem to the set X = Z ∪ θ(Z) might appear natural. Such a methodology garantees the existence of a set Y , with |Y | ≤ |X| − 1 and whose elements allow by concatenation to rebuild all the words in X. It is also well known that Y can be chosen in such a way that only trivial equations may hold among its elements: with the terminology of [1,18,19], Y is a code, or equivalently Y * , the submonoid that it generates, is free. Unfortunately, since both the words in Z and θ(Z) are expressed as concatenations of words in Y , among the words of Y ∪ θ(Y ) non-trivial equations can still hold. In other words, by applying that methodology, the initial problem would be transferred among the words in Y ∪ θ(Y ).An alternative methodology will consist in asking for codes Y which are invariant under θ (θ-invariant for short) that is, satisfying θ(Y ) = Y . Returning to the general case, where θ is an arbitrary (anti-)automorphism, this is equivalent to say that the union of the sets θ i (Y ), for all i ∈ Z, is θ-invariant. By the way, it is straightforward to show that the intersection of an arbitrary family of free θ-invariant submonoids is itself a free θ-invariant submonoid. In the present paper we prove the following result: