Skip to content

Session Continuity & Strategic Compression

In long-term projects, maintaining session continuity and effectively managing the context window are key challenges. This guide covers how to maintain an efficient workflow through strategic compression techniques.

Understanding the Context Window

Context Window Limitations

Claude Code's context window is large but still has limits:

  • Contains all conversation history
  • Contains file contents that were read
  • Contains command execution results
  • Contains tool call records

When approaching the limit, earlier content gets removed.

Impact of Context Window Size

The context window size affects:

  • How much information Claude can remember
  • How many files can be processed simultaneously
  • How long a conversation can continue
  • The accuracy and relevance of responses

Session Continuity Strategies

Identifying Session Boundaries

Know when to start a new session:

Should continue the current session:

  • Tasks are related and continuous
  • Previous context is needed
  • Still working on the same feature module
  • Context window is not full

Should start a new session:

  • Switching to a completely different task
  • Context window is approaching the limit
  • Conversation has become cluttered
  • Need to reset direction

Session Transition Techniques

Smoothly transition from one session to another:

Before ending the old session:
Summarize key decisions and findings:
1. Decided to use JWT authentication
2. Token expiration set to 1 hour
3. Using Redis for refresh token storage
4. Implemented basic login and registration
5. TODO: Add password reset feature

When starting the new session:
Continue developing the user authentication feature.
Completed: Basic login/registration, JWT auth
Tech stack: Node.js, Express, JWT, Redis
Current task: Implement password reset feature

Strategic Compression Techniques

What is Strategic Compression

Strategic compression is the selective retention of important information while discarding unimportant details to optimize context window usage.

Information Layering

Categorize information into different layers:

Core layer (must retain):

  • Project architecture and tech stack
  • Key design decisions
  • Interface definitions and conventions
  • Current task objectives

Support layer (retain as needed):

  • Implementation details
  • Code snippets
  • Test results
  • Debug information

Temporary layer (can be discarded):

  • Exploratory discussions
  • Resolved issues
  • Outdated approaches
  • Redundant information

Active Compression

Actively compress information during sessions:

Summarize our discussion so far:

Core decisions:
- Using PostgreSQL as the primary database
- Using Redis as the caching layer
- API follows RESTful design
- Authentication uses JWT

Current progress:
- Completed: Database design, user authentication
- In progress: Order management feature
- TODO: Payment integration, notification system

Technical constraints:
- Response time < 200ms
- Support 1000 concurrent users
- 99.9% availability

Now continue implementing the order management feature.

Progressive Refinement

Start from a high level and gradually go into details:

Round 1 (high level):
Design the architecture of the order management system

Round 2 (medium level):
Design the order state machine and main APIs

Round 3 (details):
Implement the create order API endpoint

Documentation Strategies

External Documentation

Record important information in external documents:

docs/
  architecture.md      # Architecture design
  api-spec.md         # API specification
  decisions/          # Design decisions
    001-database.md
    002-auth.md
  progress.md         # Progress tracking

Reference documents in sessions:

Based on the decisions in docs/decisions/002-auth.md,
implement JWT authentication

Code Comments

Record key information in code:

typescript
/**
 * User Authentication Service
 *
 * Design decisions:
 * - Using JWT for stateless authentication
 * - Access token expiration: 1 hour
 * - Refresh token stored in Redis, expiration: 7 days
 * - Password hashed with bcrypt, salt rounds: 10
 */
export class AuthService {
  // ...
}

Commit Messages

Use detailed commit messages to record context:

feat(auth): implement JWT authentication

- Add JWT token generation and validation
- Implement refresh token mechanism using Redis
- Add password hashing with bcrypt
- Create authentication middleware

Technical decisions:
- Access token expires in 1 hour
- Refresh token expires in 7 days
- Using RS256 algorithm for JWT

Related: #123

Context Recovery Techniques

Quick Recovery

Quickly recover previous working state:

Continue yesterday's work.
Project: E-commerce platform
Module: Order management
Last progress: Completed create order API
Today's task: Implement order query and update

Using Git History

Leverage Git history to recover context:

View the last 5 commits,
understand recent development progress

Quickly locate relevant code through search:

Search for all order-related files

Long-term Project Management

Project Knowledge Base

Build a project knowledge base:

docs/
  README.md           # Project overview
  getting-started.md  # Quick start
  architecture/       # Architecture docs
  api/               # API docs
  guides/            # Development guides
  decisions/         # Design decisions
  troubleshooting.md # Troubleshooting

Regular Summaries

