  Alahmadi et al. ["Twisted centralizer codes", \emph{Linear Algebra and its
Applications} {\bf 524} (2017) 235-249.] introduced the notion of twisted
centralizer codes, $\mathcal{C}_{\mathbb{F}_q}(A,\gamma),$ defined as \[
\mathcal{C}_{\mathbb{F}_q}(A,\gamma)=\lbrace X \in \mathbb{F}_q^{n \times n}:~\
AX=\gamma XA\rbrace, \] for $A \in \mathbb{F}_q^{n \times n},$ and $\gamma \in
\mathbb{F}_q.$ Moreover, Alahmadi et al. ["On the dimension of twisted
centralizer codes", \emph{Finite Fields and Their Applications} {\bf 48} (2017)
43-59.] also investigated the dimension of such codes and obtained upper and
lower bounds for the dimension, and the exact value of the dimension only for
cyclic or diagonalizable matrices $A.$ Generalizing and sharpening Alahmadi et
al.'s results, in this paper, we determine the exact value of the dimension as
well as provide an algorithm to construct an explicit basis of the codes for
any given matrix $A.$
