The question is in the title, but here is some background:


I previously asked for a general criterion to decide [which colimits commute with which limits in the category of sets](https://mathoverflow.net/questions/93262/which-colimits-commute-with-which-limits-in-the-category-of-sets) and received encouraging answers: (1) the question is already answered in some form by a [paper of Foltz](http://archive.numdam.org/numdam-bin/fitem?id=DIA_1981__5__A1_0), (2) MO user [Marie Bjerrum](https://mathoverflow.net/users/26360/marie-bjerrum) will soon provide what promise to be simpler to check criteria than Foltz's.


Now I'm curious about a special case of that question: for which categories $J$ do limits of shape $J$ commute with all filtered colimits? Certainly it is well known that finite $J$ satisfy this and it is also true that only filtered colimits commute with all finite limits [1], so one might initially guess that only finite limits commute with all filtered colimits. But this is wrong! For example, if $M$ is a finitely generated monoid (for example $\mathbb{N}$), limits of shape $BM$ commute with all filtered colimits (by $BM$ I just mean $M$ regarded as a one object category) [2]. A very similar argument actually shows that limits of shape $J$ commute with all filtered colimits as long as $J$ is "finitely generated", i.e., there is a finite set $F$ of morphisms such that every morphism in $J$ is a composition of some sequence of morphisms in $F$ (equivalently, there is a finite digraph and a functor from the free category on the digraph to $J$ which is surjective on morphisms). Are those all the $J$? **EDIT:** Answered: no! Since these work, any category with a finitely generated initial subcategory also works, and as Marc Hoyois said in his answer below, Paré proved *that* is all.


That is the end of the question but for the curious here are proofs of [1] and [2]:


[1] Assume colimits of shape $I$ commute with all finite limits in the category of sets. Let $F : J \to I$ be a finite diagram in $I$, we shall show that there is a cocone over it. Consider the functor $G : J^{\mathrm{op}} \times I \to \mathrm{Set}$ given by $G(j,i) = \hom\_I(F(j),i)$. For any $i \in I$, $\lim\_{j \in J^{\mathrm{op}}} G(j,i)$ is the set of cocones over $F$ with vertex $i$. If there were no cocones at all over $F$, $\mathrm{colim}\_{i \in I} \lim\_{j\in J^{\mathrm{op}}} G(j,i)$ would be empty. On the other hand $\mathrm{colim}\_{i \in I} G(j,i) = \{\ast\}$ for any $j$ (because every element $f$ of $\hom\_I(f(j),i)$ gets glued onto $id\_{f(j)}$ by the map $G(j,f)$), so $\lim\_{j\in J^{\mathrm{op}}}\mathrm{colim}\_{i \in I} G(j,i) = \{\ast\}$.


**Bonus mini-question**: Is there a reference for the above result? I think it might be well known unwritten folklore.


[2] Let $F : I \to M\text{-Set}$ be a filtered diagram of sets with an action of the finitely generated monoid $M$. We want to show that $\mathrm{colim} \_{i\in I}\;\mathrm{Fix}(F(i)) = \mathrm{Fix}(\mathrm{colim} \_{i\in I}\; F(i))$ where $\mathrm{Fix}(X) = \{x \in X : x=mx$ for all $m\in M\}$. The canonical map from the LHS to the RHS is clearly injective (the notion of equality for fixed points in the colimit on the left is just that they are equal in the colimit of the underlying sets of the monoids, $F(i)$). If $M$ is generated by the finite set $m\_1, \ldots, m\_r$ we can see the canonical map is also surjective: given an element of the RHS represented by $x \in F(i)$, we know that for each $k=1,\ldots, r$, it is the case that $F(\alpha\_k)(x) = F(\alpha\_k)(m\_k x)$ for some $j\_k$ and some morphism $\alpha\_k :i\to j\_k$. Since $I$ is filtered we can equalize all the $\alpha\_k$, and so for a single $j$ and a single $\alpha : i \to j$ we have that $F(\alpha)(x) = F(\alpha)(m\_k x) = m\_k F(\alpha)(x)$, so that $x$ comes from $F(\alpha)(x)$ in the LHS.



Which limits commute with filtered colimits in the category of sets?
Categories $J$ such that limits of shape $J$ commute with filtered colimits in sets are called L-finite. There are several known characterization of them: see [the nLab page about it](http://ncatlab.org/nlab/show/L-finite+category). The page refers to Robert Paré, *Simply connected limits* ([pdf](http://cms.math.ca/cjm/v42/cjm1990v42.0731-0746.pdf)). In particular, Proposition 7 says:


**A category is L-finite iff it has an initial subcategory which is finitely generated.**


There's always some ambiguity in the term "finite limit" because you can consider the source of a "diagram" to be either a graph or a category. This matters not for the notion of limit because of the free/forgetful adjunction between graphs and categories, but the free category on a finite graph may not be finite; it is however L-finite, as you'd expect. This is a situation where it seems more natural to view diagrams as graph morphisms rather than functors.


