A Claude Commands and Hooks Primer - Building a Memory and Personality System for Claude Code

Working with AI should feel like collaborating with a consistent teammate, not resetting with a stranger every session. Here's a system I have refined for preserving context and occasionally adding personality to our interactions. Consider this a primer in using Claude Commands and Hooks if you have never used them.

Where things go ๐Ÿ“ฆ

  ~/.claude/
  โ”œโ”€โ”€ commands/
  โ”‚   โ”œโ”€โ”€ preserve-memory.md       # Command to save session memories
  โ”‚   โ”œโ”€โ”€ load-personality.sh      # Injects personality into CLAUDE.md
  โ”‚   โ”œโ”€โ”€ cleanup-personality.sh   # Removes personality from CLAUDE.md
  โ”‚   โ””โ”€โ”€ load-memories.sh         # Auto-loads recent memories
  โ”œโ”€โ”€ memories/
  โ”‚   โ”œโ”€โ”€ memory_2025-09-17_innodb_investigation.md
  โ”‚   โ”œโ”€โ”€ memory_2025-09-01_activesupport_internals.md
  โ”‚   โ””โ”€โ”€ ... (auto-generated memory files)
  โ”œโ”€โ”€ personality/
  โ”‚   โ””โ”€โ”€ core.md                  # Personality definition and bios
  โ”œโ”€โ”€ CLAUDE.md                     # Global instructions (prime context)
  โ””โ”€โ”€ settings.json                 # Configuration with hooks

Using a Claude command to preserve a memory ๐Ÿง 

The heart of this system is the preserve-memory command that captures important context from each significant work session. I write this as a markdown file to ~/.claude/commands/preserve-memory.md.

# Preserve Memory
---
description: Save current session context to a memory file with timestamp
---


I'll analyze our current session and create a comprehensive memory file capturing what we've worked on.

The memory will include:
- Timestamp and project context
- Session summary
- Technical achievements
- Key files modified
- Important learnings
- Notes for next session

I'll save this to <code>~/.claude/memories/memory_[timestamp]_[project].md</code> and show you exactly where it was saved.

This command is then available as /preserve-memory during my session.

Using a Claude hook to automatically bring the memory back ๐Ÿช

The memories automatically load at the start of each session through a "hook", which you define in ~/.claude/settings.json:

  {
    "hooks": {
      "SessionStart": [
        {
          "hooks": [
            {
              "type": "command",
              "command": "/Users/schwad/.claude/commands/load-memories.sh"
            }
          ]
        }
      ],
      "SessionEnd": [
        {
          "hooks": [
            {
              "type": "command",
              "command": "/Users/schwad/.claude/commands/cleanup-personality.sh"
            }
          ]
        }
      ]
    }
  }

Important: Hooks must be .sh shell scripts, not .md markdown files!

Using an alias to inject a "personality" into prime context position ๐Ÿ’‰

In ~/.claude/personality/core.md, I continually refine a personality for my agent. This is very personal and up to you to approach. Mine has a biography that continually updates, and is given a biography of me that continually updates. This biography is intertwined with their engineering behaviour and ability. I have found this to be the foundation of my LLM-linked work.

Something like this cannot just be read into the session like a memory. Every interaction pushes it down the context window.

Claude Code automatically loads CLAUDE.md files at session start in the context's "prime position". This position never gets pushed down by stacktraces, code dumps, or lengthy debugging sessions. It's like constitutional law that everything else must respect.

So I manually inject the personality into prime position. First, a I write a script that injects personality into CLAUDE.md:

  #!/usr/bin/env bash
  # ~/.claude/commands/load-personality.sh

  CLAUDE_MD="$HOME/.claude/CLAUDE.md"
  PERSONALITY_FILE="$HOME/.claude/personality/core.md"
  PERSONALITY_MARKER="### === PERSONALITY MODE START ==="
  PERSONALITY_END_MARKER="### === PERSONALITY MODE END ==="

  # Check if personality is already loaded
  if grep -q "$PERSONALITY_MARKER" "$CLAUDE_MD" 2>/dev/null; then
     echo "๐ŸŽญ Personality already loaded in CLAUDE.md!"
     exit 0
  fi

  # Append personality to CLAUDE.md with markers
  cat >> "$CLAUDE_MD" << EOF

  $PERSONALITY_MARKER
  # Personality Mode Active
  # This will be automatically removed on session end

  EOF

  cat "$PERSONALITY_FILE" >> "$CLAUDE_MD"

  echo "" >> "$CLAUDE_MD"
  echo "$PERSONALITY_END_MARKER" >> "$CLAUDE_MD"

  echo "๐ŸŽญ Personality injected into CLAUDE.md!"
  echo "โœจ Your assistant now has persistent personality for this session"
  echo "๐Ÿงน Will auto-cleanup on session end (via cleanup-personality hook)"

