agentleFS
TheophilusChinomonaTheophilusChinomona/idev/skills/smart-context/SKILL.md

smart-context

Skill0 starsChanged 5 months agoMITView on GitHub

Token-optimized context loading: load the cached project index at session start, then Grep before Read, expanding only as needed. Use when starting a session, deciding what context to load, or generating/refreshing the project index. For feature-name → file-path lookups, the file-index skill answers directly from this index.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Step 1: Generate the index: If index.json is missing (e.g.

    line 33
  2. Distinctive:

    When you need the project-map, load ONLY the relevant section:

    line 86
  3. Very specific:

    Use the patterns section of index.json.

    line 130
  4. Very specific:

    When regenerating, the scanner updates the generated timestamp automatically.

    line 191

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Smart Context Skill

Purpose

Token-optimized context loading using the project-map as the data source.

Data Sources (Priority Order)

  1. .claude/idev/smart-context/index.json - Lightweight index (~70 lines)
  2. .claude/idev/project-map/project.map.md - Full project map (load sections on demand)

Activation

This skill is ALWAYS ACTIVE. Apply these rules to every task.


Generating the index

Step 0: Ensure project-map exists. The project map is the data source for the index. If .claude/idev/project-map/project.map.md is missing or severely stale (>30 days), generate it first:

python3 "${CLAUDE_PLUGIN_ROOT}/skills/project-map/ai_map_updater.py"

This auto-detects split vs unified projects and writes the map. Only takes a few seconds and only runs when needed (missing or stale).

Step 1: Generate the index. If index.json is missing (e.g. the session-start hook reports no index), generate it by running the scanner from the project root:

python3 "${CLAUDE_PLUGIN_ROOT}/skills/smart-context/scanner.py"

This writes .claude/idev/smart-context/index.json with the detected stack, structure roots, feature names, and file-naming patterns.

Fallback (no python3 available): build the index manually — detect the stack from package.json / *.csproj / requirements.txt / go.mod, list feature directory names under features/ or modules/, note naming patterns (e.g. *Controller.*, *.hook.*), and write the same JSON shape (stack, structure, features, patterns) to .claude/idev/smart-context/index.json.


Phase 1: Session Start

Load ONLY the lightweight index:

.claude/idev/smart-context/index.json

This gives you (contents depend on what the scanner detected):

  • Tech stack (e.g. React + .NET, Next.js + Python — whatever the project uses)
  • Detected feature names (up to 50)
  • File-naming patterns (e.g. Page, Container, Service, Controller)
  • Project structure roots

DO NOT load the full project-map yet.


Phase 2: Task Analysis

Step 2.1: Extract Keywords

From user message, identify:

  • Feature name: whatever appears in index.json's features list (e.g. orders, customers, auth)
  • Action type: fix, add, update, delete, explain, find
  • Layer: frontend, backend, api, database, full-stack

Step 2.2: Determine What to Load

Task TypeWhat to Load
Feature-specific taskGrep for feature files only
"Where is X?"Grep, don't read full map
"List all controllers"Load project-map backend section only
Architecture questionLoad project-map structure section
Bug fix in specific fileGrep → Read that file only

Phase 3: Smart Loading from Project Map

When you need the project-map, load ONLY the relevant section:

Section Loading

# To find frontend files for a feature:
Grep "FeatureName" in project.map.md → Get file paths → Read specific files

# To find backend controller:
Grep "OrdersController" in project.map.md → Get path → Read controller

# To understand FE→BE mapping:
Load only the "FE → BE Mappings" section if it exists

Never Do This

❌ Read the entire project.map.md (it can run to thousands of lines) ❌ Load all controllers "to understand the project" ❌ Pre-load map sections not related to current task

Always Do This

✅ Grep project.map.md for keywords first ✅ Extract only the paths you need ✅ Read actual source files targeted by path


Phase 4: Using Both Systems Together

User asks about "orders"
         ↓
Check index.json → "Orders" is a known feature
         ↓
Grep project.map.md for "*Order*" → Get 5 file paths
         ↓
Read only the relevant file (e.g., OrderListContainer.tsx)
         ↓
If needed, follow imports to related files

Phase 5: Pattern Reference

Use the patterns section of index.json. Illustrative examples (the real globs come from index.json):

PatternGlob
Page**/pages/*Page.tsx
Container**/containers/*Container.tsx
Service (FE)**/services/*.service.ts
Hook**/hooks/*.hook.ts
Controller**/*Controller.cs
Service (BE)**/*Service.cs

Feature Keywords → Search Patterns

Illustrative examples ONLY — the real keyword list is the features array in index.json; build the same **/[Xx]keyword* glob for whatever features that project actually has:

KeywordSearch
order, orders**/[Oo]rder*
customer**/[Cc]ustomer*
invoice**/[Ii]nvoice*
auth, login**/[Aa]uth*
payment**/[Pp]ay*
user**/[Uu]ser*
dashboard**/[Dd]ashboard*

Anti-Patterns (DO NOT DO)

  1. ❌ Loading entire project.map.md at session start
  2. ❌ Reading all files in a feature folder
  3. ❌ Pre-loading "just in case"
  4. ❌ Ignoring index.json and going straight to map
  5. ❌ Reading files not mentioned by user

Token Budget Guide

ActionEstimated Tokens
Load index.json~100
Grep project.map.md~50
Read specific section of map~200-500
Read one source file~200-800
Target per task< 1,500

Staleness Detection

The index.json records a generated timestamp. Check staleness:

1. Read index.json and extract the "generated" date
2. If older than 14 days → warn: "smart-context index is N days old — may miss new features"
3. If older than 30 days → fail loudly: "smart-context index is severely stale — regenerate"
4. If missing → generate before proceeding (see "Generating the index" above)

The session-start hook also checks file mtime and warns if > 14 days old. When regenerating, the scanner updates the generated timestamp automatically.

Summary

index.json (always)
      ↓
Grep for keywords (fast)
      ↓
project.map.md section (if needed)
      ↓
Actual source files (targeted)

The project-map is your detailed reference. The index.json is your quick lookup. Use them together, but always start minimal.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.