How to Sync Context Across Separate Claude Code Sub-Agent Sessions (Step-by-Step Guide)


Running multiple Claude Code sub-agent sessions in parallel (for example, a dedicated debugger
and a code-reviewer
) is powerful for focus and productivity. But there’s one problem: sessions don’t share context by default.
This guide shows you how to sync context across separate sub-agent sessions. You’ll learn:
Four different strategies for context sharing
When to use repo files vs. databases vs. MCP integrations
A step-by-step, automated SQLite context sync tool you can install in minutes
By the end, you’ll have a repeatable workflow for sharing notes and state across multiple Claude Code sessions—no more manual copy/paste.
Table of Contents
Why context sync matters
When you run sub-agents like a debugger
, code-reviewer
, or doc-writer
in separate Claude Code sessions, each one has its own context window. Without a sync strategy, you risk:
Losing critical debugging notes
Duplicating work across sessions
Forgetting what other agents have already solved
Context syncing ensures that your multi-agent workflow stays coordinated and efficient.
4 Proven Strategies for Context Sharing
1. Markdown Notes in Repo
Store shared notes in
.claude/context/*.md
Simple, human-readable, and version-controlled
✅ Easy to set up, but can grow noisy
2. SQLite Scratchpad (recommended)
Structured, queryable context DB
Easy to automate with a
ctx
CLI tool✅ Scales better than raw markdown
3. MCP-Backed Stores (Redis, external DB)
Centralized context accessible via Model Context Protocol (MCP) integrations
Best for teams or multi-machine setups
⚠️ Requires extra setup and permissions
4. Regenerate on Demand
Each sub-agent recomputes its needed context from git diffs, logs, or tests
✅ Zero coupling
⚠️ Doesn’t share rationales or decisions
Step-by-Step: Automating Context Sync with SQLite
This section walks you through building a drop-in context scratchpad with SQLite that any Claude Code sub-agent session can read/write.
0) Scaffold
mkdir -p tools .claude/context
python -m venv .venv && source .venv/bin/activate
pip install --upgrade pip
pip install tabulate
1) Add the CLI (tools/ctx.py
)
#!/usr/bin/env python3
import argparse, sqlite3, os, time
from tabulate import tabulate
DB_PATH = os.environ.get("CTX_DB", ".claude/context/context.db")
DDL = """
CREATE TABLE IF NOT EXISTS entries (
id INTEGER PRIMARY KEY AUTOINCREMENT,
ts INTEGER NOT NULL,
agent TEXT NOT NULL,
session TEXT,
topic TEXT,
summary TEXT,
refs TEXT
);
"""
def connect():
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
conn = sqlite3.connect(DB_PATH)
conn.executescript(DDL)
return conn
def cmd_add(args):
conn = connect()
with conn:
conn.execute(
"INSERT INTO entries(ts, agent, session, topic, summary, refs) VALUES(?,?,?,?,?,?)",
(int(time.time()), args.agent, args.session, args.topic, args.summary, args.refs)
)
print("ok: added")
def cmd_read(args):
conn = connect()
q = "SELECT ts, agent, session, topic, summary, refs FROM entries ORDER BY ts DESC LIMIT ?"
rows = conn.execute(q, (args.limit,)).fetchall()
out = []
for ts,agent,session,topic,summary,refs in rows:
out.append([time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(ts)), agent, session or "", topic or "", (summary or "")[:240], refs or ""])
print(tabulate(out, headers=["time","agent","session","topic","summary","refs"], tablefmt="github"))
def main():
ap = argparse.ArgumentParser()
sub = ap.add_subparsers(dest="cmd", required=True)
ap_add = sub.add_parser("add")
ap_add.add_argument("--agent", required=True)
ap_add.add_argument("--session", default="")
ap_add.add_argument("--topic", default="")
ap_add.add_argument("--summary", required=True)
ap_add.add_argument("--refs", default="")
ap_add.set_defaults(func=cmd_add)
ap_read = sub.add_parser("read")
ap_read.add_argument("--limit", type=int, default=50)
ap_read.set_defaults(func=cmd_read)
args = ap.parse_args()
args.func(args)
if __name__ == "__main__":
main()
Make it executable:
chmod +x tools/ctx.py
2) Use it in Sub-Agent Prompts
Example debugger.md
:
---
name: debugger
description: Debugging specialist for errors and test failures. Auto-syncs context.
tools: Read, Write, Grep, Glob, Bash
---
## Context Sync (before work)
- Run: `Bash -> python tools/ctx.py read --limit 20`
- Integrate relevant issues from other agents.
## Task Procedure
1) Capture error/stack trace
2) Localize failure region
3) Apply smallest safe fix
4) Verify with tests
## Context Sync (after work)
- Summarize root cause, fix, verification
- Run: `Bash -> python tools/ctx.py add --agent debugger --session "<label>" --topic "<topic>" --summary "<summary>" --refs "<files>"`
3) Example Session Usage
Start
code-reviewer
session: log issues withctx add
Start
debugger
session: load reviewer notes withctx read
, then append fix summaryStart
doc-writer
session: load both, generate release notes
Now, all three sessions share a durable context database.
Example Workflow with Parallel Sub-Agents
Session A (code-reviewer)
Review commit
Log summary with
ctx add
Session B (debugger)
Load reviewer context with
ctx read
Apply fix
Append summary with
ctx add
Session C (doc-writer)
Load reviewer + debugger context
Update documentation
Save context
This pattern creates a multi-agent workflow with shared state across sessions.
Troubleshooting & Best Practices
Nothing appears in
read
? Check your DB path or limit flag.Label consistently: Use session IDs like
CR-12
,DBG-45
.Avoid logging secrets: Keep
.claude/context/
in.gitignore
.Summarize, don’t dump: Add concise notes, not full logs.
Next Steps: Hooks for Automatic Syncing
Right now, agents politely run ctx read
at the start and ctx add
at the end. In the next article, we’ll explore Claude Code Hooks to enforce this automatically—for example:
Run
ctx read
before every task (PreTask
hook)Run
ctx add
after every task (PostTask
hook)
This ensures every sub-agent session consistently loads and writes context—even if you forget.
Internal Resource
👉 If you’re new to sub-agents, start with our Beginner’s Guide to Claude Code Sub-Agents.
Subscribe to my newsletter
Read articles from rcmisk directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

rcmisk
rcmisk
Lover of coding, software development/engineering, indie hackers podcast/community, start-ups, music, guitar, technology, fitness, running, biking, learning new things, travel, the beach, and hiking/mountains. As a kid I had too many interests. I grew up playing soccer from an early age and played through college! Sports and being a part of a team was always part of my DNA. Not only did I value sports and competition but I loved music, art, drawing, animation, film, computers, math, and learning. Once I hit college, the decision to choose my life path was paralyzing, and ultimately led me down many different paths. I explored economics, finance, psychology, philosophy, statistics, communications, and marketing. I graduated with a finance degree and thought the data science, statistics, and the trends and patterns would be a fun career, however my first entry level job in the industry discouraged me to continue in the industry and to explore other paths. I always had an itch to build and start something on my own or with family. Growing up I started a lawn mowing business, shoveling business, lemonade stands, and small Wordpress websites. I loved the creativity of coming up with ideas on how to help people and make money at the same time. I realized I loved technology, and seeing what could be created and started with technology really urged me to start down the path of learning how to code. My brother and I had an idea for a college social network (similar to Facebook), geared solely towards education and only for students at your college. We wanted to give students the ability to meet people on campus, finding work, organize course material, share notes and materials, find extracurricular activities, sell textbooks and furniture. I took it upon myself to learn how to build something like that. Basically taking an idea and making it happen. I learned about software development, coding languages, web frameworks, startups, marketing all on my own. I took online free courses, watched videos and tutorials about Django, Python, Javascript, HTML, and databases. I absolutely loved everything about the process. Seeing my work come to life and seeing people use what I created. It satisfied everything that I enjoyed growing up. The creativity, the design, artwork, coming up with a business, learning new things at my own pace, however I learned best, and working with my brother. I did all this while working full-time at a financial institution during my nights and weekends. We finally launched StudentGrounds, however after a year and 200 user signups later it slowly died down. This experience of taking an idea and learning everything needed to make it a reality basically propelled my interest in learning how to code and do that full time. I learned all about computer science, taking a certificate course at night at a local university. I started another project idea on the side for an event management application for my father's youth soccer tournament, and started applying to every technology company I could think of. I ultimately got my first software engineer job at a small start up in Boston as an apprentice/intern and learned on the job before getting my first full-time software engineer position at a large Boston e-commerce company. My goal there was to learn as much as I could from season professionals, and learning how the corporate world works in terms of software development. My ultimate goal is to create something on my own doing something I love, as well as enjoy life, and give back to others through education. Right now I am a full-time Software Engineer with 6 years in the marketing tech space, trying to finish a SaaS boilerplate so that I can spin up any web application for any idea at the click of a button, which will then set me up for my next idea, IdeaVerify, an automated way to verify/validate you're SaaS application idea before actually starting to code and wasting many hours and years developing something that no one would use. This blog is about my journey navigating the software engineering world, without a CS degree, building in public, keeping record of what I learned, sharing my learnings and at the same time giving back to others, teaching them how to code and giving helpful hints and insights. I am also using this blog to showcase other sides of me such as art, music, writing, creative endeavors, opinions, tutorials, travel, things I recently learned and anything else that interests me. Hope you enjoy!