Setting the name of matrix in tikz-cd

The name is already set and can be retrived from the macro \tikzcdmatrixname. To further draw over your tikzcd matrix use execute at end picture.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{cd}
\begin{document}

\begin{tikzcd}[execute at end picture={
    \filldraw[red] (\tikzcdmatrixname-1-1) circle[radius=1pt];
    \filldraw[blue] (\tikzcdmatrixname-1-2) circle[radius=1pt];
    \filldraw[green] (\tikzcdmatrixname-2-1) circle[radius=1pt];
    \filldraw[orange] (\tikzcdmatrixname-2-2) circle[radius=1pt];
  }]
  A \ar[r]\ar[d] & B \ar[d] \\
  C \ar[r]       & D \\
\end{tikzcd}

\end{document}

enter image description here


The author of tikz-cd himself in person (Florêncio Neves) suggested to me to use every matrix/.append style={name=...} (don't forget the append, see Torbjørn T.'s answer here). This way you could name your matrix as you wish.

I also think it's possible to use remember picture and overlay instead of execute at end picture. Here an MWE with both cases:

\documentclass{article}
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}[every matrix/.append style={name=mycd}, 
    execute at end picture={
    \filldraw[red] (mycd-1-1) circle[radius=1pt];
    \filldraw[blue] (mycd-1-2) circle[radius=1pt];
    \filldraw[green] (mycd-2-1) circle[radius=1pt];
    \filldraw[orange] (mycd-2-2) circle[radius=1pt];
    }]
    A \ar[r]\ar[d] & B \ar[d] \\
    C \ar[r]       & D 
\end{tikzcd}%

\begin{tikzcd}[every matrix/.append style={name=mycd}, remember picture]
    A \ar[r]\ar[d] & B \ar[d] \\
    C \ar[r]       & D 
\end{tikzcd}%
\begin{tikzpicture}[overlay, remember picture]
    \filldraw[red] (mycd-1-1) circle[radius=1pt];
    \filldraw[blue] (mycd-1-2) circle[radius=1pt];
    \filldraw[green] (mycd-2-1) circle[radius=1pt];
    \filldraw[orange] (mycd-2-2) circle[radius=1pt];
\end{tikzpicture}
\end{document}

enter image description here