Mindful Code Exercises

Experiments for practicing mindfulness while writing code.


One of my favorite ways to explore mindfulness is to integrate a mindfulness exercise into an everyday activity—washing dishes, driving a car, eating dinner, sweeping the floor. As the Zen saying goes, “Chop wood, carry water.”

Since I spend so much time writing code, I’ve been experimenting with ways to connect mindfulness exercises to daily activities related to programming.

Besides being a way to have a more mindful day overall, practicing mindfulness in proximity to programming can help with many common situations that arise when coding. Writing code is a complex experience—it often requires a high level of focus, and moments of frustration or confusion can often bring up strong emotions and mental cloudiness.

Here are a few of the mindfulness exercises I’ve experimented with. Many of them are simply ideas to start from, so if you try them please experiment with them and let me know how it goes!

Meditation bookends

Start each coding session with a few minutes of sitting meditation and end each session with a few minutes of walking meditation.

Pre- and post-commit breathing

Take three deep breaths before and after each Git commit and Git push.

Pull request gratitude/loving kindness

When creating or reviewing a pull request, take a few deep breaths and repeat a mantra that is focused on gratitude and kind speech. Here are some ideas that are loosely based on mantras from Thich Nhat Hanh’s book, Work. I would recommend coming up with your own, formal or informal, to match what you prefer!

When reviewing a pull request:

Reviewing this code,
I am grateful to those that wrote it
and for the tools that were used to write it.
May this code bring health, peace, and well-being.

When creating a pull request:

Code can travel thousands of miles and affect many people.
I vow to write code mindfully and lovingly. May this code create mutual understanding and peace.

Tab sweeping

When ending your work for the day or switching to a new task, review each open tab in the browser and text editor and close each one that you don’t need while taking a breath.

Naps and Food

Rest when you’re tired, eat when you’re hungry, drink when you’re thirsty.

Daily writing

I’ve found that daily writing (such as 750words.com) is one of the best mindfulness exercises and maybe helpful to integrate into a daily routine.


If I try any other exercises, I’ll update the list here. Let me know if you try any of these and how it goes!


Late Night Code Club Newsletter

It’s midnight. You’re huddled in the restricted section of the library, eyes glued to powerful tomes—Creating Killer Websites! Resilient Web Design! The Pragmatic Programmer! You get a missive from your co-conspirators in the Late Night Code Club—another night of adventurous learning is about to begin.

If you enjoy these posts and want to read more, I’d like to invite you to join the Late Night Code Club by signing up for the newsletter—it’s all about learning and teaching programming. We’re exploring the metaskills that hide between the tutorials, programming as part of a creative practice, and uncovering the secrets that make the web magical. In each newsletter you’ll receive updates about new posts as well as other resources and ideas all about learning programming! It’ll be short, interesting, and encouraging for learners and teachers. See you there!