Skip to content

What This Skill Does

mk:lazy-agent-loader manages agent context budget in multi-agent workflows by loading only agent summaries initially (~50 tokens each) and deferring full agent definitions until an agent is selected. This avoids loading all agent files at session start, which would consume ~26,000 tokens.

When to Use

Automatically invoked by mk:agent-detector during agent selection. Not user-invocable directly. Activated after the detector scores all agents and identifies PRIMARY/SECONDARY/OPTIONAL tiers.

Core Capabilities

Agent Index (Summaries Only)

The skill maintains a compact index of all 15 agents:

AgentCategorySpecialtySignal Keywords
orchestratorinfraTask routing / complexity classificationroute, classify, assign, complexity
plannerplanningTwo-lens planning / Gate 1plan, feature, design, scope, requirements
architectplanningADRs / system designarchitecture, schema, api, infra, design, migration
developerdevImplementation (TDD)implement, build, code, feature, fix, refactor
testerqualityTDD enforcement / test writingtest, testing, coverage, qa, jest, vitest, pytest
reviewerquality5-dimension code review / Gate 2review, audit, quality, standards
securityqualitySecurity audit / BLOCK verdictssecurity, vulnerability, audit, owasp, injection
shipperopsDeploy pipeline / PR creationship, deploy, release, commit, pr, ci
documenteropsLiving docs / changelogsdocs, documentation, changelog, readme
analystinfraCost tracking / pattern extraction / memorycost, budget, patterns, metrics, usage, memory
researcherplanningTechnology research / library evaluationresearch, compare, evaluate, library
brainstormerplanningSolution brainstorming / trade-offsbrainstorm, alternatives, tradeoff, explore
journal-writeropsFailure documentation / lessonsfailure, incident, postmortem, lesson
git-manageropsGit operations / commit / push / PRgit, commit, push, pull, branch, pr, merge
ui-ux-designerdevUI/UX design / frontend patternsdesign, ui, ux, css, layout, accessibility, responsive

Token Savings

ScenarioWithout LazyWith LazySavings
Initial load (all agents)~26,000~1,00096%
Single agent task~26,000~2,50090%
Dual agent task~26,000~4,00085%
Full stack (3 agents)~26,000~5,50079%

Loading Tiers

Score TierLoad BehaviorTokens
>= 80 (PRIMARY)Full agent definition from .claude/agents/[name].md~500-2,000
50-79 (SECONDARY)Summary only from index~50
< 50 (OPTIONAL)Not loaded0

Agent Categories and When to Load

CategoryAgentsWhen to Load
planningplanner, architect, researcher, brainstormerWhen plan/design/research requested
devdeveloper, ui-ux-designerWhen code/implementation requested
qualitytester, reviewer, securityWhen review/test/security requested
opsshipper, documenter, journal-writer, git-managerWhen ship/deploy/docs requested
infraorchestrator, analystAuto-loaded by system at session start

Cache Strategy

Loaded agents are tracked in session state (loaded_agents[]). If an agent is already loaded, skip re-loading. Force reload with:

User: "reload agent developer"

The cache invalidates automatically when the agent file's mtime changes.

Workflow

  1. Initial Load — Load agent index (this file, ~1,000 tokens). Do NOT load individual agent files.
  2. Agent Detectionmk:agent-detector scores all agents using index keywords.
  3. Primary Selection — Agent(s) with score >= 80 identified as PRIMARY.
  4. Lazy Activation — Load full definition for PRIMARY agent(s). Use summary for SECONDARY.
  5. Pre-load guard — Agents needing session-start context (orchestrator, analyst) are pre-loaded even when lazy, to avoid missed context.

Integration with Agent Detector

Step 1: Score agents using agent_index keywords
Step 2: Identify PRIMARY agent(s) with score >= 80
Step 3: Load ONLY PRIMARY agent full definitions
Step 4: For SECONDARY agents, use summary from index

Example Prompt

User: "Fix the login bug"

1. Agent Detector scores all agents using index keywords:
   - developer: +60 (fix/bug) +20 (context) = 80 → PRIMARY
   - tester: +35 (bug implies test needed) → SECONDARY

2. Lazy Loader activates:
   - Load: .claude/agents/developer.md (~1,500 tokens)
   - Summary only: tester (score 50-79)

3. Total context: ~2,500 tokens (vs ~26,000 without lazy loading)

Common Use Cases

  • Every multi-agent workflow — automatically invoked by agent-detector
  • Large project with many agents — reduces session-start token cost by 96%
  • Single-agent tasks — only one full definition loaded, rest kept as summaries

Pro Tips

  • Agents that need session-start context (orchestrator, analyst) are pre-loaded even when lazy. Don't rely on lazy loading for these.
  • If you update an agent definition file mid-session, use "reload agent [name]" to force cache invalidation. The cache auto-invalidates on file mtime change.
  • The index file itself is ~1,000 tokens. This is the cost floor — no way to go lower without losing agent detection accuracy.

Released under the MIT License.