Reload the connector skill after a compaction from the SessionStart hook
Merged
JE
2mo ago+346+346+012345678901234567890123456789-24-24-01234567890123456789
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.jsonchange. The SessionStart hook already runsbasecamp agent-hook pre-commit-snapshoton every source,compactincluded, so an older CLI stays exactly as it was. - On
source: "compact"it readstranscript_patha line at a time, looking for the last skill-load line ("text":"Base directory for this skill: …/basecamp-connect\n). If thatSKILL.mdstill exists, it addsadditionalContextnaming 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
additionalContextis 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.
PostCompactcan't add context (no decision control), so SessionStartcompactis the event.- The rename notice and this notice now share the hook's single JSON reply.
Verification
go test ./internal/commands/ -run AgentHookpasses. 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-dirand this build on PATH:- The orchestrator was set up as a dry run, then
/compactran. - The transcript shows a
compact_boundaryand the hook'shook_additional_context. - On the next request line, the model's first action was
Readof the loaded skill'sSKILL.md, and it then went through the handoff steps.
- The orchestrator was set up as a dry run, then
golangci-lint run ./internal/commands/...is clean, andmake check-skill-driftpasses.- Locally,
TestDeleteConfirmableFollowsTheAudienceNotTheDeviceandTestBareBasecampNeverReportsASetupErrorfail 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.