Overview

Run Claude Code on a long-lived repo by keeping context in files, writing a structured brief per task, isolating parallel work in worktrees, and guarding the known failure modes. Concepts are in claude-code; install and sign-in are in set-up-claude-code.

Put durable context in anchor files

Each session starts with a fresh context window. Two mechanisms carry knowledge across sessions: CLAUDE.md files you write, and auto memory that Claude writes about your corrections. Run /memory to see both and /context to confirm which files loaded.

  • CLAUDE.md at the repo root loads every session. Claude also loads CLAUDE.md files from directories above the working directory at launch, and from subdirectories when it reads files there. Put mission, voice rules, schemas, the folder map, and the “how to add a page” steps here, and keep each file short (Anthropic’s guidance is under about 200 lines).
  • TODO.md holds open work as a checkbox list, and SESSION_LOG.md is an append-only record of what each session shipped. Neither loads automatically; instruct Claude in CLAUDE.md to read them at session start.
  • CLAUDE.md is context, not enforcement. A rule that must run every time, such as a build before each commit, belongs in a hook.

Auto memory is on by default, stored per repository under ~/.claude/projects/<project>/memory/, and shared across worktrees but not across machines. Details: How Claude remembers your project. For writing the file itself, see claude-code-claude-md.

Write the brief in chat and run it in Claude Code

Draft in a chat surface, where iteration is cheap: phrasing, acceptance criteria, and non-goals. Paste the finished brief into Claude Code, which executes with tool calls. Report the build output or PR URL back to chat and revise the brief if needed.

A brief states the mission, environment, phased steps, file paths, acceptance criteria, and explicit non-goals. The template is in prompt-design.

Structure the work as phase and verify

Number the phases and end each with a command that proves it.

## Phase 2: build the content tree
Steps: create content/tooling/github.md with full frontmatter.
Verify: `find content/tooling -name "*.md" | wc -l` prints 5.

## Phase 3: build
Verify: `npx quartz build` exits 0.

If a phase fails, the session stops there instead of finishing a broken build and unwinding it.

Isolate parallel edits in worktrees

Subagents share your working tree by default, so two agents editing at once can collide.

  • Set isolation: worktree in a custom subagent’s frontmatter, or ask Claude to use worktrees for its agents. Each gets a temporary git worktree, removed automatically when it finishes without changes.
  • For a whole parallel session, run claude --worktree <name>. The worktree lands in .claude/worktrees/<name>/ on a branch named worktree-<name>. Add .claude/worktrees/ to .gitignore.
  • New worktrees branch from the remote’s default branch, not your current HEAD, so unpushed work is absent. Set worktree.baseRef to "head" to branch from current work.
  • A worktree is a fresh checkout. List gitignored files such as .env in a .worktreeinclude file to copy them in, and install dependencies there.
  • Skip isolation for read-only research subagents.

Merge results by branch, not by file. Coordination patterns are in multi-agent; the worktree reference is Run parallel sessions with worktrees.

Use the GitHub MCP tools or gh for PR operations

With the GitHub MCP server attached (MCP servers), Claude can use mcp__github__create_pull_request (set draft: true until verification passes), mcp__github__pull_request_read, and mcp__github__merge_pull_request. The gh CLI works equally well; MCP calls just avoid shell quoting problems with multi-line PR bodies. Merge strategy is in github-pr-workflow.

Guard the common failure modes

  • Unscoped find-and-replace. A regex runs repo-wide and breaks unrelated files. Scope each rename to a directory or file list in the brief.
  • Over-editing. One requested line changes and three others get rewritten. State non-goals: “do not modify any other section.”
  • Helpful refactors. Claude “improves” an unrelated smell. Name the out-of-scope files.
  • Skipped verification. A phase is reported done without running the build. Put the verification command in the brief.
  • Drifting voice. Playbook voice slides into marketing voice. Pin the rules in CLAUDE.md.

claude-code expands each failure mode.