multi-claude-cli 0.9.1__tar.gz → 0.10.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/PKG-INFO +26 -1
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/README.md +25 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/__init__.py +1 -1
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/cli.py +158 -1
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/completion.py +1 -1
- multi_claude_cli-0.10.0/src/multi_claude/sessions.py +436 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude_cli.egg-info/PKG-INFO +26 -1
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude_cli.egg-info/SOURCES.txt +1 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_completion.py +3 -1
- multi_claude_cli-0.10.0/tests/test_sessions.py +410 -0
- multi_claude_cli-0.9.1/src/multi_claude/sessions.py +0 -195
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/LICENSE +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/pyproject.toml +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/setup.cfg +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/__main__.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/accounts.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/actions.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/bundle.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/config.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/doctor.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/env.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/fsutil.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/history.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/hook.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/identity.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/launcher.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/lock.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/migrate.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/plan.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/platform.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/refresh.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/restore.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/routes.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/shared.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/shellpath.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/statusline.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude/usage.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude_cli.egg-info/dependency_links.txt +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude_cli.egg-info/entry_points.txt +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/src/multi_claude_cli.egg-info/top_level.txt +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_accounts.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_bundle.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_config.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_doctor.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_everyday.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_fsutil.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_handoff.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_help.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_history.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_identity.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_install.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_mcp.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_migrate.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_onboarding.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_packaging.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_plan.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_platform.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_refresh.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_rename.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_routes.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_set.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_shared_exclude.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_statusline.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_usability.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_usage.py +0 -0
- {multi_claude_cli-0.9.1 → multi_claude_cli-0.10.0}/tests/test_vscode.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: multi-claude-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.0
|
|
4
4
|
Summary: Run several Claude Code accounts side by side: separate CLAUDE_CONFIG_DIR directories, launchers, proxies, environment variables and arguments.
|
|
5
5
|
License: MIT
|
|
6
6
|
Project-URL: Homepage, https://github.com/jakoes-wu/multi-claude
|
|
@@ -331,6 +331,26 @@ old keychain token expired - inherit no -
|
|
|
331
331
|
- `error` comes with a reason on stderr, for example `plan lookup failed for work: timeout (via 127.0.0.1:7890, 10.01s)`. `tls_failed` usually means the Python that runs multi-claude has no root certificates (python.org installers ship an `Install Certificates.command`).
|
|
332
332
|
- `list --offline` skips the lookup — no token is read, nothing is sent — and prints the table without the two columns. `list --json` carries the same data in each account's `plan` object (`refresh` tells whether a token was renewed); scripts should use it instead of parsing the table. The lookup adds about a second, at most 15; a renewal that is under way is allowed to finish first (the first Ctrl-C only prints a notice), so that the new login is not lost.
|
|
333
333
|
|
|
334
|
+
### Finding a session
|
|
335
|
+
|
|
336
|
+
Forgot which account or which directory a session was started in? `sessions` lists the sessions of every account and every project directory, newest first, each followed by the command that resumes it:
|
|
337
|
+
|
|
338
|
+
```sh
|
|
339
|
+
multi-claude sessions
|
|
340
|
+
# ACCOUNT UPDATED CREATED SESSION ID TITLE
|
|
341
|
+
# work 2026-10-11 17:42 2026-10-11 16:05 3c588340-1219-48df-a231-509866789487 Fix the importer
|
|
342
|
+
# cd /path/to/project && claude-work --resume 3c588340-1219-48df-a231-509866789487
|
|
343
|
+
multi-claude sessions work # one account
|
|
344
|
+
multi-claude sessions --grep importer # title, directory or session id contains the text
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
- It shows the 30 most recent sessions; `--limit N` changes that and `--limit 0` shows all. `--json` prints every match with the full fields (`directory`, `created`, `updated`, `title_source`, `file`, `resume`). `conversations` is another name for the same command.
|
|
348
|
+
- The title is the session's name in Claude Code; a session without one shows the beginning of its first prompt, and `-` if it has no prompt at all. Times are local. `UPDATED` is the time of the last message, or the file's modification time when the session has no timestamps.
|
|
349
|
+
- A `~/.claude` that has not been turned into an account is listed as `default`.
|
|
350
|
+
- A session copied with `handoff` appears once per account that has a copy.
|
|
351
|
+
- The command is read-only and stays on this machine: it reads the start and the end of each session file, prints the title (a piece of your conversation) to the terminal, and saves or sends nothing. It does not list subagent transcripts.
|
|
352
|
+
- If the directory a session was started in no longer exists, the `cd` in the resume command fails; `claude --resume` only finds a session from the directory it was started in.
|
|
353
|
+
|
|
334
354
|
### Handing a session over to another account
|
|
335
355
|
|
|
336
356
|
Each account keeps its own sessions, so `claude --resume` in one account cannot see the sessions of another. `handoff` copies one session (its `.jsonl` file and the folder next to it with subagent transcripts and saved tool output) into the same project folder of another account:
|
|
@@ -451,6 +471,10 @@ The one in `~/.claude`, as before: multi-claude does not change it. After [migra
|
|
|
451
471
|
|
|
452
472
|
There is no command that switches which account plain `claude` uses. Besides `~/.claude`, plain `claude` reads the login in the keychain (macOS) and `~/.claude.json`, and neither would follow such a switch, so two accounts would get mixed up. Use the launchers (`claude-work`), or `multi-claude route --default work` and start `claude-auto`.
|
|
453
473
|
|
|
474
|
+
### Which account or directory was that session in?
|
|
475
|
+
|
|
476
|
+
`multi-claude sessions --grep TEXT` searches the titles, directories and ids of the sessions of all accounts and prints the command that resumes each match. See [Finding a session](#finding-a-session).
|
|
477
|
+
|
|
454
478
|
### How do I continue a conversation with another account?
|
|
455
479
|
|
|
456
480
|
Inside the Claude session, run `! multi-claude handoff OTHER`, then run the command it prints in a new terminal. See [Handing a session over to another account](#handing-a-session-over-to-another-account).
|
|
@@ -498,6 +522,7 @@ It never copies, exports, uploads or backs up a login. One command touches one:
|
|
|
498
522
|
| `multi-claude path NAME` | Print the account's directory. |
|
|
499
523
|
| `multi-claude code NAME [PATH] [-- ARGS ...]` | Open a separate VS Code instance with the account's environment (experimental). |
|
|
500
524
|
| `multi-claude handoff TARGET [--from NAME] [--session ID] [--force]` | Copy a session to another account and print the command that resumes it there. |
|
|
525
|
+
| `multi-claude sessions [NAME] [--grep TEXT] [--limit N] [--json]` | List the sessions of every account and directory, newest first, with the command that resumes each. Also `conversations`. |
|
|
501
526
|
| `multi-claude statusline install\|uninstall FILE` | Wrap the statusLine command in a settings file so that `usage` gets fresh numbers, or restore it. |
|
|
502
527
|
| `multi-claude completion bash\|zsh\|fish` | Print a shell completion script. |
|
|
503
528
|
|
|
@@ -304,6 +304,26 @@ old keychain token expired - inherit no -
|
|
|
304
304
|
- `error` comes with a reason on stderr, for example `plan lookup failed for work: timeout (via 127.0.0.1:7890, 10.01s)`. `tls_failed` usually means the Python that runs multi-claude has no root certificates (python.org installers ship an `Install Certificates.command`).
|
|
305
305
|
- `list --offline` skips the lookup — no token is read, nothing is sent — and prints the table without the two columns. `list --json` carries the same data in each account's `plan` object (`refresh` tells whether a token was renewed); scripts should use it instead of parsing the table. The lookup adds about a second, at most 15; a renewal that is under way is allowed to finish first (the first Ctrl-C only prints a notice), so that the new login is not lost.
|
|
306
306
|
|
|
307
|
+
### Finding a session
|
|
308
|
+
|
|
309
|
+
Forgot which account or which directory a session was started in? `sessions` lists the sessions of every account and every project directory, newest first, each followed by the command that resumes it:
|
|
310
|
+
|
|
311
|
+
```sh
|
|
312
|
+
multi-claude sessions
|
|
313
|
+
# ACCOUNT UPDATED CREATED SESSION ID TITLE
|
|
314
|
+
# work 2026-10-11 17:42 2026-10-11 16:05 3c588340-1219-48df-a231-509866789487 Fix the importer
|
|
315
|
+
# cd /path/to/project && claude-work --resume 3c588340-1219-48df-a231-509866789487
|
|
316
|
+
multi-claude sessions work # one account
|
|
317
|
+
multi-claude sessions --grep importer # title, directory or session id contains the text
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
- It shows the 30 most recent sessions; `--limit N` changes that and `--limit 0` shows all. `--json` prints every match with the full fields (`directory`, `created`, `updated`, `title_source`, `file`, `resume`). `conversations` is another name for the same command.
|
|
321
|
+
- The title is the session's name in Claude Code; a session without one shows the beginning of its first prompt, and `-` if it has no prompt at all. Times are local. `UPDATED` is the time of the last message, or the file's modification time when the session has no timestamps.
|
|
322
|
+
- A `~/.claude` that has not been turned into an account is listed as `default`.
|
|
323
|
+
- A session copied with `handoff` appears once per account that has a copy.
|
|
324
|
+
- The command is read-only and stays on this machine: it reads the start and the end of each session file, prints the title (a piece of your conversation) to the terminal, and saves or sends nothing. It does not list subagent transcripts.
|
|
325
|
+
- If the directory a session was started in no longer exists, the `cd` in the resume command fails; `claude --resume` only finds a session from the directory it was started in.
|
|
326
|
+
|
|
307
327
|
### Handing a session over to another account
|
|
308
328
|
|
|
309
329
|
Each account keeps its own sessions, so `claude --resume` in one account cannot see the sessions of another. `handoff` copies one session (its `.jsonl` file and the folder next to it with subagent transcripts and saved tool output) into the same project folder of another account:
|
|
@@ -424,6 +444,10 @@ The one in `~/.claude`, as before: multi-claude does not change it. After [migra
|
|
|
424
444
|
|
|
425
445
|
There is no command that switches which account plain `claude` uses. Besides `~/.claude`, plain `claude` reads the login in the keychain (macOS) and `~/.claude.json`, and neither would follow such a switch, so two accounts would get mixed up. Use the launchers (`claude-work`), or `multi-claude route --default work` and start `claude-auto`.
|
|
426
446
|
|
|
447
|
+
### Which account or directory was that session in?
|
|
448
|
+
|
|
449
|
+
`multi-claude sessions --grep TEXT` searches the titles, directories and ids of the sessions of all accounts and prints the command that resumes each match. See [Finding a session](#finding-a-session).
|
|
450
|
+
|
|
427
451
|
### How do I continue a conversation with another account?
|
|
428
452
|
|
|
429
453
|
Inside the Claude session, run `! multi-claude handoff OTHER`, then run the command it prints in a new terminal. See [Handing a session over to another account](#handing-a-session-over-to-another-account).
|
|
@@ -471,6 +495,7 @@ It never copies, exports, uploads or backs up a login. One command touches one:
|
|
|
471
495
|
| `multi-claude path NAME` | Print the account's directory. |
|
|
472
496
|
| `multi-claude code NAME [PATH] [-- ARGS ...]` | Open a separate VS Code instance with the account's environment (experimental). |
|
|
473
497
|
| `multi-claude handoff TARGET [--from NAME] [--session ID] [--force]` | Copy a session to another account and print the command that resumes it there. |
|
|
498
|
+
| `multi-claude sessions [NAME] [--grep TEXT] [--limit N] [--json]` | List the sessions of every account and directory, newest first, with the command that resumes each. Also `conversations`. |
|
|
474
499
|
| `multi-claude statusline install\|uninstall FILE` | Wrap the statusLine command in a settings file so that `usage` gets fresh numbers, or restore it. |
|
|
475
500
|
| `multi-claude completion bash\|zsh\|fish` | Print a shell completion script. |
|
|
476
501
|
|
|
@@ -16,7 +16,7 @@ import stat
|
|
|
16
16
|
import subprocess
|
|
17
17
|
import sys
|
|
18
18
|
from datetime import datetime, timedelta, timezone
|
|
19
|
-
from typing import List, Optional, Tuple
|
|
19
|
+
from typing import List, NamedTuple, Optional, Tuple
|
|
20
20
|
|
|
21
21
|
from . import (__version__, accounts, bundle, completion, doctor, history, hook, identity, launcher, migrate,
|
|
22
22
|
plan, platform, refresh, restore, routes, sessions, shellpath, statusline, usage)
|
|
@@ -55,6 +55,7 @@ COMMAND_GROUPS = [
|
|
|
55
55
|
("usage", "5-hour and 7-day usage of each account"),
|
|
56
56
|
("route, which", "choose an account by directory (launcher claude-auto)"),
|
|
57
57
|
("handoff", "copy a session to another account"),
|
|
58
|
+
("sessions", "find a session across accounts and directories"),
|
|
58
59
|
("mcp", "run `claude mcp` as an account"),
|
|
59
60
|
("run, path", "run any command as an account; print its directory"),
|
|
60
61
|
("code", "open VS Code for an account (experimental)"),
|
|
@@ -276,6 +277,18 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
276
277
|
p_handoff.add_argument("--force", action="store_true",
|
|
277
278
|
help="back up and replace a different copy of the session in TARGET")
|
|
278
279
|
_add_dry_run(p_handoff)
|
|
280
|
+
|
|
281
|
+
p_sessions = sub.add_parser("sessions", description="list the Claude sessions of every account and every directory, "
|
|
282
|
+
"newest first, each with the command that resumes it "
|
|
283
|
+
"(read-only; also available as `conversations`): "
|
|
284
|
+
"sessions [NAME] [--grep TEXT] [--limit N] [--json]")
|
|
285
|
+
p_sessions.add_argument("name", nargs="?", metavar="NAME",
|
|
286
|
+
help="only this account (`default` is the unregistered ~/.claude)")
|
|
287
|
+
p_sessions.add_argument("--grep", metavar="TEXT",
|
|
288
|
+
help="only sessions whose title, directory or id contains TEXT (case-insensitive)")
|
|
289
|
+
p_sessions.add_argument("--limit", type=int, metavar="N",
|
|
290
|
+
help="show at most N sessions, 0 for all (default: 30, or all with --json)")
|
|
291
|
+
p_sessions.add_argument("--json", action="store_true", help="print machine-readable JSON")
|
|
279
292
|
return parser
|
|
280
293
|
|
|
281
294
|
|
|
@@ -368,6 +381,7 @@ def main(argv: Optional[List[str]] = None) -> int:
|
|
|
368
381
|
if not argv:
|
|
369
382
|
# 不带参数:新用户先看到怎么上手,已有配置的用户看到账号表(方案 feature-easier-onboarding §5.1.1)。
|
|
370
383
|
return cmd_overview()
|
|
384
|
+
argv = _resolve_command_alias(argv)
|
|
371
385
|
parser = build_parser()
|
|
372
386
|
unknown = _unknown_command(parser, argv) or _misplaced_account_name(argv)
|
|
373
387
|
if unknown is not None:
|
|
@@ -411,6 +425,9 @@ def main(argv: Optional[List[str]] = None) -> int:
|
|
|
411
425
|
if args.days is not None or args.by is not None:
|
|
412
426
|
raise UsageError("--days and --by need --history")
|
|
413
427
|
return cmd_usage(args.name, args.json)
|
|
428
|
+
if args.command == "sessions":
|
|
429
|
+
# 只读:不加写锁,迁移未完成时也放行(与 list、usage 相同)。
|
|
430
|
+
return cmd_sessions(args.name, args.grep, args.limit, args.json)
|
|
414
431
|
if args.command == "which":
|
|
415
432
|
return cmd_which(args.path)
|
|
416
433
|
if args.command == "statusline":
|
|
@@ -1026,6 +1043,23 @@ All commands: multi-claude --help
|
|
|
1026
1043
|
"""
|
|
1027
1044
|
|
|
1028
1045
|
|
|
1046
|
+
# 别名 -> 子命令。不用 argparse 的 aliases:别名进了解析器,分组帮助、补全和 args.command 都要跟着处理两个名字。
|
|
1047
|
+
_COMMAND_ALIASES = {"conversations": "sessions"}
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
def _resolve_command_alias(argv: List[str]) -> List[str]:
|
|
1051
|
+
"""把子命令位置上的别名换成正式的子命令名;其它位置上的同名词(例如叫 conversations 的账号)不动。
|
|
1052
|
+
|
|
1053
|
+
子命令位置就是第一个不以 - 开头的词:顶层解析器没有带值的选项,_unknown_command 也按同一规则取词。
|
|
1054
|
+
"""
|
|
1055
|
+
for index, token in enumerate(argv):
|
|
1056
|
+
if not token.startswith("-"):
|
|
1057
|
+
if token in _COMMAND_ALIASES:
|
|
1058
|
+
return argv[:index] + [_COMMAND_ALIASES[token]] + argv[index + 1:]
|
|
1059
|
+
break
|
|
1060
|
+
return argv
|
|
1061
|
+
|
|
1062
|
+
|
|
1029
1063
|
def _unknown_command(parser: argparse.ArgumentParser, argv: List[str]) -> Optional[str]:
|
|
1030
1064
|
"""第一个非选项参数不是子命令时,返回带建议的报错文字;否则返回 None 交给 argparse。"""
|
|
1031
1065
|
word = next((token for token in argv if not token.startswith("-")), None)
|
|
@@ -1702,6 +1736,129 @@ def cmd_handoff(target_name: str, source_name: Optional[str], session_id: Option
|
|
|
1702
1736
|
return accounts.EXIT_OK
|
|
1703
1737
|
|
|
1704
1738
|
|
|
1739
|
+
class _SessionSource(NamedTuple):
|
|
1740
|
+
# 账号列显示的名字;未登记的默认目录显示 default
|
|
1741
|
+
name: str
|
|
1742
|
+
directory: str
|
|
1743
|
+
# 续聊命令里启动 Claude 的那一段
|
|
1744
|
+
launcher: str
|
|
1745
|
+
registered: bool
|
|
1746
|
+
|
|
1747
|
+
|
|
1748
|
+
_UNREGISTERED_DEFAULT = "default"
|
|
1749
|
+
# 未登记的默认目录没有启动命令,只能直接运行 claude;去掉这两个变量,在别的账号的 Claude 会话里
|
|
1750
|
+
# 运行也会落到默认目录(default 身份的启动命令同样先 unset 它们)。
|
|
1751
|
+
_DEFAULT_LAUNCHER = "env -u CLAUDE_CONFIG_DIR -u CLAUDE_SECURESTORAGE_CONFIG_DIR claude"
|
|
1752
|
+
_SESSIONS_TEXT_LIMIT = 30
|
|
1753
|
+
# 标题来自会话内容,可能是整段粘贴的提问:表格里只留开头,JSON 里也设上限
|
|
1754
|
+
_TITLE_TEXT_CHARS = 60
|
|
1755
|
+
_TITLE_JSON_CHARS = 200
|
|
1756
|
+
|
|
1757
|
+
|
|
1758
|
+
def _session_sources(config: Config, exists: bool) -> List[_SessionSource]:
|
|
1759
|
+
"""要列会话的目录:登记的每个账号,加上还没迁移成账号的默认目录 ~/.claude。"""
|
|
1760
|
+
sources = [_SessionSource(account.name, accounts.account_dir(config, account.name), "claude-" + account.name, True)
|
|
1761
|
+
for account in (config.accounts.values() if exists else [])]
|
|
1762
|
+
default = accounts.default_dir()
|
|
1763
|
+
# 做过 migrate-default 后 ~/.claude 是指向账号目录的软链,按真实路径比较才不会把同一批会话列两遍
|
|
1764
|
+
known = {os.path.realpath(source.directory) for source in sources}
|
|
1765
|
+
if os.path.isdir(os.path.join(default, "projects")) and os.path.realpath(default) not in known:
|
|
1766
|
+
sources.append(_SessionSource(_UNREGISTERED_DEFAULT, default, _DEFAULT_LAUNCHER, False))
|
|
1767
|
+
return sources
|
|
1768
|
+
|
|
1769
|
+
|
|
1770
|
+
def cmd_sessions(name: Optional[str], grep: Optional[str], limit: Optional[int], as_json: bool) -> int:
|
|
1771
|
+
"""只读列出各账号、各目录的会话,最近更新的在前,每条附续聊命令(方案 feature-session-list)。
|
|
1772
|
+
|
|
1773
|
+
会把会话标题或首条提问的开头打印出来(这是对话内容的片段),不保存、不联网、不读凭据。
|
|
1774
|
+
同一会话 ID 在多个账号里各有一份时(handoff 复制过)各列一行,不合并。
|
|
1775
|
+
"""
|
|
1776
|
+
if limit is not None and limit < 0:
|
|
1777
|
+
raise UsageError("--limit must be 0 or more")
|
|
1778
|
+
config, exists = load_config()
|
|
1779
|
+
sources = _session_sources(config, exists)
|
|
1780
|
+
if name is not None:
|
|
1781
|
+
# 名字先校验,没有配置文件时也一样:不合法的名字是用法错误(退出 2),不是“未登记”
|
|
1782
|
+
_checked_name(name)
|
|
1783
|
+
account = config.find(name) if exists else None
|
|
1784
|
+
if account is not None:
|
|
1785
|
+
# 登记账号优先:账号本身叫 default 时,`sessions default` 指的是它,不是未登记的默认目录
|
|
1786
|
+
sources = [source for source in sources if source.registered and source.name == account.name]
|
|
1787
|
+
elif name.casefold() == _UNREGISTERED_DEFAULT and any(not source.registered for source in sources):
|
|
1788
|
+
sources = [source for source in sources if not source.registered]
|
|
1789
|
+
else:
|
|
1790
|
+
error("account {!r} is not registered".format(name))
|
|
1791
|
+
return accounts.EXIT_ERROR
|
|
1792
|
+
entries = []
|
|
1793
|
+
skipped = 0
|
|
1794
|
+
needle = grep.casefold() if grep else None
|
|
1795
|
+
for source in sources:
|
|
1796
|
+
found, unreadable = sessions.list_sessions(source.directory)
|
|
1797
|
+
skipped += unreadable
|
|
1798
|
+
for session in found:
|
|
1799
|
+
full_title = sessions.clean_title(session.title, len(session.title))
|
|
1800
|
+
if needle is not None and not any(needle in text.casefold() for text in (
|
|
1801
|
+
full_title, session.directory or session.project, session.session_id)):
|
|
1802
|
+
continue
|
|
1803
|
+
entries.append((source, session, full_title))
|
|
1804
|
+
entries.sort(key=lambda entry: (-entry[1].updated.timestamp(), entry[0].name, entry[1].session_id))
|
|
1805
|
+
total = len(entries)
|
|
1806
|
+
if limit is None:
|
|
1807
|
+
limit = 0 if as_json else _SESSIONS_TEXT_LIMIT
|
|
1808
|
+
if limit:
|
|
1809
|
+
entries = entries[:limit]
|
|
1810
|
+
if skipped:
|
|
1811
|
+
warn("skipped {} session file(s) that could not be read".format(skipped))
|
|
1812
|
+
if as_json:
|
|
1813
|
+
_print_json({"schema_version": 1, "sessions": [{
|
|
1814
|
+
"account": source.name, "registered": source.registered, "directory": session.directory,
|
|
1815
|
+
"project": session.project, "session_id": session.session_id,
|
|
1816
|
+
"title": sessions.clean_title(full_title, _TITLE_JSON_CHARS), "title_source": session.title_source,
|
|
1817
|
+
"created": _iso(session.created), "updated": _iso(session.updated), "file": session.path,
|
|
1818
|
+
"resume": _resume_command(source, session)} for source, session, full_title in entries],
|
|
1819
|
+
"total": total, "skipped": skipped})
|
|
1820
|
+
return accounts.EXIT_OK
|
|
1821
|
+
if not entries:
|
|
1822
|
+
print("no sessions found")
|
|
1823
|
+
return accounts.EXIT_OK
|
|
1824
|
+
# 不用 _print_table:每条会话下面要插一行续聊命令。标题放最后一列,中文标题的显示宽度不影响前面各列对齐。
|
|
1825
|
+
rows = [("ACCOUNT", "UPDATED", "CREATED", "SESSION ID", "TITLE", None)]
|
|
1826
|
+
for source, session, full_title in entries:
|
|
1827
|
+
resume = _resume_command(source, session)
|
|
1828
|
+
if session.directory is None:
|
|
1829
|
+
resume += " (start directory unknown; project {})".format(
|
|
1830
|
+
sessions.clean_title(session.project, len(session.project)))
|
|
1831
|
+
rows.append((source.name, _local_minute(session.updated), _local_minute(session.created), session.session_id,
|
|
1832
|
+
sessions.clean_title(full_title, _TITLE_TEXT_CHARS) or "-", resume))
|
|
1833
|
+
widths = [max(len(row[index]) for row in rows) for index in range(4)]
|
|
1834
|
+
for row in rows:
|
|
1835
|
+
print(" ".join([cell.ljust(width) for cell, width in zip(row[:4], widths)] + [row[4]]).rstrip())
|
|
1836
|
+
if row[5] is not None:
|
|
1837
|
+
print(" " + row[5])
|
|
1838
|
+
if total > len(entries):
|
|
1839
|
+
print("showing {} of {} sessions; use --limit 0 for all, or --grep TEXT to narrow".format(len(entries), total))
|
|
1840
|
+
return accounts.EXIT_OK
|
|
1841
|
+
|
|
1842
|
+
|
|
1843
|
+
def _resume_command(source: _SessionSource, session: sessions.SessionInfo) -> str:
|
|
1844
|
+
"""续聊命令。Claude 按当前目录找会话,所以先 cd 到会话启动时的目录;目录未知时只给后半段。"""
|
|
1845
|
+
resume = "{} --resume {}".format(source.launcher, session.session_id)
|
|
1846
|
+
if session.directory is None:
|
|
1847
|
+
return resume
|
|
1848
|
+
return "cd {} && {}".format(shlex.quote(session.directory), resume)
|
|
1849
|
+
|
|
1850
|
+
|
|
1851
|
+
def _local_minute(moment: Optional[datetime]) -> str:
|
|
1852
|
+
if moment is None:
|
|
1853
|
+
return "-"
|
|
1854
|
+
try:
|
|
1855
|
+
return moment.astimezone().strftime("%Y-%m-%d %H:%M")
|
|
1856
|
+
except (OverflowError, OSError, ValueError):
|
|
1857
|
+
# 会话文件里的时间戳可以是任何合法的 ISO 时间;公元 1 年、9999 年这类值换算成本地时间会越界。
|
|
1858
|
+
# 当作没有时间显示,不让一条坏记录中断整张表
|
|
1859
|
+
return "-"
|
|
1860
|
+
|
|
1861
|
+
|
|
1705
1862
|
def cmd_statusline(action: str, path: str, dry_run: bool) -> int:
|
|
1706
1863
|
"""包装或还原设置文件中的 statusLine 命令。文件不合法时退出 1 且不改动;其它写入错误由 main 统一处理。"""
|
|
1707
1864
|
try:
|
|
@@ -20,7 +20,7 @@ POSITIONAL_KINDS = {
|
|
|
20
20
|
"route": ["dir", "name"], "which": ["dir"], "rename": ["name"], "mcp": ["name"],
|
|
21
21
|
"statusline": ["statusline", "file"], "handoff": ["name"], "login": ["name"], "set": ["name"],
|
|
22
22
|
"run": ["name"], "path": ["name"], "restore": ["name"], "code": ["name", "file"],
|
|
23
|
-
"export": ["name", "file"], "import": ["file", "name"],
|
|
23
|
+
"export": ["name", "file"], "import": ["file", "name"], "sessions": ["name"],
|
|
24
24
|
}
|
|
25
25
|
# 选项值是路径、应按文件补全的选项。
|
|
26
26
|
PATH_OPTIONS = ("-f", "--file", "--root", "--bin-dir", "--shared-dir")
|