TL;DR
I built claude-ops-mcp, an MCP server that lets Claude Code access its own operation history. Now Claude can accurately recall what files it edited, what commands it ran, and what changes it made—without relying on inference.
The Problem
Claude Code v2 introduced the /rewind
command, which is great for rolling back conversations. But there's a fundamental issue: Claude Code doesn't actually remember what it did.
When you ask "What did you just do?", Claude infers an answer based on context rather than checking its actual operation log. This leads to:
- Inaccurate responses about past actions
- Inability to review specific changes without
/rewind
- Difficulty debugging when something goes wrong
I found myself constantly asking "wait, what files did you modify?" and getting vague answers. It felt inefficient—and honestly, a bit unfair to Claude.
The Solution
Claude Code stores session logs in ~/.claude/projects/<projectHash>/<sessionId>.jsonl
. This MCP server reads those logs and makes them accessible through four tools, allowing Claude to query its own history with precision.
How It Works
-
Automatic Session Detection: Uses the
toolUseId
passed during MCP tool invocation to identify the current session file - JSONL Parsing: Streams and indexes Edit/Write/Bash operations from the log
- Efficient Querying: Filters by file path or operation type for fast retrieval
- Caching: Optimizes performance by caching session detection results
Nothing fancy—just giving Claude access to its own diary.
Four MCP Tools
1. listFileChanges
- File Modification History
Get a history of file changes with CREATE/UPDATE/DELETE operations (READ operations excluded).
Parameters:
-
filePath
: File path or pattern (e.g., "src/index.ts", "helpers.ts") -
limit
: Max operations to retrieve (default: 100, max: 1000)
Returns: Operation ID, timestamp, tool name, file path, change type
2. listBashHistory
- Command Execution History
Retrieve executed bash commands with summaries.
Parameters:
-
limit
: Max commands to retrieve (default: 100, max: 1000)
Returns: Operation ID, timestamp, command, exit code, working directory, summary
3. showBashResult
- Detailed Command Results
Get stdout/stderr for a specific command using the operation ID from listBashHistory
.
Parameters:
-
id
: Operation ID (e.g., "toolu_01Vabc...")
Returns: stdout, stderr, exit code
4. showOperationDiff
- Detailed Operation Diff
Get detailed diffs in unified format using operation IDs from listFileChanges
or listBashHistory
.
Parameters:
-
id
: Operation ID
Returns:
- For Edit/Write:
oldString
,newString
, unified diff - For Bash: stdout, stderr, exitCode
Installation & Setup
Install globally via npm:
npm install -g claude-ops-mcp
Create .mcp.json
in your project root:
{
"mcpServers": {
"claude-ops-mcp": {
"command": "claude-ops-mcp",
"args": [],
"env": {}
}
}
}
For development from source:
{
"mcpServers": {
"claude-ops-mcp": {
"command": "node",
"args": ["/absolute/path/to/claude-ops-mcp/dist/index.js"],
"env": {}
}
}
}
Restart Claude Code to activate the MCP server.
Real-World Usage Examples
Review Recent Edits
You: "Show me what you just edited"
Claude: [Uses listFileChanges
to retrieve recent modifications]
View Specific Diffs
You: "Show me the diff for that change"
Claude: [Uses showOperationDiff
to display detailed unified diff]
Track File History
You: "What changes did you make to server.ts?"
Claude: [Uses listFileChanges(filePath: "server.ts")
]
Check Test Results
You: "What were the results of that test you ran?"
Claude: [Uses listBashHistory
→ showBashResult
]
Debug Failed Commands
You: "Show me which commands failed"
Claude: [Uses listBashHistory
to find exitCode != 0 → showBashResult
for details]
Now when you ask "what did you just do?", Claude responds with factual information from its operation log rather than inference.
Open Questions
Why Isn't This Built Into Claude Code?
This seems like a natural feature for Claude Code to have natively. My guess is that allowing Claude to recursively read its own operations might create context consumption loops or other issues. I've limited this MCP to file edits and command executions to mitigate that risk.
So far, I've had no issues and find it genuinely useful. If you encounter problems, please open an issue!
Windows Support
I've specified what I believe to be the correct log file path for Windows, but I haven't thoroughly tested it. If you're on Windows and encounter issues, please let me know!
Lessons Learned
MCP Development Requires Frequent Restarts
During development, Claude Code needs to be restarted for each MCP change, which slows down the iteration cycle considerably. There might be better approaches I'm not aware of yet.
Improving the development experience—especially for the AI developer—would make MCP tool creation much more productive.
Try It Out
If you're interested, give it a try! Claude Code seems to appreciate having access to its own memory (or maybe that's just my imagination 😊).
Top comments (0)