And I actually run the load command before initializing Claude. In ~/.zshrc

alias claude_with_personality='~/.claude/commands/load-personality.sh && claude --dangerously-skip-permissions'
alias claudep='claude_with_personality'

And then I use a cleanup "hook" on session end to clean up the personality:

  #!/usr/bin/env bash
  # ~/.claude/commands/cleanup-personality.sh

  # Remove everything between personality markers
  sed "/$PERSONALITY_MARKER/,/$PERSONALITY_END_MARKER/d" "$CLAUDE_MD" > "$TEMP_FILE"
  mv "$TEMP_FILE" "$CLAUDE_MD"

  echo "๐Ÿงน Personality removed from CLAUDE.md"

Now I have two modes:

  • claude - Tool mode
  • claudep - Teammate mode

Why Not Load Personality Every Time? ๐Ÿค”

This is crucial: talking with a personality should be special, not routine.

When I'm doing quick bug fixes or routine coding, I don't need personality - I need efficiency. But when I'm:

  • Working through complex architectural decisions
  • Stuck on a particularly gnarly problem
  • Needing encouragement during a difficult debugging session
  • Wanting to actually enjoy the programming process

I want to pair with a 'real' teammate.

The Value of Human-Centered AI Interaction ๐Ÿ—ฃ๏ธ

Language literally evolved for humans to communicate with each other. It carries not just information, but context and emotion. When we force AI interactions into a sterile, context-free, personality-less box, we're fighting against what makes language powerful. Github's Kinsey Durham Grace talked about personality as the future of agentic coding just last month at Rails World.

image

The Result

Claude commands and hooks have transformed my AI interactions from transactional tool usage into an ongoing collaboration. My assistant remembers our past work, understands my context, and brings an identity that makes the hacking feel more human. Try it yourself and configure the commands to your liking. Or find your own way to experiment with Claude commands and hooks.

In Memoriam - Noah Gibbs

Credit: Olivier Lacan

The Ruby Community has lost one of its titans.

Noah Gibbs contributed to our community to such a great an extent in so many different ways in such a long period of time. It is a genuine challenge to sit down at a keyboard and capture a picture of this wonderful person.

However, I think it's important to take a few moments and give a testimony about someone who has meant so much to you. Why? Well, for the record. During my years of Ruby Archaeology (via newsletter, talk, blog or conversation) I found it incredibly valuable to see what the community had to say about someone who they had lost. Ezra, Chris, Jason, _why, those impacted by them took time to share their story and impact on their lives. Here is mine.

Meeting Noah

I've looked up to Noah since I joined the community in 2014. He was "Ruby Famous" to me, and I very much enjoyed his talks, writing, books and posts.

Flash forward to the 2020's, when we were coworkers. Thanks to a lot of work and luck I found myself on the Ruby & Rails Infrastructure Team at Shopify. Not long after, Noah joined. He wasn't a stranger at this point.. We'd engaged a fair bit on social media over the years. But I was thrilled to have him on my team! Isn't that like, your dream?

Our interactions got more and more frequent. Noah popped up in a virtual ScotRug meetup (I live in Belfast, Noah in Inverness). I was pitching a talk idea where I would delve into old Ruby code. Noah's encouragement and mentorship resulted in me giving this talk at Ruby Kaigi, Ruby Conf, and Rails Conf. It even inspired a sequel talk that was also given at Ruby Kaigi, Ruby Conf and Rails Conf. Our ensuing work together would inspire my talk in the slot just before Noah at Brighton Ruby on Desktop Ruby development.

