Reload the connector skill after a compaction from the SessionStart hook

Merged
JE
2mo ago
+346-24

Summary

After a compaction, the plugin's SessionStart hook tells a session that ran basecamp-connect to read that skill's SKILL.md in full before it goes on. This replaces the in-skill reminder that the earlier commits added.

Why

  • After a compaction Claude Code re-attaches each invoked skill, cut to its first 5,000 tokens. Once the re-attached skills pass 25,000 tokens together, the oldest are dropped whole (skills, "Skill content lifecycle").
  • This skill is ~38.8k chars. What falls past the cut is what the orchestrator needs on every request: the handoff steps and the subagent's instructions.
  • A reminder written into the skill can be dropped along with the skill. Re-invoking with the same argument adds only an "already loaded" note. That was three review rounds on the same mechanism, so the trigger has to live outside the skill.
  • Connector sessions run for days. HEY² is starting them with --autocompact 200000 (basecamp/hey-native-apps#4004), so compactions become routine.

How

  • No hooks.json change. The SessionStart hook already runs basecamp agent-hook pre-commit-snapshot on every source, compact included, so an older CLI stays exactly as it was.
  • On source: "compact" it reads transcript_path a line at a time, looking for the last skill-load line ("text":"Base directory for this skill: …/basecamp-connect\n). If that SKILL.md still exists, it adds additionalContext naming the file to Read in full, before anything else, the request in hand included, without restarting the connector.
  • It names the file instead of pasting it because additionalContext is capped at 10,000 characters (hooks).
  • It uses whichever copy of the skill the session actually loaded. Every other session, and every other source, gets nothing.
  • PostCompact can't add context (no decision control), so SessionStart compact is the event.
  • The rename notice and this notice now share the hook's single JSON reply.

Verification

  • go test ./internal/commands/ -run AgentHook passes. Each new test was shown red on a broken implementation: dropping the source check, and not reading lines longer than the 1 MiB buffer.
  • A real compaction in a scratch Claude Code 2.1.296 session, with this checkout as --plugin-dir and this build on PATH:
    • The orchestrator was set up as a dry run, then /compact ran.
    • The transcript shows a compact_boundary and the hook's hook_additional_context.
    • On the next request line, the model's first action was Read of the loaded skill's SKILL.md, and it then went through the handoff steps.
  • golangci-lint run ./internal/commands/... is clean, and make check-skill-drift passes.
  • Locally, TestDeleteConfirmableFollowsTheAudienceNotTheDevice and TestBareBasecampNeverReportsASetupError fail on origin/main too (this shell's terminal/env); remote CI is the judge.

Alternatives

  • Pasting the skill as the context: over the 10k cap, so it gets saved to a file with a 2k preview that Claude Code doesn't ask the model to read.
  • Splitting the skill across several hook entries, one 10k chunk each: fragile, and it injects ~10k tokens per compaction.
  • Restructuring the skill so per-request steps fit in 5k, with the subagent instructions in their own file: coming as a follow-up PR, as Jeremy asked.