The cortex-tms auto-tier command analyzes your git repository’s commit history and file patterns to automatically suggest and apply tier tags to documentation files. It uses a scoring system to prioritize high-value documentation while capping HOT files to prevent context bloat, keeping your tiering system aligned with actual work patterns.
cortex-tms auto-tier [options]
Automatic tier management using git history and intelligent scoring . Auto-tier solves the problem of manually deciding which files should be HOT, WARM, or COLD by combining multiple signals: file importance (canonical docs, core patterns), location (docs structure), and recency (when last modified).
Think of it as intelligent memory management for your documentation. Critical reference docs stay HOT, high-value documentation is prioritized, and a hard cap prevents HOT tier explosion. Files are scored and ranked to ensure AI agents see the most relevant context without bloat.
Typical usage :
# Preview what would change
cortex-tms auto-tier --dry-run
# Use custom thresholds for your workflow
cortex-tms auto-tier --hot 14 --warm 60
Research-Backed
Auto-tier addresses the “Lost in the Middle” research finding: LLMs recall information best from the beginning and end of context, poorly from the middle. By placing recently-modified files (likely relevant) in HOT tier at the context beginning, auto-tier optimizes AI agent performance.
Option Default Description --hot <days>7Files modified within N days get recency bonus in scoring --warm <days>30Files modified within N days → WARM tier --cold <days>90Files older than N days → COLD tier --max-hot <count>10Maximum number of HOT files (prevents context bloat) --dry-run, -dfalsePreview tier suggestions without applying changes --force, -ffalseOverwrite existing tier tags (default: respect explicit tags) --verbose, -vfalseShow detailed reasons for each tier assignment
Repository Scan
Finds all *.md files in your repository (excluding **/node_modules/**, .git/**, **/dist/**)
Git History Analysis
For each tracked file, runs git log --follow to find the last commit timestamp
Uses --follow to track files across renames
Untracked files are skipped (not in git history)
Score Calculation
Assigns points to each file based on value signals:
+100 points : Canonical HOT files (NEXT-TASKS.md, CLAUDE.md, etc.) - highest priority
+40 points : Documentation files (docs/ directory)
+10 points : Core reference docs (docs/core/ directory)
+15 points : Recently modified (≤ 7 days by default)
-60 points : Archive files (docs/archive/ → always COLD)
Tier Assignment with Strict Cap
Sorts files by score and applies tiering:
Sort by score : All files ranked (canonical=100, docs/core/+recent=65, etc.)
Apply strict cap : Top N files (default: 10) become HOT, including canonical
Canonical priority : Score 100 ensures canonical files naturally fill HOT slots first
Directory conventions : Non-HOT files use directory rules: docs/guides/ → WARM, examples/ → COLD
Time-based fallback : Unclassified files use modification time
Explicit tags : Respected unless --force used (except canonical files which can be re-tagged)
Tag Insertion
Adds <!-- @cortex-tms-tier TIER --> comment at file beginning (or after front matter)
Dry run on cortex-tms repository (145 files analyzed):
$ cortex-tms auto-tier --dry-run
🔍 DRY RUN MODE: No files will be modified.
✨ .github/copilot-instructions.md
✨ docs/core/AI-COLLABORATION-POLICY.md
✨ docs/core/ARCHITECTURE.md
✨ docs/core/CONTENT-STANDARDS.md
✨ docs/core/DOMAIN-LOGIC.md
✨ docs/core/GIT-STANDARDS.md
✨ docs/core/INFRASTRUCTURE.md
✨ docs/core/TROUBLESHOOTING.md
✨ docs/guides/CLI-USAGE.md
✨ docs/guides/MIGRATION-GUIDE.md
✨ docs/archive/bootstrap-v3.0-strategy-plan.md
✨ docs/archive/sprint-v2.5-guidance-growth.md
✨ docs/archive/sprint-v2.6-integrity-atomicity.md
✨ CREATE: 101 new tier tags
Performance : ~300ms for 145 files
Files are scored based on multiple signals (higher score = higher priority for HOT):
Signal Points Description Canonical HOT +100 Must-have files (NEXT-TASKS.md, CLAUDE.md, etc.) - highest priority Documentation +40 Files in docs/ directory Core docs +10 Additional boost for docs/core/ Recent changes +15 Modified within --hot days (default: 7) Archive penalty -60 Files in docs/archive/ (always COLD)
Maximum HOT files : Default 10 (configurable via --max-hot)
Strict cap enforcement : Total HOT files (including canonical) never exceeds —max-hot. Files are sorted by score, and the top N become HOT. Canonical files have highest scores (100), ensuring they naturally fill HOT slots first.
Canonical HOT Files (always HOT, never demoted):
NEXT-TASKS.md - Current sprint tasks
CLAUDE.md - Agent instructions
.github/copilot-instructions.md - GitHub Copilot config
docs/core/PATTERNS.md - Code patterns and conventions
docs/core/GLOSSARY.md - Project terminology
Untracked Files (not in git):
Skipped entirely (not scored or tiered)
Explicit Tier Tags :
Always respected unless --force is used
Renamed Files :
git log --follow tracks history across renames
# Safe: preview tier suggestions
cortex-tms auto-tier --dry-run --verbose
# Review output, ensure it makes sense
# Apply tier tags immediately
# Commit tier tags to repository
git commit -m " chore: add tier tags via auto-tier "
# Daily commits → tight windows
cortex-tms auto-tier --hot 3 --warm 7 --cold 30
# Only last 3 days are HOT
# Files from 4-7 days ago are WARM
# Anything older than 30 days is COLD
Use case : Active startup, daily feature releases, rapid iteration
# Weekly/bi-weekly commits → longer windows
cortex-tms auto-tier --hot 21 --warm 60 --cold 180
# Files from 4-8 weeks ago are WARM
# Anything older than 6 months is COLD
Use case : Enterprise projects, quarterly releases, maintenance mode
# Balanced for most projects
# (equivalent to: --hot 7 --warm 30 --cold 90 --max-hot 10)
# Files from 1-4 weeks ago are WARM
# Anything older than 3 months is COLD
Use case : Standard development cadence, weekly sprints
# Allow more HOT files for larger context windows
cortex-tms auto-tier --max-hot 15
# Strict cap for smaller projects
cortex-tms auto-tier --max-hot 5
# No cap (use scoring only, not recommended)
cortex-tms auto-tier --max-hot 999
Use case : Adjust based on context window size and project complexity
# Run at start of each sprint
cortex-tms auto-tier --force
# Updates all tier tags based on current state
# Ensures tiers stay aligned with work patterns
Why --force?
Without --force: Skips files with existing tier tags
With --force: Overwrites all tier tags
Use weekly to keep tiers current as project evolves
# Step 1: Apply tier tags
# Step 2: Check tier assignments
# Output shows tier distribution and file organization
# COLD files: Excluded from analysis
# Context Reduction: 85% (70K instead of 82K)
Result : AI agents read only what matters, costs less, fewer hallucinations
Code Meaning Scenario 0Success Tier tags analyzed/applied successfully 1Error Not a git repository, invalid options, git command failed
Examples :
# Success (git repo, valid options)
$ cortex-tms auto-tier --dry-run
❌ Error: Not a git repository
# Error (invalid threshold)
$ cortex-tms auto-tier --hot foo
❌ Error: --hot must be a positive number
$ cortex-tms auto-tier --dry-run --verbose
🔍 DRY RUN MODE: No files will be modified.
✨ docs/core/TROUBLESHOOTING.md
High-value doc (score: 65 )
... (detailed reasons for each file )
Use case : Understanding why files are tiered the way they are (shows scoring results)
# ✨ CREATE: 81 new tier tags
# Second run (files already have tags)
# ✓ No changes to apply (existing tags preserved)
Behavior : Respects existing tier tags
# ✨ CREATE: 81 new tier tags
# Second run (2 weeks later, with --force)
cortex-tms auto-tier --force
# 🔄 UPDATE: 23 tier changes
# (files moved from HOT→WARM as they aged)
Behavior : Overwrites all tier tags based on current git state
- cron : ' 0 0 * * 1 ' # Every Monday at midnight
workflow_dispatch : # Manual trigger
- uses : actions/checkout@v4
fetch-depth : 0 # Full git history needed
uses : actions/setup-node@v4
run : npx cortex-tms@latest auto-tier --force
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "chore: weekly tier update" || echo "No changes"
Benefit : Tiers stay current automatically, no manual work
# Update tier tags before each commit
npx cortex-tms auto-tier --force --quiet
# Stage any tier tag changes
Benefit : Every commit includes up-to-date tier tags
Warning : Adds ~300ms to commit time
Git Repository Required
Auto-tier must be run in a git-initialized project. It uses git history to determine file recency.
git commit -m " Initial commit "
# Now auto-tier will work
Other requirements :
Git installed and in PATH
Files must be committed for accurate history
Markdown (.md) files only
Subdirectory Detection (coming soon):
# Currently: Must run from repo root
cortex-tms auto-tier # ✅ Works
cortex-tms auto-tier # ❌ Error: Not a git repository
Workaround : Always run from repository root
Untracked Files :
# Untracked files are skipped (not scored or tiered)
echo " # New Doc " > new-file.md
cortex-tms auto-tier --dry-run
# Output: new-file.md won't appear
# (not in git history, so skipped)
# To tier it: commit first
git commit -m " Add new doc "
cortex-tms auto-tier --dry-run
Rationale : Only committed files have history to analyze
Binary Files :
# Only Markdown files are processed
# Images, PDFs, etc. are ignored
Performance :
# Linear scaling with file count
# 111 files: ~300ms (cortex-tms repo)
For very large repos (1000+ files), consider:
Running less frequently (monthly instead of weekly)
Using --dry-run to preview before applying
Empty Git Repository :
# No files tiered (no committed files to analyze)
# Must commit files first for auto-tier to work
Renamed Files :
# git log --follow tracks renames
git commit -m " Rename file "
cortex-tms auto-tier --dry-run
# NEW.md gets proper age (tracks history through rename)
Submodules :
# Analyzes within submodule context
# Each submodule has its own git history
Symptom :
❌ Error: Not a git repository
Run this command in a git-initialized project.
Causes :
Not in a git repository
Running from subdirectory (limitation - must run from repo root)
Solutions :
git commit -m " Initial commit "
# Currently in subdirectory
cd $( git rev-parse --show-toplevel )
Symptom :
$ cortex-tms auto-tier --hot foo
❌ Error: --hot must be a positive number
$ cortex-tms auto-tier --hot 50 --warm 30
❌ Error: --hot threshold must be ≤ --warm threshold
Solution : Use valid, ordered thresholds
# ✅ Correct: hot ≤ warm ≤ cold
cortex-tms auto-tier --hot 7 --warm 30 --cold 90
Symptom :
Causes :
All files already have tier tags (use --force to update)
No Markdown files in repository
All files in ignored directories
Solutions :
# Overwrite existing tier tags
cortex-tms auto-tier --force
# How many .md files exist?
find . -name " *.md " -not -path " */node_modules/* " | wc -l
# If 0, create some documentation
Start with Dry Run
Always preview tier suggestions before applying:
cortex-tms auto-tier --dry-run --verbose
Review the output to ensure thresholds make sense for your project.
Commit Tier Tags
Tier tags should be version-controlled:
git commit -m " chore: update tier tags "
This keeps tiers consistent across the team.
Adjust Thresholds to Workflow
Match thresholds to your commit cadence:
Daily commits : --hot 3 --warm 7
Weekly commits : --hot 14 --warm 30
Monthly commits : --hot 30 --warm 90
Run Regularly
Update tiers periodically as work shifts:
# Weekly: Before sprint planning
cortex-tms auto-tier --force
# Or: Monthly maintenance
cortex-tms auto-tier --force
# Verify tier assignments
# Update tiers before major AI coding session
cortex-tms auto-tier --force
# Ensures AI sees most relevant context
cortex-tms prompt init-session
# Should pass (tier tags don't affect validation)
Test repository : cortex-tms (145 markdown files)
Operation Time Files/Second Dry run ~300ms 370 files/s Apply tags ~340ms 325 files/s Force update ~350ms 315 files/s
Scaling :
Linear with file count
Git log is dominant cost (~2-3ms per file)
Future optimizations (planned for v3.2+):
Batched git log for large repos
Parallel file processing