[FEATURE]: Smart Project Analysis + Proactive Slash Commands — Tools that give OpenCode deep codebase awareness and seamless workflow automation #8137

Open
opened 2026-02-16 18:09:15 -05:00 by yindo · 1 comment
Owner

Originally created by @Just-mpm on GitHub (Jan 31, 2026).

Originally assigned to: @thdxr on GitHub.

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

🔍 Tool: analyze

What it does: Intelligent dependency analysis, impact prediction, and functional area detection for
TypeScript/JavaScript projects.

How it works:

  • Wraps the @justmpm/ai-tool package (powered by Skott + Knip + ts-morph)
  • Builds a dependency graph of the entire project
  • Categorizes files by technical type: page, layout, route, component, hook, service, store, util, type, config, test
  • Auto-detects functional areas/domains (auth, dashboard, payments, etc.) by analyzing file paths, naming patterns,
    and keywords
  • Caches results in .analyze/ for instant subsequent loads

Commands (no target required):
┌────────────┬────────────────────────────────────────────────────────────────────┐
│ Command │ What it does │
├────────────┼────────────────────────────────────────────────────────────────────┤
│ map │ Generates project structure map organized by technical category │
├────────────┼────────────────────────────────────────────────────────────────────┤
│ dead │ Detects orphan files and unused exports (dead code) │
├────────────┼────────────────────────────────────────────────────────────────────┤
│ areas │ Lists all detected functional domains in the project │
├────────────┼────────────────────────────────────────────────────────────────────┤
│ areas-init │ Generates .analyze/areas.config.json for manual area configuration │
└────────────┴────────────────────────────────────────────────────────────────────┘
Commands (target required):
┌────────────────┬─────────────────────────────────────────────────────────────────────────────────┐
│ Command │ What it does │
├────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
│ suggest │ Lists files to read BEFORE modifying (based on dependency graph) │
├────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
│ impact │ Shows upstream/downstream dependencies — who uses this file and what it imports │
├────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
│ context │ Extracts function/type signatures WITHOUT implementation (API overview) │
├────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
│ area │ Shows all files belonging to a specific functional area │
└────────────────┴─────────────────────────────────────────────────────────────────────────────────┘
Key distinction:

  • Category = technical type (hook, component, page) → use map
  • Area = functional domain (auth, stripe, dashboard) → use areas
  • A single file can belong to multiple areas

Why it matters: The model understands project structure before acting. Instead of blindly reading files, it knows
exactly what to read first and who will be affected by changes. This reduces unnecessary file reads and prevents
breaking changes.


Tool: commands

What it does: Enables the model to discover and execute user-defined slash commands proactively.

How it works:

  • On initialization, scans ~/.config/opencode/command/.md and .opencode/command/.md
  • Parses YAML frontmatter from each file (description, argument-hint)
  • Dynamically generates tool description listing all available commands
  • The model sees the complete list and can invoke any command by name

Technical details:

  • Commands are Markdown files with YAML frontmatter containing metadata
  • The $ARGUMENTS placeholder in command templates gets replaced with passed arguments
  • Project-level commands (.opencode/command/) override global commands with the same name
  • New commands appear automatically on next session — no code changes needed

Example model invocations:
commands({ command: "audit", arguments: "src/components --diff" })
commands({ command: "fix", arguments: "1.md --critical" })
commands({ command: "scan" })

Why it matters: Users don't need to remember to type /audit or /fix. The model recognizes intent and executes the
right command automatically. This enables complex multi-step workflows to run seamlessly.


🔌 Plugin: analyze-context

What it does: Automatically injects project structure into the system prompt when a session starts.

How it works:

  • Uses the experimental.chat.system.transform hook to inject context cleanly
  • Reads cached data from .analyze/ directory (generated by analyze map)
  • Formats file map with category icons and folder organization
  • Calculates a hash of all source file timestamps to detect staleness
  • Warns if cache is outdated and suggests regenerating
  • Detects and displays circular dependencies as warnings

What the model sees:
📊 Project Structure (cache: 2h ago)

Summary: 142 files in 28 folders

