Overview
Context attachment allows you to:- Include specific files or entire folders in conversations
- Mention files using
@filenamesyntax - Configure character budgets (200 - 250,000 chars)
- View token estimates before sending
- Store context manifest with conversation history
How Context Works
- Attach: Select files or folders to include
- Build: Glyph reads and concatenates content
- Budget: Content is truncated to fit character budget
- Estimate: View token estimates (chars ÷ 4)
- Send: Context sent in system message
- Store: Manifest saved with conversation history
Attaching Context
Via Context Menu
Search for Files/Folders
Type to filter the index:
- Files: Individual notes (e.g.,
roadmap.md) - Folders: Entire directories (e.g.,
projects/) - Space: Root folder (all files)
Select Attachments
Click files or folders to attach. Selected items appear in the attached context list.
Via @mentions
Type@ in your message to mention files:
- Detects the
@mention - Searches the file index
- Attaches the file to context
- Removes the
@mentionfrom your message
Context Index
Glyph maintains an in-memory index of your space:Indexing
- When: On AI panel open
- What: All files and folders in your space
- Excludes: Hidden files (
.gitignore,.env, etc.),node_modules - Limit: Up to 20,000 files
Structure
Fromsrc-tauri/src/ai_rig/context.rs:174:
Character Budget
Control how much context to include:Default Budget
- Default: 12,000 characters (~3,000 tokens)
- Minimum: 200 characters
- Maximum: 250,000 characters (~62,500 tokens)
Adjusting Budget
In the context menu, adjust the character budget slider or input:- Lower budget: Faster, cheaper, may truncate important content
- Higher budget: More complete context, slower, more expensive
How Budget is Applied
- Files and folders are processed in order
- Each item’s content is read and formatted
- If content exceeds remaining budget, it’s truncated with
…(truncated)suffix - Truncated items marked in manifest with
truncated: true
Context Payload Format
Glyph formats attached context as:- Folder headers mark directory attachments
- File headers show relative paths
- Content separated by
---dividers - Sent in system message or user message depending on provider
Context Manifest
The manifest provides transparency into context composition.Manifest Structure
Fromsrc-tauri/src/ai_rig/context.rs:42:
Viewing Manifest
In the AI panel:- Attach context
- Click View Manifest or expand context section
- See breakdown of attached items
Manifest Storage
Manifests are stored with conversation history:Token Estimation
Glyph estimates tokens using:tokens ≈ characters ÷ 4
This is a rough estimate. Actual tokenization varies by model. GPT-4 may use ~3 chars/token, Claude ~4 chars/token.
Cost Estimation
Use token estimates to calculate costs:- Check manifest token estimate
- Look up model pricing (input tokens)
- Calculate:
tokens × (price / 1M tokens)
- 12,000 chars = ~3,000 tokens
- GPT-4o input: $2.50 / 1M tokens
- Cost: 3,000 × (0.0075 (~$0.01)
Folder Attachments
Attaching a folder includes all files within it (recursively).Folder Behavior
- Recursive: All subdirectories included
- File limit: Up to 20,000 files per folder
- Sorting: Files sorted alphabetically
- Excludes: Hidden files and
node_modules
Example
Attachingprojects/ folder:
- Folder header:
# Folder: projects projects/glyph/roadmap.mdprojects/glyph/tasks.mdprojects/notes/2024-01-15.md
File Limits
Per-File Limits
When reading files for context:- Max file size: No hard limit (entire file read)
- Character budget: Shared across all files
- UTF-8 only: Binary files skipped
Total Limits
- Character budget: 200 - 250,000 chars
- File count: Up to 20,000 files per folder
- Memory: Limited by character budget, not file count
Security and Privacy
Path Safety
- ✅ All paths restricted to current space
- ❌ Path traversal blocked (
../not allowed) - ❌ Hidden files excluded (files starting with
.) - ❌ Symlinks outside space blocked
src-tauri/src/ai_rig/context.rs:83:
No Secrets in Context
Use Cases
Research and Summarization
Scenario: Summarize all notes from a project.projects/glyph/ and provides a summary.
Question Answering
Scenario: Answer a specific question about your notes.Content Generation
Scenario: Generate content based on existing notes.Comparison
Scenario: Compare two documents.Best Practices
Start Small
- Begin with specific files
- Attach folders only when necessary
- Use @mentions for targeted context
Review Manifest
- Check token estimates before sending
- Ensure no truncation of critical content
- Adjust budget if items are truncated
Be Specific
- Attach only relevant files
- Avoid attaching entire space unless needed
- Use folders for related content groups
Monitor Costs
- Large contexts = higher costs
- Free tier models may have stricter limits
- Ollama (local) has no token costs
Troubleshooting
”Context index failed to load”
Cause: Error reading file tree. Solution: Ensure space is open and accessible.Files not appearing in context menu
Possible causes:- File is hidden (starts with
.) - File is in
node_modules - File index hasn’t loaded yet
@mention not working
Cause: File not in index or typo in filename. Solution:- Use context menu to verify file path
- Ensure exact filename match (case-sensitive)
- Use autocomplete if available
Context truncated unexpectedly
Cause: Character budget too low. Solution: Increase character budget in context settings.”Total chars exceeds budget”
Cause: Attached files exceed 250K character limit. Solution:- Remove some attachments
- Attach specific files instead of large folders
- Split into multiple conversations
History and Audit
Context is preserved in conversation history:Storage Location
History Structure
Reviewing History
In AI panel:- Click History
- Select a past conversation
- View messages, context manifest, and tool usage
- Resume conversation or start new based on context
Next Steps
Chat Modes
Learn about chat vs create modes
AI Setup
Configure AI profiles and models
Profiles
Manage multiple AI configurations
Providers
Provider-specific guides