[FEATURE REQUEST] Directive-Based Context Loading
I've been using claude code with very impressive results both at work and at home. My biggest dilemma was running into frequent compaction issues at work, and token limits at home, so I ended up coming up with a solution that worked quite well for me. Upon explaining it to claude for a new project, it actually suggested filing an issue, so I had it search existing ones, and upon not finding something it felt was close enough, draft one.
---
### Problem
Claude Code currently loads context indiscriminately, leading to:
- Token limit hits on larger projects
- Frequent context compaction requirements (even with unlimited tokens)
- Irrelevant context consuming valuable context window space
- Inconsistent performance as project size grows
The default "load everything" approach optimizes for demos but breaks down on real-world projects.
### Proposed Solution
Implement directive-based context loading through configuration files (e.g., .claude/directives.md) that specify when and what context to load:
Directory-based triggers (pattern matching):
When working in paths matching **/test/* → load .claude/testing-guidelines.md
When working in ./src/api/* → load .claude/api-conventions.md
Task-based triggers (natural language):
When debugging network issues → load systems/networking/troubleshooting.md
When setting up CI/CD → load templates/pipeline-setup.md
### Implementation Ideas
- Configuration file format (YAML/Markdown) for directive definitions
- Pattern matching for directory-based triggers
- NLP matching for task-based triggers
- Fallback to current behavior when no directives match
- Optional: Template system for parameterized, reusable workflows
### Benefits
- Dramatically reduced token consumption
- Fewer context compaction events
- More relevant context for better responses
- Scalable to large codebases
- User-controlled vs. automatic behavior
### Real-World Usage
This pattern has been successfully implemented and tested across multiple production projects, demonstrating significant improvements in context relevance and token efficiency
compared to the default loading behavior.
### Real-World Impact
This addresses the core scalability issue preventing Claude Code adoption on enterprise-scale projects. Current approach forces users to choose between context relevance and
hitting limits.
---
This issue was collaboratively drafted with Claude Code based on real-world usage patterns and pain points.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