By category:
🧩 component: 45 | 🪝 hook: 23 | 📄 page: 18 | ⚙️ service: 12 | ...

📁 src/components/
🧩 Button.tsx
🧩 Modal.tsx
🪝 useDialog.ts

📁 src/hooks/
🪝 useAuth.ts
🪝 useFetch.ts
...

Why it matters: The model starts every session already knowing the project structure. No need to run map manually —
context is there from the first prompt. This dramatically improves first-response quality.


Summary for GitHub

Two tools + one plugin that give OpenCode deep project awareness:

  1. analyze — Static analysis powered by Skott + Knip + ts-morph. Builds dependency graphs, detects functional areas,
    and predicts impact before changes. Model knows what files to read and who gets affected.
  2. commands — Dynamic slash command discovery with proactive execution. Model sees all user-defined commands and can
    invoke them without user typing /. List updates automatically when new commands are added.
  3. analyze-context (plugin) — Auto-injects cached project structure into system prompt on session start. Zero setup,
    instant context awareness.

Result: Smarter context gathering, fewer wasted file reads, accurate impact prediction, and seamless automation of
user workflows.


Installation

Clone

git clone https://github.com/Just-mpm/ai-tools-opencode.git

Copy tools

cp tools/analyze.ts ~/.config/opencode/tools/
cp tools/commands.ts ~/.config/opencode/tools/

Copy plugin

cp plugins/analyze-context.ts ~/.config/opencode/plugins/

