Repository navigation
Claude Code session keeps losing context mid-task - am I doing something wrong? #1239
|
Hello everyone, I've been using Claude Code for about 2 weeks now and it's honestly been great for most stuff, but I keep running into this annoying issue where it seems to "forget" what we were working on. What's happening: I'll start a session working on, say, refactoring a Rust module. We'll get 15-20 messages deep, Claude understands the codebase structure, knows which files we're touching, everything's going smooth. Then suddenly it'll:
Example from yesterday: Me: "Okay now let's add error handling to the parser" ...when we literally just spent 30 minutes building the parser together. My setup:
What I've tried:
Questions:
I've seen people working on huge refactors across multiple sessions so I feel like I'm missing something obvious here. Any tips appreciated! |
Replies: 3 comments 3 replies
|
Hey @BittuChan, thanks for sharing your problem, I think I figured out what was going on after reading through some other discussions and experimenting more. TL;DR: I wasn't using the session persistence pattern correctly. Claude Code doesn't automatically maintain context across the full conversation - you need to explicitly anchor it. What actually fixed it:1. Started using TASKS.md + CLAUDE.md patternCreated two files in my project root: TASKS.md - What we're working on right now: ## Current Task: Refactor parser module for better error handling
**Goal:** Add comprehensive error types and propagate them properly through the parse chain
**Files in scope:**
- src/parser/mod.rs (main parser logic)
- src/parser/error.rs (NEW - error types)
- src/parser/token.rs (token definitions)
**Progress:**
- [x] Defined ParseError enum
- [x] Updated parse_expression to return Result<Expr, ParseError>
- [ ] Add error recovery for unclosed delimiters
- [ ] Write tests for error cases
**Next steps:**
1. Implement error recovery in parse_block()
2. Add source location tracking to errorsCLAUDE.md - Context that persists across sessions: ## Project Context
This is a Rust-based configuration file parser for a custom DSL.
**Architecture:**
- Lexer: src/lexer/ - tokenizes input
- Parser: src/parser/ - builds AST
- Evaluator: src/eval/ - executes AST
- REPL: src/main.rs - interactive mode
**Conventions:**
- All errors use anyhow for the public API
- Internal parser uses custom ParseError
- Tests in same file as implementation (Rust convention)Now when Claude starts losing context, I just say "check TASKS.md" and it immediately gets back on track. 2. Realized I was working in too many files at onceClaude Code seems to handle 3-4 active files really well, but when I had 7-8 files open across different modules, that's when context got wonky. New workflow:
3. Used explicit checkpointsEvery 20-30 minutes or at natural break points, I do: Claude then writes a clean summary of changes, updates the task list, and this seems to "reset" its understanding of where we are. Results after changing approach:Just finished a 2-hour session refactoring the entire error handling system across 6 files. Zero context loss. Claude remembered function signatures, our naming conventions, everything. The difference:
|
|
Maintainer update: the community answer here is the model I would recommend for current ECC usage. Claude Code still has a finite context window, and ECC can make that better or worse depending on how much you load. The practical fix is to keep stable project facts in Two ECC-specific notes:
We are also folding this into the ECC 2.0 context/progress work so the default guidance is less "install everything" and more "load the smallest useful surface, with explicit recovery points." |
|
Building on affaan-m's answer — the addition I'd make is about when the anchor gets written. Manual TASKS.md updates fail exactly when you need them: your symptom (asked which file, 15 messages in) is the compaction boundary having fired, not the raw window filling up. Have scripts/hooks/pre-compact.js write the active surface, and session-start.js read it back: write('.ecc/active-surface.md', {goal, files: touched.slice(-10)})Goal plus last N touched files re-anchors a session; a full transcript dump does not — it just re-costs you the window. Want me to take a crack at it? |
Hey @BittuChan, thanks for sharing your problem, I think I figured out what was going on after reading through some other discussions and experimenting more.
TL;DR: I wasn't using the session persistence pattern correctly. Claude Code doesn't automatically maintain context across the full conversation - you need to explicitly anchor it.
What actually fixed it:
1. Started using TASKS.md + CLAUDE.md pattern
Created two files in my project root:
TASKS.md - What we're working on right now: