Skip to content

feat: add --claude-dir flag to target specific Claude instances#1

Open
Gremiger wants to merge 2 commits into
fyso-dev:mainfrom
Gremiger:feat/claude-dir-flag
Open

feat: add --claude-dir flag to target specific Claude instances#1
Gremiger wants to merge 2 commits into
fyso-dev:mainfrom
Gremiger:feat/claude-dir-flag

Conversation

@Gremiger

Copy link
Copy Markdown

Summary

  • Adds -C/--claude-dir <PATH> flag to point ccwasted at any Claude instance directory instead of always defaulting to ~/.claude
  • Scanner uses <PATH>/projects/ for reading sessions; inject writes rules to <PATH>/CLAUDE.md
  • Fully backward-compatible — omitting the flag preserves existing behavior

Usage

# Default (~/.claude)
ccwasted

# Target a specific instance
ccwasted -C ~/.claude-work
ccwasted -C ~/.claude-personal

# Combine with other flags
ccwasted -C ~/.claude-work -d 7 --status
ccwasted -C ~/.claude-personal --inject

Test plan

  • ccwasted (no flag) still reads from ~/.claude as before
  • ccwasted -C ~/.claude-work reads sessions from ~/.claude-work/projects/
  • ccwasted -C ~/.claude-personal --inject writes rules to ~/.claude-personal/CLAUDE.md
  • ccwasted --help shows the new -C/--claude-dir flag with description

🤖 Generated with Claude Code

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-dir CLI flag and plumb it through main into scanner + injector.
  • Update session scanning to read from <CLAUDE_DIR>/projects when provided.
  • Update rule injection to write ccwasted-rules.md and modify CLAUDE.md under 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.

Comment thread src/main.rs Outdated
Comment thread src/scanner.rs Outdated
Comment thread src/scanner.rs Outdated
Comment thread src/inject.rs Outdated
- 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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/scanner.rs
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);

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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);

Copilot uses AI. Check for mistakes.
Comment thread src/main.rs
Comment on lines +58 to 60
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() {

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread src/scanner.rs
Comment on lines +208 to +210
let sessions = find_sessions(30, None, Some(&tmp));
std::fs::remove_dir_all(&tmp).unwrap();

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread src/scanner.rs
Comment on lines +199 to +202
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();

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants