If $M$ is a finitely generated module over a local ring $(R, \mathfrak{m})$, we can detect whether $M$ has a nonzero free direct summand as follows: Consider the natural map
$$\phi\_M\colon \mathrm{Hom}\_R(M,\mathfrak{m}) \longrightarrow \mathrm{Hom}\_R(M,R)$$
induced by the inclusion of $\mathfrak m$ into $R$. Then $M$ has a nonzero free direct summand if and only if $\\phi\_m$ is not surjective. (If $M$ has no free direct summand, then the image of every homomorphism $M \longrightarrow R$ must be inside $\mathfrak m$, so $\phi\_M$ is surjective. The converse is easy as well.)


I'd like a more precise statement to be true. The cokernel of $\phi\_M$ is a submodule of $\mathrm{Hom}\_R(M,R/\mathfrak{m})$, so is a finite-dimensional vector space. 



> 
> Is the maximal rank of a free direct summand of $M$ equal to the dimension of $\mathrm{coker} \;\phi\_M$?
> 
> 
> 


One inequality is obvious -- a surjection $M \longrightarrow R^r$ will give a subspace of dimension $r$.



Detecting and counting free direct summands
If $F$ is a free direct summand of $M$ of maximal rank, then $M=F\oplus N$, where $N$ has no free direct summand. So $\mathrm{coker} \;\phi\_M\cong\mathrm{coker} \;\phi\_F\oplus\mathrm{coker} \;\phi\_N$, and, as you've pointed out, the dimension of $\mathrm{coker} \;\phi\_F$ is the rank of $F$ and $\mathrm{coker} \;\phi\_N=0$.


