Skip to content
Back to skills

2915 Long Running State Patterns 57f0e2d4

ASecurity

Patterns for managing Claude agents across extended multi-context-window workflows. This is optional reference content for when you need to design long-running agent systems.

  • 9 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 11, 2026
testingbashtestinggitci/cd

Works with

  • claude code

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add tools-only/X-Skills --skill 2915-long-running-state-patterns_57f0e2d4 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 2915 Long Running State Patterns 57f0e2d4?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 2915 Long Running State Patterns 57f0e2d4
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-2915-long-running-state-patterns-57f0e2d4/badge)](https://www.skillsdirectory.com/skills/tools-only-2915-long-running-state-patterns-57f0e2d4)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

SKILL.md
# Long-Running State Patterns

Patterns for managing Claude agents across extended multi-context-window workflows. This is optional reference content for when you need to design long-running agent systems.

## Core Challenge

Long-running agents work in discrete sessions. Each new session starts without memory of previous sessions. Complex projects span multiple context windows. The solution: bridge gaps through structured artifacts and explicit state management.

## Context Management

### Automatic Tools

**Auto-Compact**: Triggers at ~95% context capacity. Claude Code summarizes history, preserving architectural decisions and unresolved bugs. Manually trigger with `/compact` at logical breakpoints.

**Token Budget Awareness**: Claude 4.5+ receives updates on remaining context after tool calls. Enables better task persistence and strategy adjustment.

### Compression Strategies (Karpathy Framework)

| Strategy | Description |
|----------|-------------|
| Write | Save context externally to reference later |
| Select | Load relevant context on-demand |
| Compress | Retain only tokens needed for current task |
| Isolate | Split work across subagents with clean windows |

**Hierarchical Summarization**: Subagents return condensed summaries (1,000-2,000 tokens) rather than full exploration context.

**Just-In-Time Loading**: Maintain lightweight identifiers (file paths, queries). Load data at runtime using tools.

## State Persistence

### Git-Based State Tracking

Anthropic recommends combining git history with structured progress files:

**Two-Agent Pattern**:
1. **Initializer Agent** (first session): Sets up environment, creates `init.sh` and `claude-progress.txt`, makes initial commit
2. **Coding Agent** (subsequent): Reads git history + progress files, works incrementally, commits with descriptive messages

**Why This Works**: Fresh agents understand state quickly from git + progress file. Commits enable recovery. Progress tracking prevents premature completion.

### Structured Progress Files

```
# Project Progress Log

## Current Status
- Session: [timestamp]
- Focus: [current task]
- Blockers: [if any]

## Completed Features
- Feature A: ✓ (commit abc123)

## In Progress
- Feature B: [current work description]

## Pending
- Feature C: [description]

## Testing Status
- Unit: ✓
- Integration: [status]
- E2E: [status]
```

### JSON Feature Lists

```json
{
  "features": [
    {
      "id": "auth-login",
      "status": "complete",
      "tested": true,
      "commit": "abc123"
    }
  ]
}
```

Explicit feature lists prevent premature completion and duplicate work.

## Failure Mode Prevention

| Failure | Symptom | Prevention |
|---------|---------|------------|
| One-shotting | Runs out of context mid-implementation | Work on single feature at a time, commit frequently |
| Premature completion | Half-implemented feature marked done | Require E2E verification before marking complete |
| Context loss | Next session duplicates effort | Structured progress file + clear git messages |

## Multi-Context-Window Workflows

### Session Initialization Ritual

1. `pwd` - establish location
2. `git log --oneline -20` - review recent work
3. Read progress file and CLAUDE.md
4. `source init.sh` - start services
5. Run tests to verify baseline
6. Choose single feature from pending list

### Context Boundary Crossing

**Manual Compact** (Recommended): At logical breakpoints, `/compact` then `/clear`. Start fresh on next feature.

**Memory Tool Preservation**: Before context limits, save state to memory files. Update CLAUDE.md and progress file.

## Subagent Orchestration

### Orchestrator-Worker Pattern

```
Orchestrator (Opus 4.5)
├── Holds plan, routes tasks
├── No implementation work
└── Context reserved for coordination

Subagents (Sonnet/Haiku 4.5)
├── Focused expertise
├── Own context window
├── Returns condensed results
└── Task-specific configuration
```

**Why Orchestration-Only Main Agent**: When main agent implements, everything competes for same context. Subagents get clean, dedicated context.

### Model Selection

| Model | Use For | Cost |
|-------|---------|------|
| Opus 4.5 | Orchestration, complex planning | $15/M output |
| Sonnet 4.5 | Focused implementation | $15/M output |
| Haiku 4.5 | Simple tasks (90% of Sonnet capability) | $5/M output |

Haiku 4.5 makes multi-agent orchestration economically viable.

## Test-Driven Long-Horizon Tasks

### Why Tests Matter for Agents

- Tests provide objective verification targets
- Failing tests guide implementation
- Multiple rounds (2-3) yield better results
- Enable confident recovery via revert

### Progressive Testing Across Sessions

```
Session 1: Unit tests + implementation
Session 2: Integration tests
Session 3: E2E tests
Session 4: Deployment verification
```

## Failure Recovery

### Git Recovery Strategies

**Session Branches**:
```bash
git checkout -b claude-session/$(date +%s)
# Merge on success, delete on failure
```

**Checkpoint Stash**:
```bash
git stash save "claude-checkpoint: $(date)"
```

### Claude Code Checkpoints

- Esc+Esc or `/rewind` opens checkpoint menu
- Can restore conversation, code, or both
- Bash commands (`rm`, `mv`) are not tracked

## Key Insights

### What Works

1. **Explicit state** beats implicit understanding
2. **Incremental commits** beat large commits
3. **Feature lists** prevent premature completion
4. **Tests drive implementation**
5. **Multi-agent** beats single-agent for complex tasks

### Common Pitfalls

These patterns consistently cause session failures:

1. Building everything in one session → Work one feature at a time
2. Assuming prior state → Verify with git log + progress file first
3. Relying on conversation history alone → Use structured artifacts
4. Vague requirements → Define explicit acceptance criteria
5. No recovery plan → Use session branches or checkpoint stashes

## References

- [Effective harnesses for long-running agents](https://www.anthropic.com/engineering/effective-harnesses-for-long-running-agents)
- [Claude Code Best practices](https://www.anthropic.com/engineering/claude-code-best-practices)
- [Effective context engineering](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents)
- [claude-flow](https://github.com/ruvnet/claude-flow) - Multi-agent orchestration
- [continuous-claude](https://github.com/AnandChowdhary/continuous-claude) - CI/CD loop pattern

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.