long-agent

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Long Agent Sessions

长期Agent会话

Manage extended agent sessions with progress tracking and context management.
管理带有进度跟踪和上下文管理的扩展Agent会话。

Session Management

会话管理

Initialize Session

初始化会话

bash
undefined
bash
undefined

Create session file

Create session file

SESSION_ID=$(date +%Y%m%d-%H%M%S) SESSION_FILE=~/.claude/sessions/$SESSION_ID.md
mkdir -p ~/.claude/sessions
cat > $SESSION_FILE << EOF
SESSION_ID=$(date +%Y%m%d-%H%M%S) SESSION_FILE=~/.claude/sessions/$SESSION_ID.md
mkdir -p ~/.claude/sessions
cat > $SESSION_FILE << EOF

Session: $SESSION_ID

Session: $SESSION_ID

Started: $(date) Task: [Describe task]
Started: $(date) Task: [Describe task]

Progress

Progress

  • Step 1
  • Step 2
  • Step 3
  • Step 1
  • Step 2
  • Step 3

Context

Context

[Important context to remember]
[Important context to remember]

Notes

Notes

[Running notes] EOF
echo "Session: $SESSION_FILE"
undefined
[Running notes] EOF
echo "Session: $SESSION_FILE"
undefined

Track Progress

跟踪进度

bash
undefined
bash
undefined

Update progress

Update progress

echo "- [x] Completed: [description]" >> $SESSION_FILE
echo "- [x] Completed: [description]" >> $SESSION_FILE

Add note

Add note

echo "### $(date +%H:%M) - [title]" >> $SESSION_FILE echo "[notes]" >> $SESSION_FILE
undefined
echo "### $(date +%H:%M) - [title]" >> $SESSION_FILE echo "[notes]" >> $SESSION_FILE
undefined

Resume Session

恢复会话

bash
undefined
bash
undefined

List recent sessions

List recent sessions

ls -lt ~/.claude/sessions/ | head -10
ls -lt ~/.claude/sessions/ | head -10

View session

View session

cat ~/.claude/sessions/SESSION_ID.md
cat ~/.claude/sessions/SESSION_ID.md

Continue from last checkpoint

Continue from last checkpoint

tail -50 ~/.claude/sessions/SESSION_ID.md
undefined
tail -50 ~/.claude/sessions/SESSION_ID.md
undefined

Progress Patterns

进度模式

Checkpoint System

检查点系统

bash
#!/bin/bash
bash
#!/bin/bash

checkpoint.sh SESSION_ID DESCRIPTION

checkpoint.sh SESSION_ID DESCRIPTION

SESSION_FILE=~/.claude/sessions/$1.md CHECKPOINT=$2
echo "" >> $SESSION_FILE echo "## Checkpoint: $(date +%H:%M)" >> $SESSION_FILE echo "Status: $CHECKPOINT" >> $SESSION_FILE echo "Can resume from here." >> $SESSION_FILE
undefined
SESSION_FILE=~/.claude/sessions/$1.md CHECKPOINT=$2
echo "" >> $SESSION_FILE echo "## Checkpoint: $(date +%H:%M)" >> $SESSION_FILE echo "Status: $CHECKPOINT" >> $SESSION_FILE echo "Can resume from here." >> $SESSION_FILE
undefined

Milestone Tracking

里程碑跟踪

markdown
undefined
markdown
undefined

Session Progress

Session Progress

Milestones

Milestones

  • M1: Environment setup
  • M2: Core implementation
  • M3: Testing
  • M4: Documentation
  • M1: Environment setup
  • M2: Core implementation
  • M3: Testing
  • M4: Documentation

Current: M3 - Testing

Current: M3 - Testing

Completed

Completed

  • Unit tests for auth module
  • Integration test setup
  • Unit tests for auth module
  • Integration test setup

In Progress

In Progress

  • API endpoint tests
  • API endpoint tests

Blocked

Blocked

  • Need test fixtures for edge cases
undefined
  • Need test fixtures for edge cases