Originally created by @Just-mpm on GitHub (Jan 31, 2026). Originally assigned to: @thdxr on GitHub. ### Feature hasn't been suggested before. - [x] I have verified this feature I'm about to request hasn't been suggested before. ### Describe the enhancement you want to request 🔍 Tool: analyze What it does: Intelligent dependency analysis, impact prediction, and functional area detection for TypeScript/JavaScript projects. How it works: - Wraps the @justmpm/ai-tool package (powered by Skott + Knip + ts-morph) - Builds a dependency graph of the entire project - Categorizes files by technical type: page, layout, route, component, hook, service, store, util, type, config, test - Auto-detects functional areas/domains (auth, dashboard, payments, etc.) by analyzing file paths, naming patterns, and keywords - Caches results in .analyze/ for instant subsequent loads Commands (no target required): ┌────────────┬────────────────────────────────────────────────────────────────────┐ │ Command │ What it does │ ├────────────┼────────────────────────────────────────────────────────────────────┤ │ map │ Generates project structure map organized by technical category │ ├────────────┼────────────────────────────────────────────────────────────────────┤ │ dead │ Detects orphan files and unused exports (dead code) │ ├────────────┼────────────────────────────────────────────────────────────────────┤ │ areas │ Lists all detected functional domains in the project │ ├────────────┼────────────────────────────────────────────────────────────────────┤ │ areas-init │ Generates .analyze/areas.config.json for manual area configuration │ └────────────┴────────────────────────────────────────────────────────────────────┘ Commands (target required): ┌────────────────┬─────────────────────────────────────────────────────────────────────────────────┐ │ Command │ What it does │ ├────────────────┼─────────────────────────────────────────────────────────────────────────────────┤ │ suggest <file> │ Lists files to read BEFORE modifying (based on dependency graph) │ ├────────────────┼─────────────────────────────────────────────────────────────────────────────────┤ │ impact <file> │ Shows upstream/downstream dependencies — who uses this file and what it imports │ ├────────────────┼─────────────────────────────────────────────────────────────────────────────────┤ │ context <file> │ Extracts function/type signatures WITHOUT implementation (API overview) │ ├────────────────┼─────────────────────────────────────────────────────────────────────────────────┤ │ area <name> │ Shows all files belonging to a specific functional area │ └────────────────┴─────────────────────────────────────────────────────────────────────────────────┘ Key distinction: - Category = technical type (hook, component, page) → use map - Area = functional domain (auth, stripe, dashboard) → use areas - A single file can belong to multiple areas Why it matters: The model understands project structure before acting. Instead of blindly reading files, it knows exactly what to read first and who will be affected by changes. This reduces unnecessary file reads and prevents breaking changes. --- ⚡ Tool: commands What it does: Enables the model to discover and execute user-defined slash commands proactively. How it works: - On initialization, scans ~/.config/opencode/command/*.md and .opencode/command/*.md - Parses YAML frontmatter from each file (description, argument-hint) - Dynamically generates tool description listing all available commands - The model sees the complete list and can invoke any command by name Technical details: - Commands are Markdown files with YAML frontmatter containing metadata - The $ARGUMENTS placeholder in command templates gets replaced with passed arguments - Project-level commands (.opencode/command/) override global commands with the same name - New commands appear automatically on next session — no code changes needed Example model invocations: commands({ command: "audit", arguments: "src/components --diff" }) commands({ command: "fix", arguments: "1.md --critical" }) commands({ command: "scan" }) Why it matters: Users don't need to remember to type /audit or /fix. The model recognizes intent and executes the right command automatically. This enables complex multi-step workflows to run seamlessly. --- 🔌 Plugin: analyze-context What it does: Automatically injects project structure into the system prompt when a session starts. How it works: - Uses the experimental.chat.system.transform hook to inject context cleanly - Reads cached data from .analyze/ directory (generated by analyze map) - Formats file map with category icons and folder organization - Calculates a hash of all source file timestamps to detect staleness - Warns if cache is outdated and suggests regenerating - Detects and displays circular dependencies as warnings What the model sees: 📊 Project Structure (cache: 2h ago) ✅ Summary: 142 files in 28 folders By category: 🧩 component: 45 | 🪝 hook: 23 | 📄 page: 18 | ⚙️ service: 12 | ... 📁 src/components/ 🧩 Button.tsx 🧩 Modal.tsx 🪝 useDialog.ts 📁 src/hooks/ 🪝 useAuth.ts 🪝 useFetch.ts ... Why it matters: The model starts every session already knowing the project structure. No need to run map manually — context is there from the first prompt. This dramatically improves first-response quality. --- Summary for GitHub Two tools + one plugin that give OpenCode deep project awareness: 1. analyze — Static analysis powered by Skott + Knip + ts-morph. Builds dependency graphs, detects functional areas, and predicts impact before changes. Model knows what files to read and who gets affected. 2. commands — Dynamic slash command discovery with proactive execution. Model sees all user-defined commands and can invoke them without user typing /. List updates automatically when new commands are added. 3. analyze-context (plugin) — Auto-injects cached project structure into system prompt on session start. Zero setup, instant context awareness. Result: Smarter context gathering, fewer wasted file reads, accurate impact prediction, and seamless automation of user workflows. --- Installation # Clone git clone https://github.com/Just-mpm/ai-tools-opencode.git # Copy tools cp tools/analyze.ts ~/.config/opencode/tools/ cp tools/commands.ts ~/.config/opencode/tools/ # Copy plugin cp plugins/analyze-context.ts ~/.config/opencode/plugins/
yindo added the discussion label 2026-02-16 18:09:15 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 31, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #10300: [FEATURE]:Inter-Project Context Bridging: Enable LLM Collaboration Across Sessions (similar goal of providing codebase context awareness and cross-session intelligence)
  • #10096: [FEATURE]: Smart Rules - Context-aware instruction injection with Claude Code compatibility (addresses context injection into system prompts based on file patterns, similar to the analyze-context plugin approach)
  • #5895: [FEATURE]: On-idle background processing (relates to proactive automation and background task execution when system is idle)
  • #8868: Agents and Commands are not shown (relevant to command discovery and loading system)

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 31, 2026): This issue might be a duplicate of existing issues. Please check: - #10300: [FEATURE]:Inter-Project Context Bridging: Enable LLM Collaboration Across Sessions (similar goal of providing codebase context awareness and cross-session intelligence) - #10096: [FEATURE]: Smart Rules - Context-aware instruction injection with Claude Code compatibility (addresses context injection into system prompts based on file patterns, similar to the analyze-context plugin approach) - #5895: [FEATURE]: On-idle background processing (relates to proactive automation and background task execution when system is idle) - #8868: Agents and Commands are not shown (relevant to command discovery and loading system) Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8137