Pesto after doing a sauce or before?
Put the pesto in just as the sauce is done and as you're taking it off the heat. Generally, pesto does not benefit at all from cooking. By adding it to the sauce just as it is being pulled from the heat, it's temp will equalize with the sauce, without being cooked.

Are you planning to serve this over pasta? If so, drain the pasta (save some of the pasta water) while the pasta is still quite al-dente. Simmer and stir the pasta in the sauce for a minute or so. If it needs a bit of thinning out, add reserved pasta water. Only when it feels about ready to serve, add the pesto, again just as you remove it all from the heat.

If you are planning on cooking the pasta for a while in the sauce, as in soup, I encourage you to reconsider. I recommend that you make the sauce awesome. When the sauce just seems right, boil your pasta until al-dente (don't forget to salt). Add the pasta to the sauce, slowly, not too much, not too little. Use the reserved pasta water to get just the right consistency. Let it all simmer for a minute or two, let the pasta soak up the flavor. THEN, when it all looks great, add the pesto, stir, turn off the heat, and serve.