Create project summaries regularly:

Weekly summary:
Completed this week:
- User authentication module
- Order creation feature
- Payment integration (in progress)

Technical debt:
- Need more unit tests
- API docs need updating
- Performance optimization pending

Next week's plan:
- Complete payment integration
- Implement notification system
- Performance testing and optimization

Milestone Records

Record important milestones:

Milestone 1: MVP Complete (2024-01-15)
- User registration/login
- Product browsing
- Shopping cart
- Order creation

Milestone 2: Payment Integration (2024-02-01)
- Stripe integration
- Order payment
- Payment callback handling

Milestone 3: Beta Release (2024-02-15)
- Performance optimization
- Security hardening
- User testing

Smart Context Management

Priority Management

Manage context based on importance:

High priority (always retain):
- Current task goals and requirements
- Key technical constraints
- Important design decisions

Medium priority (retain as needed):
- Related code implementations
- Test results
- Performance data

Low priority (can be discarded):
- Exploratory discussions
- Resolved issues
- Temporary debug information

Dynamic Adjustment

Dynamically adjust context based on tasks:

When switching tasks:
Don't need authentication module details right now,
focus on payment integration implementation

On-demand Loading

Only load detailed information when needed:

Now I need to understand the user authentication implementation details,
please read the relevant files in the src/auth/ directory

Session Templates

New Feature Development Template

New feature: [Feature name]

Background:
- Project: [Project name]
- Tech stack: [List]
- Related modules: [List]

Requirements:
- [Requirement 1]
- [Requirement 2]

Technical constraints:
- [Constraint 1]
- [Constraint 2]

References:
- Similar feature: [File path]
- Design doc: [Document path]

Bug Fix Template

Bug fix: [Bug description]

Environment:
- Project: [Project name]
- Branch: [Branch name]
- Affected version: [Version number]

Issue:
- Symptom: [Description]
- Reproduction steps: [Steps]
- Error log: [Log]

Related code:
- [File path]

Code Review Template

Code review: [PR number]

Review scope:
- Files: [File list]
- Change type: [Feature/Fix/Refactor]

Review focus:
- Code quality
- Security
- Performance
- Test coverage

Project context:
- Tech stack: [List]
- Code standards: [Standards]

Compression Tips

Tip 1: Use References

Use references instead of repeating content:

Bad approach:
[Repeatedly pasting large blocks of code]

Good approach:
Refer to the implementation in src/auth/login.ts

Tip 2: Summarize Discussions

Periodically summarize discussion content:

We discussed three approaches,
and ultimately chose Approach B (using Redis cache),
because it has the best performance and simplest implementation.

Tip 3: Remove Redundancy

Remove information that is no longer needed:

The previously discussed Approaches A and C have been rejected,
now focus on implementing Approach B

Tip 4: Layered Storage

Store different layers of information separately:

High-level design → docs/architecture.md
API specification → docs/api-spec.md
Implementation details → Code comments
Temporary notes → In session

Best Practices

Active Management

Actively manage context, don't wait until the window is full:

We've discussed a lot of content,
let me summarize the key points,
then continue to the next step

Stay Focused

Keep the session focused:

This discussion has drifted off topic,
let's return to the original task:
implementing the order query feature

Record Promptly

Record important information promptly:

This decision is important,
I'll record it in docs/decisions/

Regular Cleanup

Periodically clean up unnecessary information:

This debug information is no longer needed,
now focus on implementing the new feature

Tools and Techniques

Using Git

Leverage Git for history management:

bash
# View recent changes
git log --oneline -10

# View history of a specific file
git log --follow src/auth/login.ts

# View details of a commit
git show abc123

Using Note-taking Tools

Use external note-taking tools:

  • Notion
  • Obsidian
  • Markdown files
  • Wiki systems

Using Project Management Tools

Use project management tools to track progress:

  • GitHub Issues
  • Jira
  • Trello
  • Linear

Common Issues

Issue 1: Context Lost

Solution: Summarize regularly, use external documentation

Issue 2: Information Overload

Solution: Layered management, priority sorting

Issue 3: Difficult to Recover

Solution: Use templates, record key information

Issue 4: Repeated Discussions

Solution: Record decisions, reference documentation

Summary

Effective session continuity and strategic compression require:

  • Active context window management
  • Layered storage of information by importance
  • Using external documentation for key content
  • Regular summarization and compression of information
  • Maintaining session focus and continuity

By mastering these techniques, you can maintain an efficient workflow in long-term projects.

Released under the MIT License.