What Happened
Engineers at Dewu (得物) Technology published a detailed implementation report — via Juejin — describing a production-deployed, three-layer skill architecture for Claude Code that enforces component reuse in a monorepo environment. The system uses AGENTS.md persistent context, a UserPromptSubmit hook for intent routing, and a structured Skill with a unified entry point (find-component.js) to intercept code generation before new components are created.
The stated problem: developers and AI agents default to creating new components rather than searching for existing ones, causing library bloat, rising maintenance costs, and degraded UI consistency. The team 's framing is explicitly behavioral — the problem is not search capability , it is the agent's decision sequence.
Why It Matters
This write-up is one of the more rigorous public accounts of operationalizing Claude Code skills in a production mon orepo. Several findings are directly actionable for engineering teams evalu ating agentic coding tooling:
- Implicit skill triggering is unreliable. The team cites Vercel's own agent evalu ations: default skill triggering did not improve task pass rates; explicit instructions and
AGENTS.md-style passive context produced more stable behavior. This matches observed behavior across multiple agentic frameworks. - OpenAI Codex Skills use progressive disclosure. The post references Codex Skills documentation noting that agents first read only a skill's metadata/ description at runtime, loading the full
SKILL.mdonly upon activation — making thedescriptionfield the primary trigger surface. Teams building skills for any framework should treat the description as a routing contract, not documentation. - Unified entry points reduce agent hallucination paths. By collapsing
scan-components,match-component, andresolve-scopeinto a singlefind-component.jscall, the team eliminated branching uncertainty. The agent executes one business action — "check for reusable component " — rather than orchestrating multiple sub-steps independently.
The Technical Detail
Three-Layer ArchitectureThe system is structured as follows:
- Layer 1 —
AGENTS.md(persistent context): Encodes the reuse-first rule, the component index entry point, and the post-scan description completion flow. Present every session. Purpose: ensure the agent knows the mechanism exists. - Layer 2 — Hook (
UserPromptSubmit): When the user's prompt contains semantic signals like "封装组件" (encapsulate component) or "是 否有现成组件" (is there an existing component), additional context is injected before the prompt is processed. Claude Code 's documentedUserPromptSubmithook supportsadditionalContextinjection at this stage. - Layer 3 — Skill (
find-component.js): Acceptsquery,repoRoot, andstartDir. Internally: auto-triggersrun-scan .jsifcomponents.csvis absent; callsresolve-scopeto compute search boundaries; callsmatch-componentfor ranked results; logs usage for frequency weighting; returns a fixed JSON protocol with fields for success, no-match, scan-triggered, and failure states .
Monorepo Scope Resolution
resolve-scope.js parses pnpm- workspace.yaml to enumerate workspace packages, back-calculates currentAppRoot from the focused file path, then constructs a search set of: current application + root-level shared packages (e.g., apps/_share/, packages/). Full-repo search activ ates only when startDir equals the repo root. This mirrors how a human engineer searches : current app first, then shared libraries, not the entire monorepo.
Multi-Factor Matching
match-component.js and fuzzy-match. js implement a composite scoring model with the following signals, in combination:
- Exact and substring name match
- Edit-distance fuzzy match
- Token overlap
- Acron ym matching (e.g.,
dlp→DateLinkPicker) - Current-app boost (local components ranked higher)
- Usage frequency weighting (recorded on each match hit)
- Source quality weighting (README-inferred descriptions outrank pure inferred)
- File existence validation (missing files are downweighted or filtered)
- Record type priority (components ranked above dependency entries)
A configurable low-score threshold (NO_MATCH_SCORE_THRESHOLD) gates noise: if the top result scores below the threshold, the system triggers one re -scan and re-queries before returning a no-match response. This prevents low -confidence hits from reaching the agent.
What To Watch
- Claude Code hooks API evolution: The
UserPromptSubmithook is a current mechanism — Anthropic has been iter ating on Claude Code's extension surface. Any changes to hook lifecycle oradditionalContextpayload schema would require updates to the routing layer described here. - Codex Skills adoption patterns: Open AI's progressive disclosure model for Skills (metadata-first loading) is architect urally different from the
AGENTS.mdapproach. As more teams publish comparative implementations, benchmark data on trigger reliability across frameworks should emerge. - Monorepo tooling integration: The
pnpm-workspace.yamldependency for scope resolution means this approach is pn pm-specific as implemented. Teams on Nx, Turborepo, or Yarn workspaces would need equivalent workspace manifest parsers — a likely fork point for any open-source release of this tooling. - Component index freshness: The auto-scan fall back on missing
components.csvis a correctness safeguard, but scan lat ency in large monorepos could introduce agent response delays. Watch for c aching or incremental indexing approaches as this pattern scales.