Skip to content

Fix token leak from multiple daemons + reduce skill token usage#48

Merged
bearmug merged 3 commits into
mainfrom
fix/skill-token-leak
Jan 29, 2026
Merged

Fix token leak from multiple daemons + reduce skill token usage#48
bearmug merged 3 commits into
mainfrom
fix/skill-token-leak

Conversation

@bearmug
Copy link
Copy Markdown
Contributor

@bearmug bearmug commented Jan 29, 2026

Summary

  • Reduce skill token consumption by ~30% via shorter prompts
  • Fix multiple daemon instances causing massive token leak (~40k tokens/hour)

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 UserPromptSubmit hook spawned claude -p on every stale prompt.

Changes

Skill Token Reduction

  • Shorter, more focused skill prompts

Daemon Token Leak Fix

  • Atomic locking: Use mkdir-based lockdir instead of file-based lockfile (portable to macOS/Linux)
  • Semver comparison: Only NEWER versions take over running daemons
  • Lightweight hook: Remove claude -p spawn from hook - now only updates lastActivity timestamp
  • Updated tests: All tests pass with new lockdir structure

Test plan

  • All 10 test files pass (run-tests.sh)
  • New test: older versions do NOT take over newer daemons
  • Manual: verify single daemon after plugin update

@bearmug bearmug changed the title Reduce skill token consumption by ~30% Fix token leak from multiple daemons + reduce skill token usage Jan 29, 2026
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).
@bearmug bearmug force-pushed the fix/skill-token-leak branch from ee5267f to 62a546b Compare January 29, 2026 19:55
@bearmug bearmug force-pushed the fix/skill-token-leak branch from 7442cbf to bed52d1 Compare January 29, 2026 20:01
@bearmug bearmug merged commit 8efdaf8 into main Jan 29, 2026
1 check passed
@bearmug bearmug deleted the fix/skill-token-leak branch January 29, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant