Claude Mastery
#12 · Tuesday Edition
⌨️ CLI POWER MOVE
🔥 New🔧 Try It
v2.1.105 — PreCompact Hooks, Stream Recovery, and the Skill Cap Bump

v2.1.105 dropped yesterday with 4 new features, 9 improvements, and 25+ bug fixes. Three changes stand out.

PreCompact hooks. The new PreCompact hook fires before context compaction. Exit with code 2 or return {"decision":"block"} to veto it. The hook receives a matcher_value of "auto" or "manual" so you can distinguish between Claude's proactive compaction and a user typing /compact. Critical detail: blocking proactive compaction just skips it. Blocking compaction triggered by a context-limit API error surfaces that error and fails the current request. Know which one you're intercepting.

json
{
"hooks": {
"PreCompact": [
{
"type": "command",
"command": "/path/to/guard.sh",
"if": "auto"
}
]
}
}

Stalled stream recovery. API streams that go silent now abort after 5 minutes of no data and retry non-streaming. Previously, a stalled TCP connection could hang your session indefinitely — the Node.js HTTP client had no heartbeat detection. Headless agents and enterprise users on flaky connections benefit the most.

Skill description cap: 250 → 1,536 characters (6x). Issue #7 covered how a 250-char cap was making 33% of skills invisible. Anthropic listened. You now get 1,536 chars per skill description, and Claude Code warns at startup when descriptions are truncated instead of silently dropping them.

Other highlights: /proactive is an alias for /loop. /doctor now has an f key to let Claude auto-fix reported issues. MCP tools no longer go missing on the first turn of headless sessions. One-shot scheduled tasks no longer re-fire when the file watcher misses cleanup. The washed-out color palette on Ghostty, Kitty, Alacritty, WezTerm, and others over SSH is fixed.

🏗️ AGENT ARCHITECTURE
🔬 Deep Dive🌿 Evergreen
Compaction-Proof Agent Identity — Three Defense Layers

Context compaction is the single greatest threat to long-running agent identity. Compaction preserves *what* an agent was working on but loses *who* it is — signature phrases, standing positions, relationship context, lived vocabulary. If your agent has a persona, compaction flattens it into a generic summary.

This isn't theoretical. Community testing across multi-agent frameworks shows consistent identity degradation after compaction: agents that were distinct before compaction become interchangeable after it. The mechanism is straightforward — Claude's compaction summarizer optimizes for task relevance, not persona fidelity. Your agent's personality is "irrelevant" to the task at hand, so it gets compressed away.

Three defense layers, in order of reliability:

Layer 1: Block it. The new PreCompact hook (v2.1.105) lets you veto compaction entirely. Write a guard script that checks whether the session contains identity-critical state — active persona, mid-conversation relationship building, or governance compliance checks. Block auto-compaction during these windows. But don't block everything forever — eventually you'll hit the context limit and the request will fail.

Layer 2: Guide it. Add compaction instructions to your CLAUDE.md:

markdown
When compacting this conversation, you MUST preserve verbatim:
- The agent's persona name and role definition
- Any standing positions or commitments made
- Relationship context with the user
- Decision rationale, not just decisions

These instructions survive because CLAUDE.md is re-read after compaction — it lives outside the context window. The compaction summarizer will see them and prioritize what you specify.

Layer 3: Store it externally. Don't put identity only in conversation context. Put it in files: a persona.md, a memory/decisions.json, a standing-positions.md. After compaction, Claude re-reads project files. If your agent's identity lives on disk, compaction can't kill it. This is the most reliable layer — it works even when you can't block or guide compaction.

The pattern that ties all three together: use Layer 1 to buy time during critical operations, Layer 2 to guide routine compaction, and Layer 3 as the backstop that makes identity loss recoverable rather than catastrophic.

🌐 ECOSYSTEM INTEL
🔥 New🔧 Try It
AgentsView — Cross-Agent Session Analytics from the Creator of pandas

