home / skills / alekspetrov / navigator / nav-compact
This skill clears conversation context while preserving knowledge via a context marker, enabling seamless task switching without losing progress.
npx playbooks add skill alekspetrov/navigator --skill nav-compactReview the files below or copy the command above to add this skill to your agents.
---
name: nav-compact
description: Clear conversation context while preserving knowledge via context marker. Use when user says "clear context", "start fresh", "done with this task", or when approaching token limits.
allowed-tools: Read, Write, Bash
version: 1.0.0
---
# Navigator Compact Skill
Clear your conversation context while preserving all knowledge in a context marker. Like git commit before switching branches - save your state, then start fresh.
## When to Invoke
Invoke this skill when the user:
- Says "clear context", "start fresh", "reset conversation"
- Says "I'm done with this task", "moving to next feature"
- Mentions "approaching token limit", "context getting full"
- Says "compact", "clean up context"
- After completing isolated sub-task
**DO NOT invoke** if:
- User is in middle of implementation
- Context is needed for next immediate step
- Less than 20 messages in conversation (not much to gain)
## Execution Steps
### Step 1: Check If Worth Compacting
Estimate conversation size:
- If < 20 messages: Suggest waiting
- If 20-50 messages: Safe to compact
- If > 50 messages: Highly recommended
Show message:
```
π Current session: ~[N] messages
Compacting will:
- Create marker with current state
- Clear conversation history
- Free up ~[X]k tokens for new work
Continue? [Y/n]:
```
### Step 2: Create Automatic Marker
Invoke `nav-marker` skill (or create marker directly) with auto-generated name:
```
Marker name: before-compact-{YYYY-MM-DD}-{HHmm}
Note: "Auto-created before compact"
```
This marker should capture:
- Last 10-15 messages summary
- Files modified
- Technical decisions
- Current progress
- Next steps
### Step 3: Set Active Marker
Write the marker filename to `.active` file:
```bash
echo "{marker-filename}.md" > .agent/.context-markers/.active
```
This tells `nav-start` to offer restoration on next session.
### Step 4: Display Compact Instructions
Show user how to compact:
```
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β ποΈ Navigator Compact β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
Context marker created:
.agent/.context-markers/{marker-filename}.md
π Marker contains:
- Conversation summary (last 15 messages)
- Files you modified
- Technical decisions made
- Current progress & next steps
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
πΉ TO COMPACT:
Claude Code doesn't allow me to clear the conversation
programmatically. You need to do it manually:
**Method 1: New conversation**
1. Start a new conversation
2. Say "load my context" or "start my session"
3. I'll detect the active marker and restore your state
**Method 2: /clear command** (if available)
1. Type /clear
2. Say "load my context"
3. Active marker will be restored
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
π‘ Your progress is saved. You won't lose any context.
Next session:
1. Say "start my session" or run /nav:start
2. I'll detect the marker: "{marker-filename}"
3. Confirm to restore, and you'll be back where you left off
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
### Step 5: Confirm Marker Location
Verify marker was created:
```bash
ls -lh .agent/.context-markers/{marker-filename}.md
```
Show file size and confirm success:
```
β
Marker saved successfully
File: {marker-filename}.md
Size: {X} KB (~{Y} tokens)
Your context is preserved!
```
## Important Notes
**Why manual compact?**
Claude Code conversations cannot be programmatically cleared from within a conversation. The user must:
- Start a new conversation, OR
- Use `/clear` command (if available)
This skill creates the marker and sets up auto-restoration, but the actual clearing must be done by the user.
**Auto-restoration workflow:**
```
Session 1:
User: "Clear context"
β nav-compact creates marker
β Sets .active file
β Instructs user how to clear
Session 2 (new conversation):
User: "Start my session"
β nav-start detects .active file
β Offers to restore marker
β User confirms
β Context restored!
```
## Common Use Cases
### After Completing Feature
```
User: "Feature complete, clear context for next task"
β Creates marker: "before-compact-2025-10-16-1430"
β Captures: Feature implementation details
β User starts new conversation
β Restores marker, begins next feature
```
### Approaching Token Limit
```
User: "Context getting full, let's compact"
β Creates marker: "before-compact-2025-10-16-1500"
β Preserves: All current work
β User clears conversation
β Continues with fresh context
```
### Switching Between Tasks
```
User: "Done with auth, moving to payments"
β Creates marker: "auth-feature-complete"
β Clear context
β New session: Fresh start for payments
β Can restore auth marker later if needed
```
## Error Handling
**Marker creation fails**:
```
β Failed to create marker
Cannot compact without preserving context.
Fix marker creation first.
```
**Not enough context to preserve**:
```
β οΈ Very little context (< 10 messages)
Compacting now won't save much. Consider:
- Continue working
- Compact after more progress
Continue anyway? [y/N]:
```
**Active marker already exists**:
```
β οΈ Active marker already exists:
.agent/.context-markers/.active
This means you have an unrestored marker from previous compact.
Options:
1. Load that marker first (recommended)
2. Overwrite with new marker
3. Cancel compact
Your choice [1-3]:
```
## Success Criteria
Compact is successful when:
- [ ] Context marker created successfully
- [ ] Marker contains comprehensive summary
- [ ] `.active` file created (for auto-restoration)
- [ ] User knows how to clear conversation
- [ ] User knows marker will auto-restore on next session
## Scripts
**compact.py**: Automated compact workflow
- Create marker
- Set active file
- Generate restore instructions
## Best Practices
**When to compact:**
- β
After completing isolated feature/sub-task
- β
After major documentation update
- β
Before switching to unrelated work
- β
When approaching 70%+ token usage
- β In middle of implementation
- β When context needed for next step
- β After every few messages (wasteful)
**Compact frequency:**
- Small task (30 min): No compact needed
- Medium task (2-3 hours): Compact after completion
- Large task (full day): Compact at logical breakpoints
- Multi-day task: Compact at end of each session
## Notes
This skill automates the preparation for compacting but cannot clear the conversation itself (Claude Code limitation).
The value is in:
1. Automatic marker creation
2. Setting up auto-restoration
3. Guiding user through process
4. Preserving context seamlessly
This provides same functionality as `/nav:compact` command but with natural language invocation.
This skill creates a persistent context marker and clears the live conversation so you can start fresh without losing progress. It saves a compact summary of recent messages, modified files, decisions, progress, and next steps, then instructs you how to manually clear the chat and restore state later. Use it to avoid token limits and to switch tasks safely.
The skill inspects the recent conversation length and decides if compacting is worthwhile. It generates an automatic marker file named before-compact-{timestamp} that includes a 10β15 message summary, files changed, technical decisions, current progress, and next steps. It writes the marker filename to the .agent/.context-markers/.active file and displays concise instructions for manually clearing the chat and restoring the marker in a new session.
Will I lose my work when I compact?
No. The marker saves a summary, modified files list, decisions, progress, and next steps. The live conversation must be cleared manually, but the marker allows full restoration later.
Can the skill clear the conversation for me?
No. Claude Code does not allow programmatic clearing from within a conversation. The skill creates the marker and shows exact steps to manually clear and restore.
What if an active marker already exists?
The skill alerts you. Options are to load the existing marker first, overwrite it, or cancel the new compact. Loading the existing marker is recommended.