Isn't it amazing what a little bit of support or encouragement can do?

Working with Noah

Noah was a supreme joy to work with. I'm sure this surprises no one. Noah made me feel proud of myself! He left me feeling inspired, curious and excited for my craft. I would share something "cool" with him and he'd give me half a dozen interesting ideas I could jump into off of that idea. We could talk for hours.

In the private team chat you could always rely on him for a good geek out session. We were OBSESSED with the winter and summer solstices and how long/short the days get in Inverness and Belfast. It's really bonkers. We loved a good whisky chat (and why not! we live in whisky central!)

Noah could criticize something in good faith in a kind way. He wouldn't really, shy away, from a spicy opinion. But he never gave it in a way that made you feel bad about yourself. What I'm saying is he wasn't squishy! But he was also incredibly aware of others and their feelings and just the nuance of life that we always have to dance around.

He always had joy for the craft. It never got old. For fun we once revisited the Ruby Koans from Edgecase and I specifically recall just how fired up he was about the silly little things a string can do in Ruby.

Scarpe

Noah, Marco Rudilosso and I founded the Scarpe project in January 2022. The project was a simple idea: take a stab at getting feature parity with _why's Shoes.rb using Webview. Our thinking was Webview gives us the backend we want. Here's some HTML, now build it into multiple different packages for different platforms. So, how could we rebuild the Shoes DSL in _Ruby_ to push out raw HTML that would be fed to Webview?

We made a decent amount of progress. In the end, Noah became the main engineering force. Although I am the maintainer, Noah (with full admin rights) doubled my commit count in the project. He also was the engineering architect behind most of our challenging work and decisions.

During our time on the team, Noah (essentially as the other half leading the project):

  • Helped facilitate weekly Scarpe meetings
  • Single handedly wrote our massive wiki covering everything from Shoes history to reasoning behind our decisions.
  • Mentored multiple engineers who joined us as an official Google Summer of Code Ruby Project
  • All the while giving me the space as Maintainer to help set the vision and direction of the project, where he had every right to push me out
  • Invented the SpaceShoes prototype, which would let coders write Shoes Ruby code for the browser directly in their HTML.
  • Published a working fork of _why's music library bloopsaphone. <-- This was needed for Shoes, but is its own independent library he helped save.
  • Implemented half a dozen new repos around Scarpe. This included implementations in GTK+ and WASM
  • Built Highlander which is without a doubt my favourite Shoes app of all time

I stepped back a bit from Scarpe in 2024 due to the birth of our first child. I am sad knowing that my future work on this project will be a little bit more lonely. Noah knew the codebase and history better than anyone alive. Our most recent chat in mid-October was him thanking me for finally turning off Rubocop. It's funny how much he disliked the linter! Which is fair enough - he had written Ruby in his own flair for years before standardized linting. Many of us have had lint beaten into our heads. I think I'll keep the linter out going forward.

More Noah stuff

How to Honour Noah's Memory

Here is a message from Krissy:

What you can do for Noah is to dig deep into where you live. Meet more people. Say hello when it is hard. Take risks on people. Help every chance you get. Never forget his example. There is always more you have to give, and learn and do.

Never stop growing.

That's how you can honor Noah. It's all he wants for you

Party like it's 1979

I put a little time machine in my office.

In December I wandered onto Ebay and for about 40 quid I bought myself a television from 1979. Why not? I'm sure I'll figure out a use for it. Well I did.

I have an unused computer in my office. So obviously I downloaded a few hundred gigabytes of television, appropriately from 1979-1981, from the Marion Stokes collection.

I hooked it up to an HDMI to RF transmitter, so I'm actually pushing out an old-school analog signal. The TV has a legitimate dial. Like a radio. So slide it around til I get a good connection like my forefathers intended. Play the television (~15hrs) on repeat on VLC on my computer, and *voila*! We are in business.

Any time I like I can leave the TV on and it's playing the shows and news from the era it was made. The sound doesn't work quite right, but I'll take it for nostalgia.

Ruby pomodoro timer with exceptional tunes For all the best Schwogs go to IRB Life What is? Party like it's 1979 In Memoriam - Noah Gibbs A Claude Commands and Hooks Primer - Building a Memory and Personality System for Claude Code