Fix token leak from multiple daemons + reduce skill token usage#48
Merged
Conversation
Consolidate repeated patterns into lib-common.md and slim down verbose skills to reduce context loading overhead: - Create lib-common.md with sanitize, bridge update, and error patterns - Slim tool-slack.md: 6.9KB → 3.0KB (remove inline examples) - Slim tool-gcalendar.md: 3.8KB → 1.8KB (trim docs) - Slim connection-detect.md: 6.5KB → 2.8KB (extract reusable parts) - Slim hub-focus.md: 8.6KB → 2.1KB (remove mode examples) - Slim hub-ack-slack.md: 5.2KB → 1.9KB (condense selectors) - Slim hub.md: 5.8KB → 2.6KB (compact extraction scripts) - Slim hub-ack-github-pr.md: 4.0KB → 1.9KB (trim fix loop docs) - Slim hub-refresh.md and hub-ack.md (reference lib-common) All 180 tests pass. No functionality changes.
Root cause: Multiple plugin paths (installed, dev, worktree) each spawned their own daemon, and the hook also spawned Claude CLI on every prompt. Changes: - Use atomic mkdir-based locking instead of file-based lockfile - Add semver comparison so only NEWER versions take over daemons - Remove Claude CLI spawn from hook - now only updates lastActivity - Update tests for new lockdir structure This reduces token consumption from ~40k/hour to daemon-controlled refresh only (single instance).
ee5267f to
62a546b
Compare
7442cbf to
bed52d1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root Cause (Daemon Fix)
Multiple plugin paths (installed cache, dev repo, worktrees) each spawned their own daemon, and version mismatch logic caused them to fight. Additionally, the
UserPromptSubmithook spawnedclaude -pon every stale prompt.Changes
Skill Token Reduction
Daemon Token Leak Fix
mkdir-based lockdir instead of file-based lockfile (portable to macOS/Linux)claude -pspawn from hook - now only updateslastActivitytimestampTest plan
run-tests.sh)