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 modeclaudep
- 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.