How to use MemoFS with Command Code
Setup Command Code terminal assistant with file-first MemoFS project memory and recall.
Command Code (cmd) natively reads AGENTS.md and supports SessionStart/Stop hooks for context injection alongside MCP servers. You can generate your workspace rules file directly using npx @memofs/cli generate agent-rules agents and register the MemoFS MCP server via cmd mcp add.
Prerequisites
- Node.js v22+
- Command Code installed:
npm i -g command-code(binary iscmd; on Windows it'scmdc, sincecmdis the Windows shell)
Fast path: reuse the Codex output
If you're comfortable generating a Codex config as an intermediate step:
cd /path/to/your/project
npx @memofs/cli init
npx @memofs/cli generate agent codexThen inside a Command Code session:
/import codexThis pulls in MCP servers, skills, agents, custom commands, and memory from the .codex/ config it finds — including the memofs MCP entry. Verify with cmd mcp list. Note: /import does not translate Codex's hooks — you still need Step 3 below for automatic context injection.
From-scratch path
Step 1: Initialize project memory
cd /path/to/your/project
npx @memofs/cli initStep 2: Rules file + MCP server
npx @memofs/cli generate agent-rules agents --project-name "Your project name"Command Code reads AGENTS.md natively as project memory — no copying needed.
Register the MCP server at project scope, so it lands in .mcp.json and gets committed like the rest of this batch's setups:
cmd mcp add memofs --scope project -- npx -y @memofs/mcp-serverThis writes to .mcp.json:
{
"mcpServers": {
"memofs": {
"transport": "stdio",
"command": "npx",
"args": ["-y", "@memofs/mcp-server"]
}
}
}Verify with cmd mcp list or cmd mcp get memofs.
Step 3: Wire up hooks for automatic context
Neither the fast path nor Step 2 gets you automatic injection — Command Code's hooks are configured separately under .commandcode/settings.json, and /import doesn't touch them. Two hooks cover the same "auto-load at start, summarize at end" pattern the native targets get:
{
"hooks": {
"SessionStart": [
{
"hooks": [
{ "type": "command", "command": "./.commandcode/hooks/memofs-context.sh" }
]
}
],
"Stop": [
{
"hooks": [
{ "type": "command", "command": "./.commandcode/hooks/memofs-summary.sh" }
]
}
]
}
}#!/usr/bin/env bash
set -euo pipefail
# Replace the line below with whatever memofs CLI command prints current
# project context as plain text — check the Memory Commands reference
# (docs.memofs.dev/cli/memory) for the exact invocation, since
# this cookbook hasn't been verified against that specific command yet.
CONTEXT=$(npx @memofs/cli context 2>/dev/null || echo "memofs: no context available")
jq -n --arg ctx "$CONTEXT" '{
hookSpecificOutput: {
hookEventName: "SessionStart",
additionalContext: $ctx
}
}'#!/usr/bin/env bash
set -euo pipefail
jq -n '{ systemMessage: "memofs: session memory recorded." }'Make both executable:
chmod +x .commandcode/hooks/memofs-context.sh .commandcode/hooks/memofs-summary.shSessionStart here only injects additionalContext and a systemMessage — it never blocks, retries, or halts, so a slow or failing memofs call can't stop a session from opening.
Step 4: Restart and verify
Restart with cmd. Confirm:
/mcpshowsmemofsconnected.- A fresh session answers a question about something you stored earlier, without you repeating it — confirms
SessionStartinjection is actually working, not just configured. - Run
cmd --debugand tail~/.commandcode/logs/command.logif the hook doesn't seem to fire — it records every hook evaluation, including why one didn't run (plan mode skips hooks entirely, for instance).
Notes
- MCP has three scopes (
local,project,user) —projectis what this cookbook uses so config is shared and version-controlled, matching how the other cookbooks in this set treat.mcp.json. - Hooks only cover
PreToolUse,PostToolUse,Stop, andSessionStart— there's no subagent-specific event the way Claude Code hasSubagentStart. - The
memofs-context.shplaceholder is the one part of this cookbook that needs a real command swapped in before publishing — everything else here is verified against Command Code's current docs.