Macro: A macro to more easily distinguish Claude Code sessions

Yes, this is a post about AI, though there's no AI involved in the macro itself :). I have been using Claude Code to tackle some personal projects I've long wanted to do but lacked the expertise to build (a database to track the shows I'm watching or want to watch with a web front end, and a system to retrieve character information for books, movies, and TV series, to name just two).

As a (mostly) non-coder, claude has impressed me with what it has allowed me to do, but that's not the point of this post. When you work in claude, you use a Terminal window. And you can open many projects in many windows, all of which soon start to look the same. I have, more than once, asked for changes in Project A when I should have been changing Project B.

claude offers a way to make the sessions more distinctive, by renaming the workspace and assigning it a color, but both are "post start" tasks. I wanted to always set certain projects to certain names and colors. And that's all the first version of this macro did.

Update: I've uploaded a new version of the macro. Now it can optionally use a custom Terminal profile, and it (optionally) sets background colors in those Terminal windows to match the specified highlight colors. It also has a greatly-improved launcher, and I removed the Found Image action, so you need edit only one variable to use the macro.

Update 2: The code now uses @Nige_S' brilliant idea to check for the input prompt via AppleScript; this gets rid of any need to guess a delay. I also added a progress bar, so you can tell for sure when it's ready. Thanks, @Nige_S!

Here's how three of my projects look with this version of the macro:

The macro automates the whole process: You select a project from a list, and the macro opens a Terminal window, activates the custom profile, changes the background color, moves to the proper project folder, launches claude, and then renames the workspace and sets the color highlight once claude is open.

The new demo macro is fully functional, and lets you open Claude Code in your Desktop, Documents, or Downloads folders, just so you can see how it works.

Download Macro(s): Claude Code projects - Generic.kmmacros (18 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 15.7.5
  • Keyboard Maestro v11.0.4

To use this for real Claude Code projects, replace the text in the purple local_myApps variable action with the name, path, and color choice for each of your projects. To disable the custom colors and custom Terminal profile, just change those variable' values from TRUE to FALSE.

There's a delay near the end of the macro, colored red and set to three seconds. You may need to increase this to allow Claude to be ready before you send the commands that change the workspace name and prompt color.

This isn't a huge thing, but it saves me from having to remember to run two commands whenever I launch claude. Adding new projects is easyβ€”it's just another row in local_myApps, with name, path, and color choice. I press my chosen hot key, pick my project, and off it goes.

And yes, I know I should be learning to code instead of relying on AI, but as they said in many a movie over the years, "I'm getting too old for this s....". claude helps turn my "I'd love to..." ideas into reality.

-rob.

3 Likes

I have been experiencing this problem! I didn’t know about the workspace naming/color feature. Thanks for telling me about it and making it easier to use!

The first post now has a much-improved version of the macro, one that will (optionally) use a custom Terminal profile and (optionally) color Terminal background windows, as seen in the screenshot in the first post.

It also has much better launcher logic (only one variable to modify), and I removed the Found Image action, which wasn't reliable anywayβ€”it turns out that sometimes the image gets munged if Claude Code is parsing long startup files. So now activation is strictly delay-based (the red action near the end of the macro).

With a custom Terminal (I changed the window title, size, and cursor), and background colors to match my prompt color, it's now super easy to distinguish my projects from one another.

-rob.

What's happening during that time? Might you be able to leverage Terminal's busy AS term?

tab n : A tab.
...
properties
...
busy (boolean, r/o) : Whether the tab is busy running a process.

Ignore all that - I'm a buffoon :). Unfortunately, the busy property returns TRUE as soon as Claude Code launches, and stays TRUE while it's running.

-rob.

1 Like

Shame, but I feared that might be the case...

Do you instead end up at a prompt of some kind? If so you could use contents, grabbing the last line and parsing that for the prompt.

Bingo! That worked. The prompt is drawn in a very distinctive style:

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯  

So by checking for that in the output of the contents AppleScript, it appears to work predictably and reliably. I'll test a bit more before updating the macro, though.

Update: I've replaced the macro in the first post with the new version that uses the AppleScript solution. It's working very well here.

Thanks!
-rob.

1 Like