Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ SESSION_STATE.md
.test-results/
.workflow-state.json
specs/
build/
dist/
*.egg-info/
51 changes: 45 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@

Launch a new Claude Code session in any project. When a session's context window fills up, this script seamlessly transfers work to a fresh Claude instance in a new terminal tab — no human intervention needed. Also supports switching to a different project entirely.

## Quick start

```bash
# 1. Install (Python 3.8+, no other dependencies)
pip install git+https://github.com/grobomo/context-reset

# 2. Add a stop hook to ~/.claude/settings.json
```

Add this to your Claude Code settings (`~/.claude/settings.json`):

```json
{
"hooks": {
"Stop": [
{
"type": "command",
"command": "new-session --project-dir $CLAUDE_PROJECT_DIR"
}
]
}
}
```

That's it. Claude will automatically reset to a fresh session when context gets heavy, carrying over TODO.md and a readable summary of the conversation.

If you already have stop hooks, just add the entry to your existing `Stop` array.

## How it works

1. Reads the last 500 JSONL lines from the transcript (efficient reverse-read, no full file load)
Expand Down Expand Up @@ -59,16 +87,27 @@ Each new tab gets:

## Integration with Claude Code hooks

Add to a [stop hook](https://docs.anthropic.com/en/docs/claude-code/hooks) module to let Claude trigger resets autonomously when context gets heavy:

```
python C:/path/to/context-reset/new_session.py --project-dir $CLAUDE_PROJECT_DIR
Add to a [stop hook](https://docs.anthropic.com/en/docs/claude-code/hooks) in `~/.claude/settings.json` to let Claude trigger resets autonomously when context gets heavy:

```json
{
"hooks": {
"Stop": [
{
"type": "command",
"command": "new-session --project-dir $CLAUDE_PROJECT_DIR"
}
]
}
}
```

The script reads `$CLAUDE_PROJECT_DIR` by default, so from a hook you can simply:
The script reads `$CLAUDE_PROJECT_DIR` by default, so from a hook you can simply use `new-session`.

If you prefer to run from source instead of pip install:

```
python C:/path/to/context-reset/new_session.py
python /path/to/context-reset/new_session.py --project-dir $CLAUDE_PROJECT_DIR
```

## Session continuity
Expand Down
18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[build-system]
requires = ["setuptools>=64"]
build-backend = "setuptools.build_meta"

[project]
name = "claude-context-reset"
version = "1.0.0"
description = "Launch new Claude Code sessions with automatic state handoff"
readme = "README.md"
license = "MIT"
requires-python = ">=3.8"

[project.scripts]
new-session = "new_session:main"
context-reset = "new_session:main"

[tool.setuptools]
py-modules = ["new_session", "context_reset", "task_claims"]
Loading