feat: add --claude-dir flag to target specific Claude instances#1
feat: add --claude-dir flag to target specific Claude instances#1Gremiger wants to merge 2 commits into
Conversation
Adds -C/--claude-dir <PATH> flag so users with multiple Claude instances (e.g. ~/.claude-work, ~/.claude-personal) can point ccwasted at any of them without relying on the ~/.claude default. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds support for targeting an alternate Claude instance directory via a new -C/--claude-dir flag, so scanning and rule injection can operate on non-default Claude directories while preserving the existing ~/.claude behavior when the flag is omitted.
Changes:
- Add
-C/--claude-dirCLI flag and plumb it throughmaininto scanner + injector. - Update session scanning to read from
<CLAUDE_DIR>/projectswhen provided. - Update rule injection to write
ccwasted-rules.mdand modifyCLAUDE.mdunder the selected Claude base directory.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/main.rs |
Adds the new CLI flag and passes the selected base directory into scanning/injection. |
src/scanner.rs |
Extends find_sessions to accept an optional Claude base directory and derive the projects/ path from it. |
src/inject.rs |
Extends inject_rules to accept an optional Claude base directory for writing rules/CLAUDE.md updates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Use Option<PathBuf> for --claude-dir CLI arg (with DirPath hint) to
avoid manual String→PathBuf conversion
- Use .join(".claude").join("projects") for clarity and portability
- Use imported Path in function signatures instead of fully-qualified
std::path::Path
- Add unit test for find_sessions with a custom claude_base
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pub fn find_sessions(days: u32, project_dir: Option<&str>) -> Vec<FoundSession> { | ||
| pub fn find_sessions(days: u32, project_dir: Option<&str>, claude_base: Option<&Path>) -> Vec<FoundSession> { | ||
| let today = Local::now().date_naive(); | ||
| let since = today - chrono::Duration::days(days as i64 - 1); |
There was a problem hiding this comment.
since uses days as i64 - 1, which produces a negative duration when days == 0 (e.g., -d 0), making the date range start in the future and likely returning no sessions. Consider clamping to a minimum of 1 day (e.g., use days.saturating_sub(1) for the duration, or validate days >= 1 before computing the range).
| let since = today - chrono::Duration::days(days as i64 - 1); | |
| let effective_days = days.max(1) as i64; | |
| let since = today - chrono::Duration::days(effective_days - 1); |
| let claude_dir = cli.claude_dir.as_deref(); | ||
| let found = scanner::find_sessions(cli.days, cli.project_dir.as_deref(), claude_dir); | ||
| if found.is_empty() { |
There was a problem hiding this comment.
When --claude-dir is provided but points to a non-existent instance (or missing projects/), find_sessions returns empty and the CLI prints "No conversations found for today", which is misleading for a bad path. Consider validating the provided claude_dir (and its projects subdir) up front and emitting a specific error message when it’s invalid/unreadable.
| let sessions = find_sessions(30, None, Some(&tmp)); | ||
| std::fs::remove_dir_all(&tmp).unwrap(); | ||
|
|
There was a problem hiding this comment.
The test manually calls remove_dir_all(&tmp).unwrap() mid-test; if an assertion panics before cleanup (or if removal fails), it can leave behind temp state and create follow-on failures. Using an RAII tempdir (or a scoped cleanup guard) would ensure cleanup happens reliably even on panic.
| let tmp = std::env::temp_dir().join("ccwasted_test_claude_base"); | ||
| let project_dir = tmp.join("projects").join("-test-project"); | ||
| std::fs::create_dir_all(&project_dir).unwrap(); | ||
|
|
There was a problem hiding this comment.
This test uses a fixed temp directory name under std::env::temp_dir(), which can cause flakiness if tests run in parallel or a previous run left the directory behind (and could also pick up unrelated files). Prefer using a unique temp dir (e.g., via tempfile::tempdir() or by appending a random/UUID suffix).
Summary
-C/--claude-dir <PATH>flag to point ccwasted at any Claude instance directory instead of always defaulting to~/.claude<PATH>/projects/for reading sessions; inject writes rules to<PATH>/CLAUDE.mdUsage
Test plan
ccwasted(no flag) still reads from~/.claudeas beforeccwasted -C ~/.claude-workreads sessions from~/.claude-work/projects/ccwasted -C ~/.claude-personal --injectwrites rules to~/.claude-personal/CLAUDE.mdccwasted --helpshows the new-C/--claude-dirflag with description🤖 Generated with Claude Code