---
name: compact-fix
description: Restore context after chat compaction by retrieving the execution plan and checking current progress.
---

# Context Recovery After Compaction

Restores full context after a Claude Code chat has been compacted by retrieving the execution plan and current task status.

## Project Configuration

Read project configuration from `.claude/project.json`:
- `projectName`
- `linear.teamId`, `linear.teamName`, `linear.projectId`
- `github.owner`, `github.repo`

If `.claude/project.json` doesn't exist, suggest running `/setup-project` first.

## Instructions for Claude

When this skill is invoked, restore context from the current branch and Linear issue.

### Step 0: Load Configuration

```bash
PROJECT_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
```

Read `$PROJECT_ROOT/.claude/project.json`.

### Step 1: Get Current Workflow Status

1. Get the current Git branch: `git branch --show-current`
2. Extract the issue ID (e.g., `ABC-XX` from `feature/ABC-XX-title`)
3. If an issue ID is found, fetch from Linear:
   ```
   Use mcp__linear__get_issue with the extracted ID
   ```
4. Check sub-issues and their statuses
5. This shows:
   - Current branch and workflow
   - Linear issue tied to this branch
   - All tasks and their statuses

### Step 2: Retrieve the Execution Plan

1. Use the Task tool with `subagent_type="Explore"` and `thoroughness="medium"` to recover codebase context related to the current feature. Pass the issue title and key terms.
2. Look for plan files:
   - `.claude/plan.md` or similar
   - Recent commit messages mentioning the plan
3. If a Linear issue was found, read its full description — it may contain the implementation plan

### Step 3: Identify Current Progress

1. Check which sub-issues are "Done" in Linear
2. Check which sub-issue is "In Progress"
3. Determine the next logical step:
   - Use `git status` and `git diff` to see uncommitted work
   - Cross-reference with the plan and sub-issue statuses

### Step 4: Review REFERENCES Folder

Check for a `REFERENCES/` directory. If it exists, read relevant files based on the feature being worked on (API references, integration docs, architecture guides, testing plans, setup guides).

### Step 5: Present Context Summary

```
## Context Restored

**Current Branch**: [branch-name]
**Feature**: [feature description]
**Project**: [config.projectName]

### Execution Plan Summary
[Brief summary of the plan and approach]

**References Used**:
- [List of REFERENCES files relevant to this feature]

### Progress Status
**Completed Tasks**:
- [x] Task 1 name
- [x] Task 2 name

**In Progress**:
- [ ] Current task name

**Pending**:
- [ ] Next task 1
- [ ] Next task 2

### Current Working State
[Summary of current git changes based on git status/diff]

### Next Steps
[What to work on next based on the plan and progress]

Ready to continue? Let me know if you need:
- To continue with the current task
- To review any specific part
- To update task status in Linear
```

## Key Points

1. **Always check the Linear issue first** — it contains the full context
2. **Read REFERENCES files** relevant to the feature
3. **Sync git status with Linear tasks** — ensure they're in alignment
4. **Don't guess** — if you can't find the plan, tell the user explicitly
5. **Update Linear tasks** as you make progress after context is restored

## Error Handling

**If the execution plan is not found:**
```
Execution Plan not found

I found the current workflow but couldn't locate the Execution Plan.
Let me check git history and current code to understand the context...

[Proceed with code exploration and ask user for clarification if needed]
```

**If no active workflow exists:**
```
No active workflow found for branch: [branch-name]

You're not on a feature branch with a tracked workflow.

Would you like to:
1. Switch to an existing feature branch
2. Start a new feature (use /new-feature)
3. Work on this branch without tracking
```
