Repository navigation
Feature: Coding agent sidecar — watch session transcripts, build knowledge graph #669
Description
Activity
Claude finished @bm-clawd's task in 1m 24s —— View job
Issue Triage
- Read and analyze issue
- Check for duplicate issues
- Add appropriate labels
- Post triage analysis
Analysis
Type: Feature Request — new functionality (coding agent sidecar)
Priority: Medium — valuable capability for power users but not blocking existing functionality
Component: CLI + MCP — requires new
bm watch-sessionsCLI command; output becomes available via MCP toolsComplexity: Complex — major architectural addition involving:
- File watching infrastructure for multiple agent formats
- LLM-based extraction pipeline
- New transcript parsers (Claude Code JSONL, Codex JSON, etc.)
- Deduplication logic against existing knowledge graph
- Privacy/sensitive content filtering
- Session end detection heuristics
Duplicate check: No duplicate found. Closest related issues are #498 (BM reposwarm — multi-repo memory) and the existing
bm watchfunctionality, but this is a distinct new feature.
Triage Notes
This is a well-scoped and detailed spec. A few observations:
Strengths of the proposal:
- Zero-coupling design (file watching only, no agent hooks) is the right approach
- The phased implementation (Option A → B → C) is pragmatic
- Reusing existing BM observations/relations format keeps it consistent with the rest of the knowledge graph
- The comparison table vs. Letta is accurate — this approach is more portable and auditable
Key open questions that should be resolved before implementation:
-
Session end detection is the hardest unsolved problem. Claude Code sessions don't have explicit end markers — using file modification time threshold (e.g., "no writes for 5 minutes") is reasonable but imprecise for long pauses during a session. This needs a concrete decision.
-
LLM dependency — the extraction step requires an API call to an LLM. This adds a required external dependency and cost. Should the extraction be optional/configurable, or is it always required? A cheaper "no-LLM" mode (just log the session without extraction) could lower the barrier to entry.
-
Cross-project memory — the spec notes learnings should be visible across projects. The current BM project model is per-project; cross-project visibility would require either a shared "global" project or the sidecar writing to a designated shared project.
-
bm watch-sessionsvs. importer — Basic Memory already has an importer pattern (basic-memory import claude conversations). A session watcher is a live version of the same idea. It might be worth unifying these under the importer infrastructure rather than building parallel watching infrastructure.
Suggested next steps:
- Resolve session end detection approach
- Decide on the LLM dependency model (required vs. optional)
- Prototype the Claude Code JSONL extraction prompt with a few real sessions
- Consider whether
importinfrastructure can be extended for live watching
Labels added:
enhancement(others from the issue template not yet created in this repo)Related Research: OpenClaw-RL (Princeton, March 2026)
Paper: https://arxiv.org/abs/2603.10165 ("Train Any Agent Simply by Talking")
Key insight relevant to this issue: every agent interaction generates a "next-state signal" (user corrections, re-queries, tool outputs, error resolutions) that is currently thrown away. The paper argues this is the most valuable training data agents produce.
The sidecar's structured extraction of
[decision],[error_resolved],[pattern], and[learning]observations from coding sessions is capturing exactly these signals in plain text. We're building the dataset this paper says is most valuable — just storing it as a searchable knowledge graph instead of feeding it into a training loop.Future consideration: the structured session history BM builds could eventually serve as training data for agent improvement, not just recall. The architecture supports it.
Interesting feature idea. Related note: one of the biggest cost drivers in long Claude Code sessions is conversation history growing unbounded. A sidecar that watches transcripts could also help flag when context is getting expensive.
Key numbers:
- Input tokens are charged every turn (conversation history grows linearly)
- Crossing 200K input tokens doubles the rate on all tokens
- Output tokens cost 5x more than input
Some strategies for managing this: https://github.com/Sagargupta16/claude-cost-optimizer/blob/main/guides/02-context-optimization.md
SPEC: Coding Agent Sidecar
Summary
A file-watcher-based sidecar that observes coding agent session transcripts and ingests them as structured Basic Memory notes. No hooks, no plugins, no coupling to agent internals. Just watches files and builds a knowledge graph.
Problem
Coding agents (Claude Code, Codex, Cursor, OpenCode) forget everything between sessions. Solutions like Letta's claude-subconscious inject themselves into the agent's runtime — fragile, vendor-specific, opaque. CLAUDE.md is a single flat file with no structure or search.
Users need persistent, searchable, cross-agent memory that:
Approach
Watch session files → Extract knowledge → Write BM notes → Available via MCP
The sidecar never touches the coding agent. It reads session transcript files from disk, runs an extraction agent over them, and writes structured Basic Memory notes. The coding agent picks up that knowledge on its next session via BM's MCP server (already installed).
Session File Locations
~/.claude/sessions/~/.codex/sessions/Extraction Model
The extraction agent processes each session transcript and produces:
1. Session Summary Note
memory/sessions/YYYY-MM-DD-short-description.md2. Entity Updates
If the session references or modifies known entities (people, projects, architectural decisions), update existing notes:
3. Gotcha / Learning Notes
Reusable lessons extracted to their own notes:
Extraction Categories
The extraction agent looks for:
[decision][pattern][learning][error_resolved][files_changed][todo][context]Implementation Options
Option A:
bm watch-sessionsNew CLI command that watches session directories and runs extraction.
~/.claude/sessions/for new/modified filesOption B: OpenClaw plugin enhancement
Add session watching to
openclaw-basic-memoryplugin.bm watch)Option C: Standalone sidecar process
Separate process/daemon, not tied to BM CLI or OpenClaw.
bm-sidecar --watch ~/.claude/sessions/ --project my-projectRecommendation: Start with Option A (
bm watch-sessions) for dogfooding, then Option B for OpenClaw users. Option C later if there's demand from non-OpenClaw users.Extraction Agent
The extraction step needs an LLM to produce structured notes from raw transcripts. Options:
Key prompt behaviors:
.gitignorepatterns — don't extract secrets or sensitive pathsDeduplication
The extraction agent should search BM before writing:
This prevents the knowledge graph from filling with redundant session notes.
Privacy / Security
Why This Beats Letta's Approach
Open Questions
Prior Art