Overview
The CLI provides utilities for AI agents and automation workflows. The context command
retrieves memories formatted for LLM prompt injection, while watch monitors
memories in real-time.
context Command
Get memories formatted for injection into LLM prompts. Designed for AI agents and automation.
Basic Usage
# Get context for a query
trix context "user preferences"
# Limit to token budget
trix context "project info" --max-tokens 2000
# Filter by space
trix context "api docs" --space backend
# Limit number of memories
trix context "recent notes" --limit 5
# Set minimum similarity score
trix context "api docs" --min-score 0.5Output Formats
The context command supports multiple output formats for different use cases:
| Format | Description | Use Case |
|---|---|---|
plain | Raw content, newline-separated | Default, simple injection (default) |
xml | XML-tagged format | Structured parsing, Claude XML tags |
numbered | Numbered list with IDs | Reference tracking, citations |
markdown | Markdown with headers | Human-readable documentation |
claude | Claude-optimized XML tags | Prompt injection for Anthropic models |
openai | OpenAI message-array format | System/context blocks for GPT prompts |
json | Structured JSON payload | Programmatic consumption |
# Plain format (default)
trix context "api docs" --format plain
# XML format for structured parsing
trix context "api docs" --format xml
# Numbered for reference tracking
trix context "recent notes" --format numbered
# Markdown for documentation
trix context "project info" --format markdownToken Management
Control output size with token budgets to stay within LLM context limits:
# Limit to ~2000 tokens (approximately 8000 characters)
trix context "project context" --max-tokens 2000
# Combine with memory limit
trix context "api docs" --max-tokens 4000 --limit 10
# Token estimation uses ~4 chars per token
# Actual tokens may vary by LLM tokenizerToken estimation uses approximately 4 characters per token. Actual token counts may vary depending on the LLM tokenizer (GPT, Claude, etc.).
Scripting with Context
# Use in bash scripts
CONTEXT=$(trix context "user preferences" --max-tokens 1000)
echo "Based on this context: $CONTEXT"
# Pipe to LLM CLI
trix context "api docs" | llm "Summarize these API docs"
# Combine with other tools
trix context "recent errors" --format xml > context.xml
# Silent operation (no spinner, returns empty for no results)
PREFS=$(trix context "preferences" --max-tokens 500)
if [ -n "$PREFS" ]; then
echo "Found preferences: $PREFS"
fiThe context command is designed for silent, agent-friendly operation. It doesn't show spinners and returns empty output (not an error) when no memories are found.
context Options
| Option | Description | Default |
|---|---|---|
--max-tokens | Maximum approximate tokens (0 = unlimited) | 0 |
--format, -f | Output format: plain, xml, numbered, markdown, claude, openai, json | plain |
--space, -s | Search within specific space | default |
--limit, -l | Maximum memories to include | 10 |
--min-score | Minimum similarity score (0.0-1.0) | 0.3 |
--with-graph | Include relationship graph summary between retrieved memories (use --with-graph=false to disable) | true |
Relationship Graph
Include a summary of relationships between retrieved memories with the --with-graph flag.
This helps AI agents understand how memories connect to each other.
# Include relationship graph
trix context "architecture decisions" --with-graph
# With XML format for structured parsing
trix context "api docs" --format xml --with-graph
# Limit results but show their connections
trix context "project info" --limit 5 --with-graphThe relationship graph summary shows connections like supports, references, derived_from, and contradicts between the retrieved memories. This
context helps AI agents understand the knowledge structure and make more informed responses.
watch Command
Monitor memories in real-time as they're created. Useful for live dashboards, monitoring, and event-driven workflows.
Basic Usage
# Watch all new memories
trix watch
# Watch specific space
trix watch --space work
# Watch for tagged memories
trix watch --tags alert,important
# Watch with custom interval
trix watch --interval 10s
# Press Ctrl+C to stop watchingOutput Formats
| Format | Description |
|---|---|
brief | Compact single-line format (default) |
full | Complete memory details |
json | JSON format for piping to other tools |
# Brief format (default)
trix watch --format brief
# Full details
trix watch --format full
# JSON for piping
trix watch --format json | jq '.content'Filtering
# Watch specific space only
trix watch --space alerts
# Watch for specific tags
trix watch --tags error,critical
# Combine filters
trix watch --space production --tags error --interval 3s
# Minimum interval is 1 second
trix watch --interval 1sUse Cases
- Live Dashboard: Display new memories on a screen or dashboard
- Alerting: Watch for memories tagged "alert" or "error"
- Event-Driven: Trigger actions when new memories appear
- Monitoring: Track activity in specific spaces or projects
- Integration: Pipe to other tools for processing
# Pipe to notification system
trix watch --tags alert --format json | \
jq -r '.content' | \
xargs -I {} notify-send "Trix Alert" "{}"
# Log to file
trix watch --space production > production.log
# Trigger actions
trix watch --tags deploy --format json | \
while read -r line; do
echo "$line" | jq '.content' | bash
doneThe watch command polls the API at regular intervals. Be mindful of polling frequency to avoid excessive API calls. The minimum interval is 1 second.
watch Options
| Option | Description | Default |
|---|---|---|
--space, -s | Watch specific space | all spaces |
--tags, -t | Filter by tags (comma-separated) | all tags |
--interval, -i | Polling interval (min: 1s) | 5s |
--format, -f | Output format: brief, full, json | brief |
Integration Examples
AI Agent Workflow
#!/bin/bash
# Example: AI agent with Trix context
# Get relevant context for user query
USER_QUERY="How do I authenticate?"
CONTEXT=$(trix context "$USER_QUERY" --max-tokens 2000 --format xml)
# Inject into LLM prompt
PROMPT="<context>$CONTEXT</context>
<query>$USER_QUERY</query>
Answer the user's query using the provided context."
# Send to LLM (example with llm CLI)
echo "$PROMPT" | llmEvent-Driven Automation
#!/bin/bash
# Example: React to new memories with specific tags
trix watch --tags deploy --format json | while read -r memory; do
CONTENT=$(echo "$memory" | jq -r '.content')
ID=$(echo "$memory" | jq -r '.id')
echo "New deployment memory detected: $ID"
echo "Content: $CONTENT"
# Trigger deployment pipeline
./deploy.sh "$CONTENT"
# Update memory with result
trix mem update "$ID" --tags "deploy,processed"
doneContext Caching for Performance
#!/bin/bash
# Example: Cache context to reduce API calls
CACHE_FILE="/tmp/trix-context.cache"
CACHE_TTL=300 # 5 minutes
# Check if cache exists and is fresh
if [ -f "$CACHE_FILE" ] && \
[ $(($(date +%s) - $(stat -c %Y "$CACHE_FILE"))) -lt $CACHE_TTL ]; then
CONTEXT=$(cat "$CACHE_FILE")
else
# Refresh cache
CONTEXT=$(trix context "project knowledge" --max-tokens 4000)
echo "$CONTEXT" > "$CACHE_FILE"
fi
# Use cached context
echo "Using context: $CONTEXT"Next Steps
- AI-CLI Integration - Auto-capture from Claude Code CLI
- Templates - Create reusable templates
- Daemon - Run Trix as a background service
- Import & Export - Bulk data operations