Dazu habe ich folgendes gemacht:
    \documentclass{book}
    \usepackage{xparse,tocloft,listings}
    \newcommand{\codelist}{Codelist}
    \newlistof{code}{cod}{\codelist}
    \NewDocumentEnvironment{code}{m}
    {
            \begin{lstlisting}
            \refstepcounter{code}
            \addcontentsline{cod}{code}
            {\protect\numberline{\thechapter.\thecode}#1}\par
    }
    {\caption{#1}\end{lstlisting}}
    \begin{document}
    \begin{code}{Caption}
    Some Code
    \end{code}
    \listofcode
    \end{document}
Jemand ne Idee?! Missing \endcsname inserted.
<to be read again>
\global
l.17 \begin{code}{Caption}

