Labs

Advanced Context Management for Claude Code Across Multiple Repositories

Advanced Context Management for Claude Code Across Multiple Repositories

If you work across multiple repositories—such as a frontend, a backend, and a shared library—with AI coding assistants like Claude Code, you're likely familiar with the frustration: Claude Code often loses track of the current project, forgets conventions from other repositories, and you spend half your session re-explaining information it previously knew.

Fortunately, there are effective strategies to mitigate this issue.

The Core Problem: Claude Code Has One Context Window

Claude Code lacks persistent memory across sessions or repositories. When you open a new project, it starts fresh. When you switch from your API repository to your frontend repository mid-session, context from the first repository does not automatically transfer. This becomes a significant problem when:

  • Your API and frontend share types but reside in different repositories.
  • You need to make coordinated changes across both repositories simultaneously.
  • Your backend conventions differ from your frontend conventions.
  • You are performing a migration that touches multiple codebases.

Solution 1: The Shared CLAUDE.md Strategy

Create a root-level CLAUDE.md file in each repository that cross-references the others and defines project specifics:

# API Repo - CLAUDE.md

## This project
REST API using Node.js + Express + PostgreSQL
Auth: JWT tokens, 15min access / 7day refresh

## Paired with: frontend repo at ../frontend
Frontend expects:
- All API responses: { data: ..., error: null } or { data: null, error: "message" }
- Date format: ISO 8601 strings (not timestamps)
- Auth header: Bearer {accessToken}

## Shared types
See ../shared-types/index.ts for TypeScript interfaces
Any API change that affects response shape MUST update shared-types first

Similarly, for the frontend repository, the CLAUDE.md could be structured as follows:

# Frontend Repo - CLAUDE.md

## This project
Next.js 14 + TypeScript + Tailwind

## Paired with: API repo at ../api
API base URL: http://localhost:3001
All fetch calls use: src/lib/api.ts (do not call fetch directly)
Error handling: check error field on response, never .catch() alone

## When making API changes
1. Check ../api/CLAUDE.md for response format
2. Update src/types/ to match any schema changes
3. Update src/lib/api.ts if adding new endpoints

Now, when Claude Code reads your CLAUDE.md, it immediately understands the cross-repository relationships and conventions.

Solution 2: The Context Handoff File

When you are actively working across multiple repositories, create a temporary CONTEXT.md file at your workspace root:

workspace/
  CONTEXT.md      ← Claude reads this first
  api/
  frontend/
  shared-types/

This CONTEXT.md file can contain specific details about the current task, guiding Claude Code's understanding of cross-repository operations:

# Active work context - 2026-04-08

## Current task
Adding user avatar upload feature
- API changes: POST /api/users/avatar, returns { avatarUrl: string }
- Frontend changes: ProfilePage.tsx needs upload button + preview
- Database: Added avatar_url column to users table (migration already run)

## St
↗ Read original source