clauderan 0.1.0

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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +215 -0
  3. package/dist/index.js +2828 -0
  4. package/package.json +40 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Michael
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,215 @@
1
+ # ran
2
+
3
+ [![CI](https://github.com/Michaelliv/clauderan/actions/workflows/ci.yml/badge.svg)](https://github.com/Michaelliv/clauderan/actions/workflows/ci.yml)
4
+ [![codecov](https://codecov.io/gh/Michaelliv/clauderan/graph/badge.svg)](https://codecov.io/gh/Michaelliv/clauderan)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+ [![Bun](https://img.shields.io/badge/Bun-%23000000.svg?logo=bun&logoColor=white)](https://bun.sh)
7
+ [![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
8
+
9
+ Search and browse your Claude Code bash command history.
10
+
11
+ ```
12
+ "What was that docker command I ran yesterday?"
13
+ ```
14
+
15
+ ```bash
16
+ $ ran search docker --limit 3
17
+
18
+ [ok] docker build -t myapp .
19
+ Build the application image
20
+ 1/15/2025, 10:30 AM | /projects/myapp
21
+
22
+ [ok] docker push myapp:latest
23
+ Push to registry
24
+ 1/15/2025, 10:35 AM | /projects/myapp
25
+
26
+ [error] docker compose up -d
27
+ Start services
28
+ 1/14/2025, 3:20 PM | /projects/api
29
+ ```
30
+
31
+ Every bash command Claude Code runs is logged in session files. `ran` indexes them into a searchable database so you can find that command you ran last week, see what worked, and avoid repeating mistakes.
32
+
33
+ ## Install
34
+
35
+ ```bash
36
+ # With Bun (recommended)
37
+ bun add -g clauderan
38
+
39
+ # With npm
40
+ npm install -g clauderan
41
+
42
+ # Or build from source
43
+ git clone https://github.com/Michaelliv/clauderan
44
+ cd clauderan
45
+ bun install
46
+ bun run build # Creates ./ran binary
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ ```bash
52
+ # Search for commands containing "docker"
53
+ ran search docker
54
+
55
+ # Use regex patterns
56
+ ran search "git commit.*fix" --regex
57
+
58
+ # Filter by project directory
59
+ ran search npm --cwd /projects/myapp
60
+
61
+ # List recent commands
62
+ ran list
63
+ ran list --limit 50
64
+
65
+ # Manually sync (usually automatic)
66
+ ran sync
67
+ ran sync --force # Re-index everything
68
+ ```
69
+
70
+ ## Examples
71
+
72
+ **Find a failing build command:**
73
+ ```bash
74
+ $ ran search "npm run build" --limit 5
75
+ # Look for [error] entries to see what failed
76
+ ```
77
+
78
+ **What commands did I run in a specific project?**
79
+ ```bash
80
+ $ ran search "" --cwd /projects/api --limit 20
81
+ # Empty pattern matches everything, filtered by directory
82
+ ```
83
+
84
+ **Re-run something from last week:**
85
+ ```bash
86
+ $ ran list --limit 100
87
+ # Scroll through recent history, copy what you need
88
+ ```
89
+
90
+ ## Commands
91
+
92
+ ### `ran search <pattern>`
93
+
94
+ Search command history by substring or regex.
95
+
96
+ | Flag | Description |
97
+ |------|-------------|
98
+ | `--regex`, `-r` | Treat pattern as regular expression |
99
+ | `--cwd <path>` | Filter by working directory |
100
+ | `--limit`, `-n <N>` | Limit number of results |
101
+ | `--no-sync` | Skip auto-sync before searching |
102
+
103
+ ### `ran list`
104
+
105
+ Show recent commands, newest first.
106
+
107
+ | Flag | Description |
108
+ |------|-------------|
109
+ | `--limit`, `-n <N>` | Number of commands (default: 20) |
110
+ | `--no-sync` | Skip auto-sync before listing |
111
+
112
+ ### `ran sync`
113
+
114
+ Index new commands from Claude Code sessions.
115
+
116
+ | Flag | Description |
117
+ |------|-------------|
118
+ | `--force`, `-f` | Re-index all sessions from scratch |
119
+
120
+ ## How It Works
121
+
122
+ Claude Code stores conversation data in `~/.claude/projects/`. Each session is a JSONL file containing messages, tool calls, and results.
123
+
124
+ `ran` scans these files, extracts Bash tool invocations, and indexes them into a local SQLite database at `~/.ran/history.db`. It tracks file positions so subsequent syncs only process new content.
125
+
126
+ **Auto-sync**: By default, `search` and `list` automatically sync before returning results. Use `--no-sync` to skip this if you want faster queries.
127
+
128
+ **Privacy**: `ran` is read-only and local-only. It reads Claude's session files but never modifies them. No data is sent anywhere.
129
+
130
+ ## Data Model
131
+
132
+ Each indexed command includes:
133
+
134
+ | Field | Description |
135
+ |-------|-------------|
136
+ | `command` | The bash command that was executed |
137
+ | `description` | What Claude said it does (e.g., "Build the project") |
138
+ | `cwd` | Working directory when command ran |
139
+ | `timestamp` | When the command was executed |
140
+ | `is_error` | Whether the command failed |
141
+ | `stdout` | Command output (stored, not displayed by default) |
142
+ | `stderr` | Error output (stored, not displayed by default) |
143
+ | `session_id` | Which Claude session ran this command |
144
+
145
+ ## For AI Agents
146
+
147
+ If you're an AI agent (like Claude Code) reading this to understand the tool:
148
+
149
+ ### When to use `ran`
150
+
151
+ - User asks "what was that command I/you ran?"
152
+ - User wants to find a command from a previous session
153
+ - User needs to recall commands from a specific project
154
+ - User wants to see commands that failed
155
+
156
+ ### When NOT to use `ran`
157
+
158
+ - Finding files by name → use `Glob`
159
+ - Searching file contents → use `Grep`
160
+ - Checking recent conversation context → already in your context
161
+ - User's personal shell history → not indexed, only Claude's commands
162
+
163
+ ### Capabilities
164
+
165
+ ```
166
+ ran search <pattern>
167
+ Flags: --regex, --cwd <path>, --limit <n>, --no-sync
168
+ Returns: Matching commands with status, description, timestamp, directory
169
+
170
+ ran list
171
+ Flags: --limit <n>, --no-sync
172
+ Returns: Recent commands, newest first
173
+
174
+ ran sync
175
+ Flags: --force
176
+ Returns: Count of files scanned and commands indexed
177
+ ```
178
+
179
+ ### Example workflow
180
+
181
+ **User**: "What kubectl command did you use to check the pods?"
182
+
183
+ **Agent**: Let me search my command history:
184
+ ```bash
185
+ ran search kubectl --limit 10
186
+ ```
187
+
188
+ Then relay the relevant command(s) to the user.
189
+
190
+ ## Development
191
+
192
+ ```bash
193
+ # Install dependencies
194
+ bun install
195
+
196
+ # Run directly
197
+ bun run src/index.ts search docker
198
+
199
+ # Run tests
200
+ bun test
201
+
202
+ # Run tests with coverage
203
+ bun test --coverage
204
+
205
+ # Build binary
206
+ bun run build
207
+ ```
208
+
209
+ ## About the name
210
+
211
+ `ran` — past tense of "run." It shows you what commands *ran*.
212
+
213
+ ---
214
+
215
+ MIT License