DEV Community

brian austin
brian austin

Posted on

Claude Code context window: how to manage long sessions without losing progress

Claude Code context window: how to manage long sessions without losing progress

You're 45 minutes into a complex refactor. Claude Code has been brilliant — finding edge cases, suggesting patterns, catching bugs. Then it happens:

This conversation is getting long. Claude's responses may be slower or less accurate.
Enter fullscreen mode Exit fullscreen mode

Everything you've built together — the context, the understanding, the momentum — is about to degrade. Here's how to stop that from happening.

Why the context window matters

Claude Code's context window holds your entire conversation: your prompts, Claude's responses, file contents, terminal output. When it fills up, Claude starts losing the earliest parts — like RAM swapping to disk. Quality drops before you hit the hard limit.

The practical limit where quality degrades is around 80-90% full. By then, Claude may:

  • Forget decisions made early in the session
  • Repeat suggestions you already rejected
  • Lose track of your project's conventions
  • Miss cross-file dependencies

Strategy 1: Compact before you hit the wall

The /compact command summarizes your conversation into a compressed form, dramatically reducing token usage while keeping the key context.

/compact
Enter fullscreen mode Exit fullscreen mode

Run this proactively when you've completed a logical chunk of work — not when you're desperate. After compacting:

  • Claude has a summary of what was accomplished
  • You've reset the token counter
  • The session can continue cleanly

Make it a habit: finish a feature → compact → start next feature.

Strategy 2: CLAUDE.md as persistent memory

Context window resets don't wipe your CLAUDE.md file. This is your persistent project memory:

# Project context

## Architecture decisions
- Using PostgreSQL, not MongoDB (decided 2026-03-15)
- Auth via JWT with 7-day expiry
- API versioned at /api/v2/

## Current sprint
- Feature: user notification system
- PR #47 in progress
- Blocked on: rate limiter design

## Conventions
- Async/await only, no .then() chains
- Error handling: always throw, never return null
- Tests: one describe block per function
Enter fullscreen mode Exit fullscreen mode

When you start a new session or after compacting, Claude reads this automatically. The decisions you made yesterday aren't lost — they're documented.

Strategy 3: Break sessions by scope

Long context problems are often scope problems. Instead of one giant session:

# Session 1: design and plan
claudecc
> Plan the notification system. Output a spec to SPEC.md.
/compact

# Session 2: implement
claudecc  
> Read SPEC.md. Implement the notification system.
/compact

# Session 3: test
claudecc
> Read the notification system implementation. Write comprehensive tests.
Enter fullscreen mode Exit fullscreen mode

Each session has a clear scope. CLAUDE.md + written specs carry context between sessions. No session fills its window.

Strategy 4: Use /clear strategically

Sometimes you need a hard reset:

/clear
Enter fullscreen mode Exit fullscreen mode

This wipes the conversation entirely. Use it when:

  • You've gone down a wrong path and need to start over
  • You're switching to an unrelated task
  • The session is corrupted by bad context

After clearing, re-read your CLAUDE.md and relevant files to rebuild context fast:

> Read CLAUDE.md and src/notifications/. I want to continue implementing the digest email feature.
Enter fullscreen mode Exit fullscreen mode

Strategy 5: Output to files, not just terminal

Every file Claude creates or reads counts against context. But files on disk don't. When Claude generates something large (a plan, a spec, test output), have it write to a file:

> Analyze the auth system and write your findings to AUDIT.md
Enter fullscreen mode Exit fullscreen mode

Now you can /compact and ask Claude to read AUDIT.md when needed — it loads fresh into the new context instead of being buried in old conversation.

The rate limit problem

Long Claude Code sessions hit rate limits before they hit the context window. You're building momentum, context resets are one problem, but hitting overloaded mid-task is another.

One solution: set ANTHROPIC_BASE_URL to a proxy that removes the rate limit entirely.

export ANTHROPIC_BASE_URL=https://simplylouie.com/api/anthropic
Enter fullscreen mode Exit fullscreen mode

That's it. Claude Code reads this env var automatically. Your sessions run on a paid API account with no queue — just continuous work. SimplyLouie is ✌️$2/month, no rate limits.

Quick reference

Situation Action
Finished a logical chunk /compact
Going down wrong path /clear
Session degrading /compact then re-read key files
Starting fresh day Read CLAUDE.md first
Hit rate limit Set ANTHROPIC_BASE_URL
Large output Ask Claude to write to file

The mental model

Think of Claude Code's context like a whiteboard. /compact erases the scratch work but keeps the summary. /clear wipes the whole board. CLAUDE.md is the sticky note that survives both.

Keep your whiteboard from filling up with irrelevant history, and you'll never lose a session mid-task.


Running long Claude Code sessions without rate limit interruptions? SimplyLouie is ✌️$2/month — set one env var and your sessions run uninterrupted.

Top comments (0)