claude-sessions: default new session to cwd project, attach after new/resume
Claude-Session: https://claude.ai/code/session_01SCd4vYV3ig6CpcPV9PCsC6
This commit is contained in:
@@ -333,6 +333,18 @@ def spawn_session(project_dir: str, profile: str, mode: str,
|
||||
return True
|
||||
|
||||
|
||||
def find_claude_md_dir(start: Path) -> Optional[Path]:
|
||||
"""Nearest directory at or above start (stopping at $HOME) containing a CLAUDE.md."""
|
||||
for d in [start, *start.parents]:
|
||||
if d == HOME.parent or d == Path("/"):
|
||||
break
|
||||
if (d / "CLAUDE.md").is_file():
|
||||
return d
|
||||
if d == HOME:
|
||||
break
|
||||
return None
|
||||
|
||||
|
||||
# ── Commands ─────────────────────────────────────────────────────────────────
|
||||
|
||||
def cmd_list(args) -> None:
|
||||
@@ -437,6 +449,8 @@ def cmd_recover(args) -> None:
|
||||
|
||||
profiles_cfg = load_profiles()
|
||||
print()
|
||||
# Land in the session only when resuming exactly one; several stay detached.
|
||||
attach = len(selected) == 1
|
||||
for s in selected:
|
||||
if not s["project_dir"]:
|
||||
warn(f"Skipping: project directory not found for {s['project_hash']}")
|
||||
@@ -444,7 +458,7 @@ def cmd_recover(args) -> None:
|
||||
profile_cfg = profiles_cfg.get(s["profile"], {})
|
||||
mode = getattr(args, "mode", None) or profile_cfg.get("default_mode", "quick")
|
||||
spawn_session(project_dir=s["project_dir"], profile=s["profile"],
|
||||
mode=mode, resume_id=s["session_id"])
|
||||
mode=mode, resume_id=s["session_id"], attach=attach)
|
||||
print()
|
||||
|
||||
|
||||
@@ -615,18 +629,26 @@ def cmd_menu(_args=None) -> None:
|
||||
input("\nPress Enter to return to menu…")
|
||||
|
||||
elif raw == "n":
|
||||
default_dir = find_claude_md_dir(Path.cwd())
|
||||
try:
|
||||
project = input(" Project name: ").strip()
|
||||
if default_dir:
|
||||
print(f" Found CLAUDE.md in {BOLD}{default_dir}{NC}")
|
||||
project = input(
|
||||
f" Project [{BOLD}{default_dir.name}{NC}] (Enter = use this, or type another): "
|
||||
).strip()
|
||||
if not project:
|
||||
project = str(default_dir)
|
||||
else:
|
||||
project = input(" Project name: ").strip()
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
print()
|
||||
continue
|
||||
if not project:
|
||||
continue
|
||||
import types
|
||||
a = types.SimpleNamespace(project=project, mode=None, profile=None, name=None, attach=False)
|
||||
a = types.SimpleNamespace(project=project, mode=None, profile=None, name=None, attach=True)
|
||||
print()
|
||||
cmd_spawn(a) # this exec's — won't return
|
||||
input("\nPress Enter to return to menu…")
|
||||
cmd_spawn(a) # exec's claude-tmux --attach; replaces this process
|
||||
|
||||
elif raw.isdigit():
|
||||
idx = int(raw) - 1
|
||||
@@ -656,8 +678,7 @@ def cmd_menu(_args=None) -> None:
|
||||
continue
|
||||
print()
|
||||
spawn_session(project_dir=project_dir, profile=profile,
|
||||
mode=mode, resume_id=session_id)
|
||||
input("\nPress Enter to return to menu…")
|
||||
mode=mode, resume_id=session_id, attach=True)
|
||||
else:
|
||||
print(f" {YELLOW}Unknown choice: {raw!r}{NC}")
|
||||
time.sleep(1)
|
||||
|
||||
Reference in New Issue
Block a user