[FEATURE] Task-scoped rules: load rule files by task type, not only by path
Preflight Checklist
- [ ] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
Rules in .claude/rules/*.md support a paths: frontmatter: they load lazily when matching files are touched. There is no equivalent for task type. Directives like "when creating or changing an HTTP endpoint, define the contract and error format first, and add a contract test in the same PR" apply to a kind of work, not to a directory — often before any file is touched.
Today the only homes for such directives are (a) CLAUDE.md, where they dilute everything else (the docs' own guidance caps CLAUDE.md size because adherence drops), or (b) external machinery: we built a UserPromptSubmit hook that runs the prompt against an indexed directive catalog by semantic similarity and injects the top matches in full via additionalContext (working reference: https://gist.github.com/brunox64/ffbdfb4f78fe928fce31c866c9d83aad). It approximates task scoping through retrieval rather than a real task-type taxonomy, and it works, but this is exactly the kind of policy concept that deserves first-class support, like paths: already has, instead of every team re-deriving it from a search index.
Proposed Solution
Frontmatter on rule files, mirroring paths::
---
task: "creating or changing HTTP endpoints, routes, controllers, API contracts"
---
Every new endpoint gets a contract (request, response, 4xx errors) before the handler, and a contract test in the same PR.
Loading semantics (either tier is valuable alone):
- Model-mediated (cheap): expose task-scoped rules like skills — name +
taskdescription always visible; the model pulls the body when the description matches the work (same mechanism that triggers skills today). - Harness-mediated (stronger): classify the user prompt against the
taskdescriptions (embedding or the small routing model already used elsewhere) and inject matching rule bodies at prompt time; re-inject after compaction.
Alternatives considered
- Big CLAUDE.md: dilution; contradictions resolved arbitrarily.
- References from CLAUDE.md to other files: cost context and are not followed.
- Skills as directive containers: skills are procedures the model invokes; directives are constraints that must arrive — inversion of control matters.
- External hook + search service (our current solution): works, proves demand, but every team rebuilds it.
Evidence it works
Running for our team via hooks: sub-second retrieval, directives injected in full within a budget. We don't have "suggested vs. used" measurement wired up yet — that's on our own gap list, not a claim we're making here. Details: https://gist.github.com/brunox64/ffbdfb4f78fe928fce31c866c9d83aad.
Environment
Claude Code 2.1.248, Linux x86_64
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