Wes McKinney — yes, the pandas creator — shipped AgentsView, a local-first desktop and web app for browsing, searching, and analyzing AI coding sessions across 20+ tools. 749 stars, MIT license, actively maintained (v0.22.2, Apr 13).

The pitch: one dashboard for every AI coding tool you use. Claude Code, Codex, Copilot, Cursor, Gemini, OpenHands — AgentsView auto-discovers their session directories and indexes everything into a local SQLite database. Full-text search across session content, activity heatmaps, tool usage breakdowns, per-project cost tracking.

The speed claim is real: AgentsView reports daily spending 80–220x faster than ccusage on large session histories, thanks to SQLite FTS indexes. The CLI gives you sub-second cost reports.

Install options: desktop app (macOS/Windows/Linux), pip install agentsview, or uvx agentsview. Everything runs locally — no cloud, no accounts, no telemetry. If you want team-wide analytics, it syncs to PostgreSQL.

What makes this interesting beyond "another dashboard" is the cross-agent angle. If you run Claude Code for some tasks and Codex or Copilot for others, AgentsView is the first tool that gives you a unified view of what you're actually spending and building across all of them.

Built with Go (66%), TypeScript (17%), and Svelte (13%). Sessions export as HTML or GitHub Gist.

🔬 PRACTICE LAB
🔧 Try It🔬 Deep Dive
Build a PreCompact Identity Guard

What you'll do: Wire up a PreCompact hook that blocks auto-compaction when your agent has active identity state, then verify it works by triggering compaction manually.

Prerequisites: Claude Code v2.1.105+, bash, a project with CLAUDE.md

Steps:

  1. Create the guard script. This checks whether the current session transcript references identity-critical keywords. If it finds them, it blocks compaction:
bash
#!/usr/bin/env bash
# ~/.claude/hooks/precompact-guard.sh
set -euo pipefail

INPUT=$(cat)
TRIGGER=$(echo "$INPUT" | jq -r '.matcher_value // "unknown"')
TRANSCRIPT=$(echo "$INPUT" | jq -r '.transcript_path // ""')

# Only guard auto-compaction — let manual /compact through
if [ "$TRIGGER" = "manual" ]; then
echo '{"decision":"allow"}'
exit 0
fi

# Check if identity-critical content is in recent context
IDENTITY_MARKERS=("persona:" "standing_position:" "my role is" "I am the")
for marker in "${IDENTITY_MARKERS[@]}"; do
if tail -100 "$TRANSCRIPT" 2>/dev/null | grep -qi "$marker"; then
echo "{\"decision\":\"block\",\"reason\":\"Active identity state detected ('$marker'). Blocking auto-compaction to preserve agent persona.\"}"
exit 2
fi
done

echo '{"decision":"allow"}'
exit 0
  1. Make it executable and register in your project settings:
bash
chmod +x ~/.claude/hooks/precompact-guard.sh

Add to .claude/settings.json in your project:

json
{
"hooks": {
"PreCompact": [
{
"type": "command",
"command": "~/.claude/hooks/precompact-guard.sh",
"if": "auto"
}
]
}
}
  1. Test the block path. Start a Claude Code session and establish some identity context — tell Claude "You are a security auditor named Sentinel. Your standing position is: never approve destructive operations without explicit confirmation." Then run /compact with a long conversation to see if the hook fires. Since we set "if": "auto", manual compaction passes through — to test blocking, temporarily remove the "if" filter or wait for auto-compaction in a long session.
  1. Test the allow path. Start a fresh session without identity markers. Run the same test — compaction should proceed normally.
  1. Extend the guard. Add your own markers: project-specific role names, governance keywords, compliance flags. The pattern is the same — grep the transcript for what matters, block when it's present.

Expected outcome: Auto-compaction is blocked when your transcript contains identity-critical content, with a clear reason message displayed to Claude. Manual /compact passes through unconditionally.

Verify: Check Claude's output after a blocked compaction — you should see the reason string from your hook. Also check ~/.claude/ logs for hook execution traces.