anthropics / anthropics/claude-code-action

Enable Claude to remember previous run context

Đang mở
#925 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
dev-experience enhancement feature-request p3
Ngôn ngữ chính
TypeScript
Star
8.9k
Fork
2.1k
Merge trung bình
3 ngày 9 giờ
Pull request đã merge (30 ngày)
10

Mô tả

## Summary

Currently, each Claude run starts with zero knowledge of previous interactions on the same PR/issue. While previous comments are included as raw text in the prompt, there's no structured way to carry over what was done, what decisions were made, or what's still pending.

This proposal adds lightweight session state persistence between runs.

## Problem

When a user triggers Claude multiple times on the same PR/issue:
1. Claude has no structured understanding of what it did in previous runs
2. Previous comments are included as raw text, wasting tokens without providing clear context
3. Claude may repeat work, contradict earlier decisions, or lose track of multi-step tasks
4. Users have to re-explain context that Claude should already know

## Proposed Solution

Embed structured session state as a hidden HTML comment in Claude's tracking comment, then parse it on the next run.

### 1. Serialize session state at end of run

Instruct Claude (via the base prompt) to append a hidden HTML comment with structured data:

```html

```

### 2. Parse previous session state on next run

During prompt generation, detect and parse `claude-session-state` blocks from previous Claude comments.

### 3. Inject as structured context in the prompt

```xml


fixed null check in auth.ts, added unit test
used JWT instead of session tokens per user request
performance test not yet run

```

### Tradeoffs of this approach

- **Pros**: No external storage needed, GitHub comments act as persistence layer, minimal architecture change
- **Cons**: Comment length limit (65536 chars) includes state, comment edits could break state, relies on Claude generating valid JSON consistently

### Alternative approaches worth considering

- **Summarize previous comments at run start** — Instead of explicit state, use the existing fetched comments and summarize them during prompt generation. Simplest approach with no schema to maintain, but less structured.
- **State file in branch** — Commit `.claude/session-state.json` to the working branch. Most reliable but adds noise to commit history.
- **GitHub Actions artifacts** — Store state via `actions/upload-artifact`, restore on next run. Clean separation but adds infrastructure complexity.

## Scope

This could be implemented incrementally:

1. **Phase 1**: Add instructions to the base prompt for Claude to include session state in its comment
2. **Phase 2**: Parse previous session states from existing comments during `fetchGitHubData()`
3. **Phase 3**: Inject parsed state into the prompt as ``

Phase 1 alone could ship as an initial PR since it lays the groundwork without changing existing behavior.

## Notes

- Applies to tag mode only (agent mode doesn't use tracking comments)
- Open to other approaches — would appreciate maintainer input on the preferred direction
- Happy to submit a PR if this direction sounds reasonable

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.