@@ -85,10 +85,11 @@ Help users add project patterns using Project Intelligence standard. **Easiest w
8585## Usage
8686
8787``` bash
88- /add-context # Interactive wizard (recommended)
88+ /add-context # Interactive wizard (recommended, saves to project )
8989/add-context --update # Update existing context
9090/add-context --tech-stack # Add/update tech stack only
9191/add-context --patterns # Add/update code patterns only
92+ /add-context --global # Save to global config (~/.config/opencode/) instead of project
9293```
9394
9495---
@@ -98,11 +99,13 @@ Help users add project patterns using Project Intelligence standard. **Easiest w
9899** Run** : ` /add-context `
99100
100101** What happens** :
101- 1 . Checks for external context files in ` .tmp/ ` (if found, offers to extract)
102- 2 . Checks for existing project intelligence
103- 3 . Asks 6 questions (~ 5 min) OR reviews existing patterns
104- 4 . Generates/updates technical-domain.md
105- 5 . Agents now use YOUR patterns
102+ 1 . Saves to ` .opencode/context/project-intelligence/ ` in your project (always local)
103+ 2 . Checks for external context files in ` .tmp/ ` (if found, offers to extract)
104+ 3 . Checks for existing project intelligence
105+ 4 . Asks 6 questions (~ 5 min) OR reviews existing patterns
106+ 5 . Shows full preview of files to be created before writing
107+ 6 . Generates/updates technical-domain.md + navigation.md
108+ 7 . Agents now use YOUR patterns
106109
107110** 6 Questions** (~ 5 min):
1081111 . Tech stack?
@@ -124,6 +127,23 @@ Help users add project patterns using Project Intelligence standard. **Easiest w
124127
125128## Workflow
126129
130+ ### Stage 0.5: Resolve Context Location
131+
132+ Determine where project intelligence files should be saved. This runs BEFORE anything else.
133+
134+ ** Default behavior** : Always use local ` .opencode/context/project-intelligence/ ` .
135+ ** Override** : ` --global ` flag saves to ` ~/.config/opencode/context/project-intelligence/ ` instead.
136+
137+ ** Resolution:**
138+ 1 . If ` --global ` flag → ` $CONTEXT_DIR = ~/.config/opencode/context/project-intelligence/ `
139+ 2 . Otherwise → ` $CONTEXT_DIR = .opencode/context/project-intelligence/ ` (always local)
140+
141+ ** If ` .opencode/context/ ` doesn't exist yet** , create it silently — no prompt needed. The directory structure is part of the output shown in Stage 4.
142+
143+ ** Variable** : ` $CONTEXT_DIR ` is set here and used in all subsequent stages.
144+
145+ ---
146+
127147### Stage 0: Check for External Context Files
128148
129149Check: ` .tmp/ ` directory for external context files (e.g., ` .tmp/external-context.md ` , ` .tmp/context-*.md ` )
@@ -180,7 +200,7 @@ Ready to harvest? [y/n]: _
180200
181201### Stage 1: Detect Existing Context
182202
183- Check: ` ~/.opencode/context/project-intelligence/ `
203+ Check: ` $CONTEXT_DIR ` (set in Stage 0.5 — either ` .opencode/context/project-intelligence/ ` or ` ~/.config/ opencode/context/project-intelligence/ ` )
184204
185205** If exists** :
186206```
@@ -206,18 +226,41 @@ Current patterns:
206226Options:
207227 1. Review and update patterns (show each one)
208228 2. Add new patterns (keep all existing)
209- 3. Replace all patterns (start fresh, backup old )
229+ 3. Replace all patterns (start fresh)
210230 4. Cancel
211231
212232Choose [1/2/3/4]: _
213233```
214234
235+ ** If user chooses 3 (Replace all):**
236+ ```
237+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
238+ Replace All: Preview
239+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
240+
241+ Will BACKUP existing files to:
242+ .tmp/backup/project-intelligence-{timestamp}/
243+ ← technical-domain.md (Version: 1.2)
244+ ← business-domain.md (Version: 1.0)
245+ ← navigation.md
246+
247+ Will DELETE and RECREATE:
248+ $CONTEXT_DIR/technical-domain.md (new Version: 1.0)
249+ $CONTEXT_DIR/navigation.md (new Version: 1.0)
250+
251+ Existing files backed up → you can restore from .tmp/backup/ if needed.
252+
253+ Proceed? [y/n]: _
254+ ```
255+
215256** If not exists** :
216257```
217258━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
218259No project intelligence found. Let's create it!
219260━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
220261
262+ Saving to: $CONTEXT_DIR
263+
221264Will create:
222265 - project-intelligence/technical-domain.md (tech stack & patterns)
223266 - project-intelligence/navigation.md (quick overview)
@@ -485,7 +528,7 @@ Preview: technical-domain.md
485528Size : {line_count } lines (limit : 200 per @mvi_compliance )
486529Status : ✅ MVI compliant
487530
488- Save to : ~ / . opencode / context / project - intelligence / technical - domain .md
531+ Save to : $CONTEXT_DIR / technical - domain .md
489532
490533Looks good ? [y / n / edit ]: _
491534` ` `
@@ -511,12 +554,35 @@ Running validation...
511554✅ Version set : 1.0 (@version_tracking )
512555✅ MVI compliant (<30s scannable )
513556✅ No duplication
557+ ` ` `
558+
559+ **navigation.md preview** (also created/updated):
560+ ` ` `
561+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
562+ Preview : navigation .md
563+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
514564
515- Creating files per @project_intelligence ...
516- ✓ technical -domain .md
517- ✓ navigation .md (updated per @navigation_update )
565+ # Project Intelligence
518566
519- Done !
567+ | File | Description | Priority |
568+ | ------| -------------| ----------|
569+ | [technical -domain .md ](technical -domain .md ) | Tech stack & patterns | critical |
570+
571+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
572+ ` ` `
573+
574+ **Full creation plan**:
575+ ` ` `
576+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
577+ Files to write :
578+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
579+
580+ CREATE $CONTEXT_DIR /technical -domain .md ({line_count} lines )
581+ CREATE $CONTEXT_DIR /navigation .md ({nav_line_count} lines )
582+
583+ Total : 2 files
584+
585+ Proceed ? [y /n ]: _
520586` ` `
521587
522588---
@@ -529,9 +595,10 @@ Done!
529595━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
530596
531597Files created :
532- ~/. opencode / context / project - intelligence /technical -domain .md
533- ~/. opencode / context / project - intelligence /navigation .md
598+ $CONTEXT_DIR /technical -domain .md
599+ $CONTEXT_DIR /navigation .md
534600
601+ Location : $CONTEXT_DIR
535602Agents now use YOUR patterns automatically !
536603
537604━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -543,7 +610,7 @@ What's next?
543610 > " Create API endpoint"
544611 (Uses YOUR pattern ! )
545612
546- 2. Review : cat ~ / . opencode / context / project - intelligence / technical - domain .md
613+ 2. Review : cat $CONTEXT_DIR / technical - domain .md
547614
5486153. Add business context : / add - context -- business
549616
@@ -560,6 +627,18 @@ When you:
560627
561628Agents stay synced !
562629
630+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
631+ 💡 Tip : Global patterns
632+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
633+
634+ Want the same patterns across ALL your projects ?
635+ / add - context -- global
636+ → Saves to ~ / .config / opencode / context / project - intelligence /
637+ → Acts as fallback for projects without local context
638+
639+ Already have global patterns ? Bring them into this project :
640+ / context migrate
641+
563642━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
564643📚 Learn More
565644━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -593,7 +672,7 @@ Agents stay synced!
593672### Pattern Detection (Stage 1)
594673
595674**Process**:
596- 1. Check: `ls ~/.opencode/context/project-intelligence/`
675+ 1. Check: `ls $CONTEXT_DIR/` (path determined in Stage 0.5)
5976762. Read: `cat technical-domain.md` (if exists)
5986773. Parse existing patterns:
599678 - Frontmatter: version, updated date
@@ -822,16 +901,22 @@ Check code & retry.
822901A: Check file exists, <200 lines. Run `/context validate`
823902
824903**Q: See what's in context?**
825- A: `cat ~/.opencode/context/project-intelligence/technical-domain.md`
904+ A: `cat .opencode/context/project-intelligence/technical-domain.md` (local) or `cat ~/.config/ opencode/context/project-intelligence/technical-domain.md` (global)
826905
827906**Q: Multiple context files?**
828- A: Yes! Create in `~/.opencode/context/ project-intelligence/` . Agents load all.
907+ A: Yes! Create in your project-intelligence directory . Agents load all.
829908
830909**Q: Remove pattern?**
831- A: Edit directly: `nano ~/ .opencode/context/project-intelligence/technical-domain.md`
910+ A: Edit directly: `nano .opencode/context/project-intelligence/technical-domain.md`
832911
833912**Q: Share w/ team?**
834- A: Yes! Commit `~/.opencode/context/project-intelligence/` to repo.
913+ A: Yes! Use local install (`.opencode/context/project-intelligence/`) and commit to repo. Team members get your patterns automatically.
914+
915+ **Q: Local vs global?**
916+ A: Local (`.opencode/`) = project-specific, committed to git, team-shared. Global (`~/.config/opencode/`) = personal defaults across all projects. Local overrides global.
917+
918+ **Q: Installed globally but want project patterns?**
919+ A: Run `/add-context` (defaults to local). Creates `.opencode/context/project-intelligence/` in your project even if OAC was installed globally.
835920
836921**Q: Have external context files in .tmp/?**
837922A: Run `/context harvest` to extract and organize them into permanent context
0 commit comments