undefined

Context Management

上下文管理

Save Important Context

保存重要上下文

bash
#!/bin/bash
bash
#!/bin/bash

save-context.sh SESSION_ID

save-context.sh SESSION_ID

SESSION_FILE=~/.claude/sessions/$1.md
cat >> $SESSION_FILE << 'CONTEXT'
SESSION_FILE=~/.claude/sessions/$1.md
cat >> $SESSION_FILE << 'CONTEXT'

Critical Context (Don't Lose)

Critical Context (Don't Lose)

File Locations

File Locations

  • Main entry: src/index.ts
  • Config: src/config.ts
  • Tests: tests/
  • Main entry: src/index.ts
  • Config: src/config.ts
  • Tests: tests/

Key Decisions

Key Decisions

  • Using JWT for auth (not sessions)
  • PostgreSQL for persistence
  • Redis for caching
  • Using JWT for auth (not sessions)
  • PostgreSQL for persistence
  • Redis for caching

Current State

Current State

  • Auth module: complete
  • API routes: 80% done
  • Tests: 40% coverage CONTEXT
undefined
  • Auth module: complete
  • API routes: 80% done
  • Tests: 40% coverage CONTEXT
undefined

Context Recovery

上下文恢复

bash
undefined
bash
undefined

Get context for resumption

Get context for resumption

CONTEXT=$(grep -A 50 "## Critical Context" ~/.claude/sessions/$SESSION_ID.md)
gemini -m pro -o text -e "" "I'm resuming a long coding session. Here's the context:
$CONTEXT
Help me remember:
  1. Where was I?
  2. What's the next step?
  3. Any gotchas to remember?"
undefined
CONTEXT=$(grep -A 50 "## Critical Context" ~/.claude/sessions/$SESSION_ID.md)
gemini -m pro -o text -e "" "I'm resuming a long coding session. Here's the context:
$CONTEXT
Help me remember:
  1. Where was I?
  2. What's the next step?
  3. Any gotchas to remember?"
undefined

Bearings Check

状态检查

Get Your Bearings

查看当前状态

bash
#!/bin/bash
bash
#!/bin/bash

bearings.sh - Where am I in this task?

bearings.sh - Where am I in this task?

echo "=== Current Session Status ===" echo ""
echo "=== Current Session Status ===" echo ""

Git status

Git status

echo "### Git Status" git status --short
echo "" echo "### Recent Commits" git log --oneline -5
echo "" echo "### Modified Files" git diff --stat HEAD~3
echo "" echo "### TODO Items" grep -r "TODO|FIXME" src/ --include="*.ts" | head -10
undefined
echo "### Git Status" git status --short
echo "" echo "### Recent Commits" git log --oneline -5
echo "" echo "### Modified Files" git diff --stat HEAD~3
echo "" echo "### TODO Items" grep -r "TODO|FIXME" src/ --include="*.ts" | head -10
undefined

Progress Summary

进度总结

bash
undefined
bash
undefined

Generate progress summary

Generate progress summary

gemini -m pro -o text -e "" "Summarize progress on this session:
Session log: $(tail -100 ~/.claude/sessions/$SESSION_ID.md)
Git activity: $(git log --oneline -10)
Provide:
  1. What's been accomplished
  2. Current status
  3. Remaining work
  4. Estimated completion"
undefined
gemini -m pro -o text -e "" "Summarize progress on this session:
Session log: $(tail -100 ~/.claude/sessions/$SESSION_ID.md)
Git activity: $(git log --oneline -10)
Provide:
  1. What's been accomplished
  2. Current status
  3. Remaining work
  4. Estimated completion"
undefined

Long Task Patterns

长期任务模式

Multi-Day Task

多日任务

markdown
undefined
markdown
undefined

Multi-Day Task: [Name]

Multi-Day Task: [Name]

Day 1 - [Date]

Day 1 - [Date]

Accomplished

Accomplished

  • [items]
  • [items]

Blocked

Blocked

  • [items]
  • [items]

Tomorrow

Tomorrow

  • [items]

  • [items]

Day 2 - [Date]

Day 2 - [Date]

Context from Yesterday

Context from Yesterday

[summary]
[summary]

Accomplished

Accomplished

  • [items]
undefined
  • [items]
undefined

Handoff Document

交接文档

When handing off to another session or agent:
markdown
undefined
当交接给另一个会话或Agent时:
markdown
undefined

Task Handoff

Task Handoff

What This Is

What This Is

[Brief description]
[Brief description]

Current State

Current State

  • [Bullet points of where things stand]
  • [Bullet points of where things stand]

What's Working

What's Working

  • [Completed items]
  • [Completed items]

What's Not Working

What's Not Working

  • [Issues/blockers]
  • [Issues/blockers]

Next Steps

Next Steps

  1. [Specific step]
  2. [Specific step]
  1. [Specific step]
  2. [Specific step]

Key Files

Key Files

  • src/main.ts
    - Entry point
  • src/auth/
    - Auth module (done)
  • src/api/
    - API routes (in progress)
  • src/main.ts
    - Entry point
  • src/auth/
    - Auth module (done)
  • src/api/
    - API routes (in progress)

Commands to Know

Commands to Know

bash
npm run dev    # Start development
npm test       # Run tests
npm run build  # Build for production
bash
npm run dev    # Start development
npm test       # Run tests
npm run build  # Build for production

Gotchas

Gotchas

  • [Things that might trip you up]
undefined
  • [Things that might trip you up]
undefined

Session Templates

会话模板

Feature Development

功能开发

bash
cat > ~/.claude/sessions/feature-template.md << 'EOF'
bash
cat > ~/.claude/sessions/feature-template.md << 'EOF'

Feature: [Name]

Feature: [Name]

Requirements

Requirements

  • Requirement 1
  • Requirement 2
  • Requirement 1
  • Requirement 2

Design

Design

[Architecture notes]
[Architecture notes]

Implementation Progress

Implementation Progress

  • Step 1
  • Step 2
  • Step 3
  • Step 1
  • Step 2
  • Step 3

Testing

Testing

  • Unit tests
  • Integration tests
  • Manual testing
  • Unit tests
  • Integration tests
  • Manual testing

Documentation

Documentation

  • Code comments
  • README update
  • API docs EOF
undefined
  • Code comments
  • README update
  • API docs EOF
undefined

Bug Fix

Bug修复

bash
cat > ~/.claude/sessions/bugfix-template.md << 'EOF'
bash
cat > ~/.claude/sessions/bugfix-template.md << 'EOF'

Bug Fix: [Issue ID/Description]

Bug Fix: [Issue ID/Description]

Symptom

Symptom

[What's happening]
[What's happening]

Expected

Expected

[What should happen]
[What should happen]

Investigation

Investigation

  • Reproduced locally
  • Found root cause
  • Identified fix
  • Reproduced locally
  • Found root cause
  • Identified fix

Fix

Fix

[Description of fix]
[Description of fix]

Verification

Verification

  • Fix works
  • No regressions
  • Tests added EOF
undefined
  • Fix works
  • No regressions
  • Tests added EOF
undefined

Best Practices

最佳实践

  1. Log frequently - Update progress often
  2. Save context - What would you need to resume?
  3. Create checkpoints - Mark safe resume points
  4. Summarize before breaks - Capture state of mind
  5. Use templates - Consistent structure helps
  6. Track blockers - Note what's waiting
  7. Handoff cleanly - Assume fresh context next time
  1. 频繁记录 - 经常更新进度
  2. 保存上下文 - 恢复会话时你需要什么信息?
  3. 创建检查点 - 标记安全的恢复点
  4. 休息前总结 - 记录当前的思路状态
  5. 使用模板 - 一致的结构更有帮助
  6. 跟踪阻塞问题 - 记录待处理的事项
  7. 清晰交接 - 假设下次会话是全新的上下文