Why did context get truncated midtask How do I prevent it

Session context is limited by the model window. Long chats, large tool outputs, or many files can trigger compaction or truncation.
What helps:
Ask the bot to summarize the current state and write it to a file.
Use /compact before long tasks, and /new when switching topics.
Keep important context in the workspace and ask the bot to read it back.
Use sub-agents for long or parallel work so the main chat stays smaller.
Pick a model with a larger context window if this happens often.