Claude Code: Memory & Personality System Using Commands and Hooks

The author has developed a system to enhance the interaction with AI by preserving context and adding personality, using Claude Commands and Hooks. The system includes commands and scripts stored in specific directories, such as preserving memory, loading personality, and cleaning up personality.

The preserve-memory command captures important context from each significant work session and saves it as a markdown file with a timestamp and project context, session summary, technical achievements, key files modified, important learnings, and notes for the next session.

The memories are automatically loaded at the start of each session through a "hook" defined in settings.json. The personality is injected into the prime context position using an alias that runs a script before initializing Claude. The personality is loaded into CLAUDE.md, which is the global instructions file that never gets pushed down by stacktraces or lengthy debugging sessions.

The system aims to transform AI interactions from transactional tool usage into an ongoing collaboration, where the assistant remembers past work, understands context, and brings an identity that makes the interaction feel more human. The author encourages others to try it and configure the commands to their liking.

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

02 Oct 2025 09:00 AM

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 `~/.claude/memories/memory_[timestamp]_[project].md` 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.

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.