You use /scid or /scon to perform the command on the appropriate connection..

Here is a simple alias to find the CID of a particular network.
Code:
alias n-cid var %a | scon -a if $1 == $!network $eval({ var %a = $cid },0) | return %a

Example...
  • scid $n_cid(Undernet)
    mode #chanA o Zyzzyx26


Here is the same alias except this finds the CID by server name
Code:
alias s-cid var %a | scon -a if $1 == $!server $eval({ var %a = $cid },0) | return %a