Overview
This section covers advanced CLI usage including export/import operations, scripting patterns, environment variables, and automation workflows. The CLI is designed to work seamlessly with shell scripts and other tools.
Export and Import
Backup, migrate, and transfer memories between accounts or environments.
Export
# Export all memories to JSON
trix export > backup.json
# Export with format
trix export --format json --file memories.json
trix export --format markdown --file notes.md
trix export --format csv --file data.csv
# Export with filters
trix export --space work
trix export --tags important,project
trix export --since 30d
trix export --query "meeting notes"
# Compress output
trix export --format json | gzip > backup.json.gzImport
# Import memories from file
trix import backup.json
# Import with options
trix import memories.json --space imported
trix import memories.json --tags imported,2024
trix import memories.json --dry-run
trix import memories.json --force
# Import from stdin
cat backup.json | trix import -
# Import from compressed file
gunzip -c backup.json.gz | trix import -Export/Import Options
| Option | Description |
|---|---|
--format | Output format: json, markdown, csv |
--file | Write to file instead of stdout |
--space | Filter/target space |
--tags | Filter by tags (export) or add tags (import) |
--since | Export memories created since (e.g., 30d, 7d) |
--dry-run | Preview import without making changes |
--force | Overwrite existing memories on import |
Scripting Examples
The CLI is designed for scripting and automation:
Basic Scripting
#!/bin/bash
# Store conversation context
echo "$CONVERSATION" | trix remember - --space conversations --quiet
# Search and process results with jq
trix recall "user preferences" -o json | jq '.memories[].content'
# Get memory IDs only
MEMORY_IDS=$(trix memories list --id-only --space work)
# Loop through memories
for id in $MEMORY_IDS; do
trix memories get $id -o json
done
# Conditional based on search results
if trix recall "api key" --count > 0; then
echo "Found API keys"
fiPipeline Integration
# Import from another tool
cat exported-notes.txt | trix remember - --space imported
# Export and backup
trix export -o json | gzip > backup-$(date +%Y%m%d).json.gz
# Search and format
trix recall "action items" -o json | \
jq -r '.memories[] | "- \(.content)"' > todo.md
# Chain commands
trix recall "old notes" --id-only | trix weaken --batch
trix recall "deprecated" --id-only | trix forget - --forceAI Agent Integration
#!/bin/bash
# Inject context into LLM prompt
CONTEXT=$(trix context "user preferences" --max-tokens 2000 --format xml)
# Use in your LLM call
llm_response=$(your_llm_call "$CONTEXT" "$USER_QUERY")
# Store the response
echo "$llm_response" | trix remember - --tags response,agent --quietDaily Backup Script
#!/bin/bash
# Daily memory backup script
set -e
BACKUP_DIR="$HOME/trix-backups"
DATE=$(date +%Y-%m-%d)
# Create backup directory
mkdir -p "$BACKUP_DIR"
# Export all memories
trix export -o json --quiet > "$BACKUP_DIR/memories-$DATE.json"
# Keep only last 30 days
find "$BACKUP_DIR" -name "memories-*.json" -mtime +30 -delete
echo "Backup complete: $BACKUP_DIR/memories-$DATE.json"Cleanup Script
#!/bin/bash
# Clean up old and expired memories
set -e
echo "Cleaning up expired memories..."
trix forget --expired --force
echo "Tagging stale memories for review..."
# Tag memories that haven't been accessed in 90+ days
STALE_IDS=$(trix stale --days 90 --limit 500 -o json | jq -r '.[].id')
if [ -n "$STALE_IDS" ]; then
echo "$STALE_IDS" | trix batch tag - --add needs-review
echo "Tagged $(echo "$STALE_IDS" | wc -l) memories"
else
echo "No stale memories"
fi
echo "Done!"Environment Variables
Configure the CLI using environment variables:
| Variable | Description |
|---|---|
TRIX_API_KEY | API key for authentication |
TRIX_TOKEN | JWT token for session auth |
TRIX_API_URL | API endpoint URL |
TRIX_DEFAULT_SPACE | Default space for operations |
# Set up environment for scripting
export TRIX_API_KEY="gdb_your_api_key"
export TRIX_DEFAULT_SPACE="<space-uuid>"
# Use in scripts
#!/bin/bash
if [ -z "$TRIX_API_KEY" ]; then
echo "Error: TRIX_API_KEY not set"
exit 1
fi
trix remember "Automated note" --quietUse a .env file with tools like direnv to automatically load
environment variables when entering a project directory.
Output Formats
The CLI supports multiple output formats for different use cases:
# Table output (default, human-readable)
trix memories list
# JSON output (for scripting and jq)
trix memories list -o json
trix memories list -o json | jq '.[0]'
# YAML output
trix memories list -o yaml
# ID-only output (for piping)
trix memories list --id-only
# Count only
trix recall "query" --count
# No headers (for parsing)
trix memories list --no-headerjq Integration
The CLI has built-in jq filtering support:
# Filter with jq inline
trix recall "notes" --jq '.[].content'
trix memories list --jq 'map(select(.tags | contains(["important"])))'
trix jobs list --jq '[.[] | select(.status == "failed")]'
# Complex filtering
trix export -o json | jq '
.memories
| map(select(.created_at > "2026-01-01"))
| sort_by(.priority)
| reverse
| .[0:10]
'Cron Jobs
Automate tasks with cron:
# Edit crontab
crontab -e
# Daily backup at 2 AM
0 2 * * * /usr/local/bin/trix export -o json > /backups/trix-$(date +\%Y\%m\%d).json
# Clean expired memories weekly
0 3 * * 0 /usr/local/bin/trix forget --expired --force
# Sync from integration every hour
0 * * * * /home/user/scripts/trix-sync.sh >> /var/log/trix-sync.log 2>&1Make sure to use the full path to the trix binary in cron jobs, and set
the TRIX_API_KEY environment variable.
Debugging
Tools for troubleshooting CLI issues:
# Run diagnostics
trix doctor
# Verbose output
trix recall "query" -v # Verbose
trix recall "query" -vv # Debug
trix recall "query" -vvv # Trace
# Check authentication
trix auth status
trix whoami
# View current config
trix config list
# Test connectivity
trix version --checkDoctor Output
The trix doctor command checks:
- Configuration file validity
- API connectivity
- Authentication status
- Available updates
- Shell completion installation
Performance Tips
Use Batch Operations
For bulk operations, use batch commands instead of loops:
# Slow - one request per memory
for id in $IDS; do
trix reinforce $id
done
# Fast - single batch request
echo "$IDS" | trix reinforce --batchLimit Results
# Only fetch what you need
trix recall "query" --limit 5
trix memories list --limit 20Use ID-Only for Scripting
# Faster than parsing JSON
trix memories list --id-only | head -10Cache Context for Agents
# Cache context to avoid repeated API calls
CONTEXT=$(trix context "user info" --max-tokens 2000)
# Use $CONTEXT multiple times in your scriptSecurity Best Practices
- Never commit API keys - Use environment variables or secure vaults
- Use separate keys - Create different API keys for different environments
- Rotate keys regularly - Use
trix keys createandtrix keys delete - Limit key permissions - Create non-admin keys when full access isn't needed
- Set expiration - Use
--expiresfor temporary access
# Create a limited-time key for a script
trix keys create --name "backup-script" --expires 7d
# Store key securely (example with pass)
pass insert trix/backup-key
# Use in scripts
export TRIX_API_KEY=$(pass show trix/backup-key)
trix export > backup.jsonNext Steps
- MCP Server - Connect to AI assistants
- Daemon - Run Trix as a background service
- AI Agents - Build autonomous agents with memory
- Best Practices - Tips for memory management