Skip to content

feat: session continuity — context-refresh command + warm session start pattern for Claude Code #155

@stackbilt-admin

Description

@stackbilt-admin

Problem

Claude Code sessions start cold. Even with CLAUDE.md and memory files, the AI has to rediscover current project state (open issues, pending work, recent decisions) at the start of every session. This creates cognitive overhead and missed context.

charter serve already exposes ADF context as an MCP server — the foundation is there. What's missing is a first-class way to assemble live project state into that context before a session starts.

Proposed additions

1. charter context-refresh command

A new command that assembles a live project snapshot and writes it to .ai/context.adf and optionally CONTEXT.md:

charter context-refresh [--output CONTEXT.md] [--sources git,github,d1]

Sources:

  • git — last N commits, current branch, uncommitted changes
  • github — open issues with specified labels, recent PRs, CI status
  • d1 — pending work items from a Cloudflare D1 table (configurable endpoint + query)
  • aegis / custom — extensible via .charter/context-sources.json

Output shape (written to .ai/context.adf):

# Live Context — 2026-05-22T11:00:00Z

## Open Work
- [repo/issues tagged `auto-fix`]
- [pending D1 queue items]

## Recent Activity  
- [last 5 commits]
- [recently merged PRs]

## Pending Decisions
- [items awaiting human approval]

2. Session start hook integration

A Claude Code SessionStart hook (or UserPromptSubmit on first message) that calls charter context-refresh automatically:

{
  "hooks": {
    "UserPromptSubmit": [{
      "matcher": "*",
      "hooks": [{"type": "command", "command": "charter context-refresh --once"}]
    }]
  }
}

--once flag: only runs if context.adf is older than N minutes, not on every message.

3. charter serve MCP exposure of context.adf

charter serve already works. Enhancement: expose a charter_context tool that returns the current context.adf contents as a structured object, so the LLM can call it directly rather than reading a file.

4. ADF warm-start instruction in CLAUDE.md

charter adf init should generate a ## Session Start section in CLAUDE.md that tells Claude Code to:

  1. Call charter_context (MCP tool) to load live state
  2. Read CONTEXT.md if available
  3. Check memory files for recent decisions

Why this belongs in charter

Charter already owns:

  • ADF format (.ai/*.adf)
  • charter serve (MCP server)
  • Project governance context

Session continuity is the natural next layer. The governance evidence charter tracks (commit trailers, policy stamps, blast radius) is exactly the signal that makes a warm session start meaningful — not just "what files changed" but "what decisions were made and why."

Real-world validation

This pattern was developed for the CodeBeast autonomous review agent (Stackbilt internal). CodeBeast uses charter for governance, tarotscript for symbolic decision oracles, and Claude Code as the primary dev interface. The missing piece is always session startup — rediscovering where we left off costs 5-10 minutes per session and loses nuance that can't be captured in static memory files.

A charter context-refresh that knows about D1 queue state, open GitHub issues, and recent decide receipts would make the session start ritual automatic and complete.

Implementation notes

  • context-refresh should be composable: users define sources in .charter/context-sources.json
  • D1 source requires CLOUDFLARE_API_TOKEN + database ID — pull from env or .charter/config.json
  • GitHub source uses GITHUB_TOKEN — already expected by charter
  • Output should be idempotent: safe to run on every session start
  • charter serve MCP tool charter_context should return structured JSON not raw markdown

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions