AI Agent Integration
Memex is designed for AI coding assistants. The CLI is the recommended interface.
Claude Code
Permission Setup
Add to .claude/settings.local.json:
{
"permissions": {
"allow": ["Bash(mx:*)"]
}
}
This grants Claude Code permission to run any mx command without prompting.
Session Hooks
For automatic context injection, use hooks:
{
"hooks": {
"SessionStart": [{ "hooks": [{ "type": "command", "command": "mx session-context" }] }]
}
}
Write the hook into .claude/settings.json:
mx session-context --install
The mx session-context command:
- Injects project-relevant KB context at session start
- Provides a concise workflow reminder plus related entries
Claude Code Plugin (Optional)
This repo ships a Claude Code plugin manifest in .claude-plugin/. From the repo
root, add the local marketplace and install the plugin:
/plugin marketplace add ./.claude-plugin/marketplace.json
/plugin install memex@memex
Restart Claude Code after installing or updating the plugin.
Workflow Pattern
# Before implementing: search KB for existing patterns
mx search "authentication patterns"
# During work: add discoveries for future sessions
mx add --title="OAuth2 Setup" --tags="auth,patterns" --category=patterns \
--content="..."
JSON Output vs JSON Errors (Important for Agents)
Many mx subcommands support --json, which controls success output formatting.
Errors are still human-readable text by default.
For machine-parseable errors with stable error codes, use the global flag:
# JSON error on stderr (with {"error": "...", "code": 1234, "message": "..."}):
mx --json-errors get nonexistent.md
# Success JSON on stdout, JSON errors on stderr:
mx --json-errors add --title="Entry" --tags="a,b" --content="..." --json
Notes:
--json-errorsis global, so it is best placed before the subcommand (the CLI also accepts it later and normalizes it).--json-errorsimplies a quieter "machine mode" (warnings are suppressed) to keep stderr parseable.
Codex CLI
Codex can use memex via shell commands in AGENTS.md:
## Knowledge Base
Search organizational knowledge before implementing:
- `mx search "query"` - Find existing patterns
- `mx get path/entry.md` - Read specific entry
- `mx add --title="..." --tags="..." --category=... --content="..."` - Add discoveries
Codex Skills (Optional)
This repo includes a Memex skill at skills/memex-kb-usage/. Codex loads skills from
$CODEX_HOME/skills (defaults to ~/.codex/skills). Copy or symlink the skill
into that directory and restart Codex.
Example:
mkdir -p ~/.codex/skills
cp -r skills/memex-kb-usage ~/.codex/skills/
Other AI Agents
Any agent with shell access can use the mx CLI.
Common Patterns
# Check for relevant knowledge before implementing
mx search "deployment strategies"
# Add discoveries for future sessions
mx add --title="API Rate Limiting" \
--tags="api,patterns" \
--category=patterns \
--content="..."
# View recent project KB updates
mx whats-new --scope=project --days=7
# Quick status check
mx info
Search Strategy
- Before implementing: Search for existing patterns
- When stuck: Search for troubleshooting guides
- After solving: Add solution to KB
When to Search KB
- Looking for organizational patterns or guides
- Before implementing something that might exist
- Understanding infrastructure or deployment
- Troubleshooting known issues
When to Contribute
- Discovered reusable pattern or solution
- Troubleshooting steps worth preserving
- Infrastructure or deployment knowledge
- Project-specific conventions
Project Configuration
Configure project-specific KB settings in .kbconfig:
# In your project directory
cat <<'EOF' > .kbconfig
kb_path: ./kb
primary: design
boost_paths:
- design/*
default_tags:
- memex
EOF
This .kbconfig file:
- Points
mxat the project KB (kb_path) - Routes new entries to
projects/<name>by default (primary) - Boosts project entries in search results (
boost_paths) - Suggests project-specific tags (
default_tags)
Best Practices
- Search before creating - Avoid duplicate entries
- Tag consistently - Use
mx tagsto see existing tags - Link related entries - Use
[[path/to/entry]]syntax - Keep entries focused - One topic per entry
- Update, don't duplicate - Append to existing entries