V-CodeSmith/nuxt-llm-context
About
A Nuxt module & CLI that analyzes your project structure and generates a compressed llms.txt to cut LLM context waste by ~60%.
AI & Machine LearningMeasured star growth
- in 24h
- 0
- in 7 days
- Collecting history
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Original@yourscope/nuxt-llm-context
Give your AI coding assistant a map of your Nuxt project instead of the whole repository.
Cursor, Copilot, Windsurf, Claude Code and Codex all work from whatever context
you hand them. Pointing them at llms.txt — a short, generated map of which files
are core, how they are wired together, and what to ignore — means fewer tokens
spent re-reading lockfiles, dead components and build output, and better answers
about the files that actually matter.
npx nuxt-llm-context scan # writes llms.txt in ~1s on a small app
# my-shop
> Nuxt 4, TypeScript, Tailwind project, 84 source files, 31 components, 12 routes.
## Core files — always read before editing
- `nuxt.config.ts`: project config (28 lines)
- `app.vue`: application entry (12 lines)
- `pages/index.vue`: route `/` (96 lines, used by `layouts/default.vue`)
- `composables/useAuth.ts`: composable (auto-imported) (54 lines, used by `components/AppHeader.vue`, `pages/checkout.vue`)
- `server/api/products.get.ts`: Nitro API route (21 lines)
- `components/ProductCard.vue`: component (auto-imported) (44 lines, used by `pages/index.vue`)
## Component / composable usage
- `components/ProductCard.vue` -> `pages/index.vue`, `pages/search.vue`
- `composables/useAuth.ts` -> `components/AppHeader.vue`, `pages/checkout.vue`, `middleware/auth.ts`
## Routes (pages)
- `/` -> `pages/index.vue`
- `/product/[slug]` -> `pages/product/[slug].vue`
## Ignore (do not read, waste of context)
- .nuxt/, node_modules/, .output/, dist/, coverage/
- Unreferenced (no importer, no template usage — delete rather than extend): `components/OldButton.vue`
## Conventions
- Auto-imports are on: do not add `import { ref } from 'vue'` style imports for Nuxt/Vue APIs.
- Data fetching uses `useFetch` / `useAsyncData`; never call the API from `setup()` directly.
- Server routes live under `server/api/**` and use `defineEventHandler`.
Everything runs locally: no source code leaves your machine.
Install
npm install -D @yourscope/nuxt-llm-context
The analysis engine is Python (standard library only — nothing to pip install). If
no CPython ≥ 3.9 is found, a private interpreter is fetched through
uv on first run: user-local, no admin rights. Override
the interpreter with pythonPath / LLM_CONTEXT_PYTHON for offline or CI machines.
Use it as a Nuxt module
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@yourscope/nuxt-llm-context'],
llmContext: {
outputPath: 'llms.txt',
maxTokens: 1200,
},
})
You get four things:
| Surface | What it does |
|---|---|
/__llm-context/scan |
Dev-only JSON endpoint, ?write=1 also writes the file |
useLLMContext() |
Auto-imported composable: { result, pending, error, ready, scan() } |
$llmContext |
Same API via the plugin: useNuxtApp().$llmContext |
runOnBuild / watch |
Regenerate on nuxt build, or on file changes while nuxt dev runs |
<script setup lang="ts">
const { result, pending, scan } = useLLMContext()
onMounted(() => scan()) // result.value.coreFiles, result.value.llmsTxt, …
</script>
Module options
| Option | Default | Meaning |
|---|---|---|
outputPath |
llms.txt |
Output file, relative to the Nuxt root |
includePatterns |
[] |
Only these globs ([] = every .vue/.ts/.js/.mjs/.mts/.cjs/.cts/.jsx/.tsx) |
excludePatterns |
[] |
Extra ignores; !pattern re-includes |
pythonPath |
auto | Explicit CPython ≥ 3.9 |
maxTokens |
1200 |
Soft ceiling — sections shrink until the file fits |
maxCore |
20 |
Files listed under "Core files" |
structure |
true |
Directory tree section |
routeList |
true |
Route table |
deadCode |
true |
Unreferenced files report |
shareUrl |
false |
Add a compressed playground URL to the JSON payload |
writeAgents |
false |
Also write AGENTS.md (never overwrites an existing one) |
runOnBuild |
false |
Scan during nuxt build |
watch |
false |
Rescan on dev file changes (1.5 s debounce) |
devRoute |
true |
Register /__llm-context/scan |
enabled |
true |
Master switch |
runOnBuild and watch shell out to the CLI in a child process, so a hung
analyzer can never block your dev server.
Use the CLI (module not required)
npx nuxt-llm-context scan # write llms.txt
npx nuxt-llm-context scan --stdout # preview, write nothing
npx nuxt-llm-context init # create llms.config.ts + .llmignore
npx nuxt-llm-context --help
| Flag | Meaning |
|---|---|
--root <dir> |
Project root (default: cwd) |
--config <file> |
Explicit config file |
--output, -o <file> |
Output path (default llms.txt) |
--include <glob> |
Only matching files (repeatable) |
--exclude <glob> |
Skip matching files (repeatable, ! re-includes) |
--python <path> |
Interpreter to use |
--max-tokens <n> |
Soft token ceiling |
--max-core <n> |
Size of the core section |
--write-agents |
Also write AGENTS.md when absent |
--share-url |
Print a playground link with the compressed output |
--no-structure / --no-routes / --no-dead-code |
Drop a section |
--stdout / --no-write |
Print instead of writing / analyse only |
--json |
Full JSON payload (for scripts) |
--fail-on-unused |
Exit 2 when unreferenced components exist |
--quiet, -q |
Errors only |
Exit codes: 0 success · 1 failure (bad root, missing Python, empty include
match, unknown flag) · 2 --fail-on-unused found dead components.
Configuration resolution
- CLI flags
llms.config.{ts,mts,js,mjs,json}in the project root (or--config)llmContextinnuxt.config.ts- defaults
llms.config.ts is TypeScript, loaded through jiti — types come from the package:
import type { LLMContextConfigFile } from '@yourscope/nuxt-llm-context'
export default {
outputPath: 'llms.txt',
excludePatterns: ['legacy/', '!legacy/still-used.vue'],
maxTokens: 1200,
} satisfies LLMContextConfigFile
CI
npx nuxt-llm-context scan --fail-on-unused
Regenerate in the pipeline (or on a pre-commit hook) and commit llms.txt so the
map never drifts from the code it describes.
How the analysis works
| Stage | Detail |
|---|---|
| Scan | Walks the tree with gitignore-style rules. .llmignore plus built-ins skip node_modules, .nuxt, .output, tests, lockfiles, binaries, maps and .env* |
| Parse | Regex analysis of SFC <template>/<script>, imports (static, dynamic, #components), exports and template tags. No full parser, so a half-written file never crashes the run |
| Graph | Explicit imports and Nuxt auto-import component usage (there is no import statement for <AppHeader/>), plus page → layout edges |
| Rank | Weighted PageRank over that graph, biased by layer (pages, composables, server …) and file size |
| Classify | core / supporting / ignorable |
| Report | llms.txt (+ optional AGENTS.md) and a JSON payload for tooling |
Core means: entry files (app.vue, error.vue), config, everything Nuxt
registers implicitly (plugins/, middleware/, modules/), every page/layout,
Nitro routes, and anything with an importer or template usage. Files nothing
references are listed as unreferenced instead of being presented as architecture.
Ignore rules follow .gitignore semantics: rules are matched in order and the
last match wins, so a later !path re-includes something an earlier rule excluded —
including one of the built-in defaults. A directory that could contain a
re-included file is still traversed.
JSON payload
{
"ok": true,
"root": "/abs/path/to/project",
"coreFiles": ["app.vue", "nuxt.config.ts", "pages/index.vue"],
"componentUsage": { "components/AppHeader.vue": ["pages/index.vue"] },
"unusedFiles": ["components/OldButton.vue"],
"treeSummary": "components/ (3 files) - components\n AppHeader.vue (10L, 2 importers)",
"llmsTxt": "# my-app\n\n> …",
"tokenEstimate": 712,
"stats": { "fileCount": 84, "totalLines": 5104, "tailwind": true, "apiRoutes": 3 },
"routes": ["pages/index.vue"],
"deadCode": [],
"files": [{ "path": "pages/index.vue", "kind": "core", "role": "page", "score": 0.032 }],
"durationMs": 640,
"version": "0.1.0"
}
Programmatic API
import { scanProject } from '@yourscope/nuxt-llm-context/core'
const { result, pythonVersion } = await scanProject({ root: process.cwd(), write: true })
console.log(result.tokenEstimate, result.coreFiles)
Playground
playground/ is a Nuxt 4 + Pinia app that scans itself through the dev route and
shows core files, component usage, unreferenced files, the generated Markdown and
the token budget.
npm install
npm run build # the playground loads the built module from ../dist
npm run dev # http://localhost:3000
Development
npm install
npm run build # unbuild → dist/ (module, core, CLI args, runtime)
npm test # vitest (JS) + Python unittest suite
npm run typecheck # tsc --noEmit
src/module.ts defineNuxtModule: runtime config, plugin, dev route, hooks
src/core/ Python resolution, analyzer bridge, config loading, init
src/cli/args.ts argument parser behind bin/cli.js
src/runtime/ plugin, useLLMContext(), dev scan route
bin/cli.js standalone CLI
analyzer/ Python engine (scan → parse → graph → report)
analyzer/tests/ unittest suites + fixture Nuxt apps
test/ vitest: arg parsing, config loading, Python bridge
The suites cover the failure modes that actually showed up during development:
empty <button> templates being mistaken for BaseButton.vue, pages/index.vue
mapping to /pages, auto-registered plugins reported as dead code, negated
excludes being ignored, and a 120-token budget still emitting 360 tokens.
Troubleshooting
"Python 3.9+ is required … could not be found" — set an interpreter explicitly:
pythonPath in llmContext, --python /path/to/python3, or LLM_CONTEXT_PYTHON.
Offline machines cannot use the uv bootstrap.
includePatterns matched no files — the include globs exclude everything except
nuxt.config; check the patterns or drop --include.
The dev endpoint returns 500 after a rebuild — restart nuxt dev; Nitro caches
the module's handler paths, and a rebuild replaces them.
Generated file is larger than expected — lower maxTokens. Sections are dropped
in order (structure → routes → usage → conventions → ignores) until it fits, with a
floor of the header, summary and three core files.
Notes and limits
- Python is required; the uv bootstrap needs network access the first time.
- The parser is heuristic, not a compiler: imports built from variables and components registered at runtime are not resolved.
.llmignoreis read from the project root only.AGENTS.mdis written only when it does not exist, so an existing agent file is never clobbered.- With
writeAgents, runscanafter large refactors so the map stays honest.
MIT
Explore related projects
Loading…