diff --git a/.gitignore b/.gitignore index 86763a3..90b00f8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ SESSION_STATE.md .test-results/ .workflow-state.json specs/ +build/ +dist/ +*.egg-info/ diff --git a/README.md b/README.md index b49fa27..51039e9 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d1964d9 --- /dev/null +++ b/pyproject.toml @@ -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"]