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
|
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 ─────────────────────────────────────────────────────────────────
|
# ── Commands ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
def cmd_list(args) -> None:
|
def cmd_list(args) -> None:
|
||||||
@@ -437,6 +449,8 @@ def cmd_recover(args) -> None:
|
|||||||
|
|
||||||
profiles_cfg = load_profiles()
|
profiles_cfg = load_profiles()
|
||||||
print()
|
print()
|
||||||
|
# Land in the session only when resuming exactly one; several stay detached.
|
||||||
|
attach = len(selected) == 1
|
||||||
for s in selected:
|
for s in selected:
|
||||||
if not s["project_dir"]:
|
if not s["project_dir"]:
|
||||||
warn(f"Skipping: project directory not found for {s['project_hash']}")
|
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"], {})
|
profile_cfg = profiles_cfg.get(s["profile"], {})
|
||||||
mode = getattr(args, "mode", None) or profile_cfg.get("default_mode", "quick")
|
mode = getattr(args, "mode", None) or profile_cfg.get("default_mode", "quick")
|
||||||
spawn_session(project_dir=s["project_dir"], profile=s["profile"],
|
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()
|
print()
|
||||||
|
|
||||||
|
|
||||||
@@ -615,18 +629,26 @@ def cmd_menu(_args=None) -> None:
|
|||||||
input("\nPress Enter to return to menu…")
|
input("\nPress Enter to return to menu…")
|
||||||
|
|
||||||
elif raw == "n":
|
elif raw == "n":
|
||||||
|
default_dir = find_claude_md_dir(Path.cwd())
|
||||||
try:
|
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):
|
except (KeyboardInterrupt, EOFError):
|
||||||
print()
|
print()
|
||||||
continue
|
continue
|
||||||
if not project:
|
if not project:
|
||||||
continue
|
continue
|
||||||
import types
|
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()
|
print()
|
||||||
cmd_spawn(a) # this exec's — won't return
|
cmd_spawn(a) # exec's claude-tmux --attach; replaces this process
|
||||||
input("\nPress Enter to return to menu…")
|
|
||||||
|
|
||||||
elif raw.isdigit():
|
elif raw.isdigit():
|
||||||
idx = int(raw) - 1
|
idx = int(raw) - 1
|
||||||
@@ -656,8 +678,7 @@ def cmd_menu(_args=None) -> None:
|
|||||||
continue
|
continue
|
||||||
print()
|
print()
|
||||||
spawn_session(project_dir=project_dir, profile=profile,
|
spawn_session(project_dir=project_dir, profile=profile,
|
||||||
mode=mode, resume_id=session_id)
|
mode=mode, resume_id=session_id, attach=True)
|
||||||
input("\nPress Enter to return to menu…")
|
|
||||||
else:
|
else:
|
||||||
print(f" {YELLOW}Unknown choice: {raw!r}{NC}")
|
print(f" {YELLOW}Unknown choice: {raw!r}{NC}")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user