Context is the single biggest factor in your agent’s quality. As the context window fills up, responses get slower and less focused. Managing context well is the difference between a productive two-hour session and one where you restart every twenty minutes.
How context works
Every message you send and every file the agent reads adds to the context window. Your agentic CLI uses a large context window, but it is not infinite. When it fills up:
- Responses slow down (more tokens to process)
- The agent loses track of earlier conversation details
- Quality degrades as important information gets crowded out by noise
Check how full your context is at any time:
/context
This shows a visual grid of your context usage with suggestions for when to compact.
Clearing vs. compacting
These are different tools for different situations.
/clear — start fresh
Wipes the entire conversation. Use it when you are switching to an unrelated task.
# Done reviewing auth code, now moving to billing feature
/clear
When to use:
- Switching between unrelated tasks (review -> feature work -> debugging)
- After completing a major piece of work
- When the agent starts referencing irrelevant earlier context
When not to use:
- Mid-task when you still need the agent to remember what you have been doing
- After a long exploration phase you want to build on
/compact [instructions] — compress and continue
Summarizes the conversation so far, keeping key facts while freeing up space. The agent continues with the summary as its memory of what happened.
# Getting long -- compress but keep the important parts
/compact
# Compress with specific guidance on what to remember
/compact focus on the database schema changes and test failures
The optional instructions tell the agent what to prioritize in the summary. This is powerful — it keeps the agent focused on what matters for your next steps.
When to use:
/contextshows the window is getting full- You are mid-task and need to keep going
- You have done a lot of exploration and want to preserve findings while freeing space
When not to use:
- When switching to an entirely different task (use
/clearinstead) - When the conversation is already short
Decision tree
Need to free up context?
|
+-- Switching to an unrelated task? --> /clear
|
+-- Continuing current work?
|
+-- Can you summarize what matters? --> /compact [instructions]
|
+-- Everything matters equally --> /compact (no instructions)
Session management
Your AI coding agent automatically saves conversations. You can resume, branch, and organize them.
Resume a session
# Resume the most recent session
agent -c
agent --continue
# Resume a specific session by name or ID
agent -r "auth refactor"
agent --resume abc123
Inside an active session:
/resume
This opens a session picker showing your recent conversations.
Name sessions for findability
/rename auth-service-refactor
Named sessions are easier to find later. Name them after the task, not the date.
Branch a conversation
/branch risky-approach
Creates a copy of the current conversation. Use this before trying something you might want to undo — if the approach fails, your original conversation is untouched.
Practical pattern:
# Working on a feature, want to try two approaches
/branch approach-a
# Try approach A here...
# If it doesn't work out, go back and try B
/resume original-session
/branch approach-b
Export a conversation
/export auth-refactor-notes.txt
Saves the full conversation as plain text. Useful for sharing findings with teammates or keeping a record of architectural decisions.
Patterns for long sessions
Phase-compact pattern
For large tasks, compact between phases to preserve findings while freeing space:
Phase 1: Explore the codebase
→ /compact focus on findings about the auth module and its dependencies
Phase 2: Plan the changes
→ /compact focus on the agreed implementation plan and file list
Phase 3: Implement
→ /compact focus on what has been implemented and what remains
Phase 4: Test and review
→ (context is fresh enough to finish)
Multi-session pattern
For work that spans days, use named sessions:
# Day 1: Explore and plan
agent
/rename billing-migration-explore
# ... explore, plan, /compact findings ...
# Day 2: Implement
agent -r "billing-migration-explore"
# Continue with full context of yesterday's findings
Tips
- Run
/contextperiodically during long sessions. It takes two seconds and prevents surprises. /compactwith instructions is almost always better than/compactalone. Tell the agent what matters./clearbetween unrelated tasks is free and prevents context bleed — the agent accidentally applying patterns from task A to task B.- Name every session that lasts more than fifteen minutes. Future you will thank present you.
/branchbefore risky experiments. It costs nothing and gives you a clean rollback.- The
Esc Escshortcut (press Escape twice) opens the rewind interface to restore code and conversation to a previous point. - Use
/btwfor quick side questions without cluttering context. The question and answer are ephemeral — they never enter the conversation history. Works even while the agent is mid-response.