claude-code-toolkit 0.3.1

Claude Code management tool for credential sync, session monitoring, and GitHub integration
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# claude-code-toolkit

_Part of the [GoodieBag](https://github.com/deepbrainspace/goodiebag) collection
of tools and libraries_

[![Crates.io](https://img.shields.io/crates/v/claude-code-toolkit.svg)](https://crates.io/crates/claude-code-toolkit)
[![Rust](https://img.shields.io/badge/rust-2024-orange.svg)](https://www.rust-lang.org/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg)](https://github.com/deepbrainspace/goodiebag/actions)

Claude Code management tool for automatic credential synchronization to GitHub,
session monitoring, and daemon service management.

## Features

- **πŸ”„ Automatic Credential Sync**: Syncs Claude Code credentials to GitHub
  organization/repository secrets
- **⏰ Smart Scheduling**: Monitors token expiry and syncs 1 minute after new
  token generation
- **🎯 Multi-Target Support**: Sync to multiple GitHub organizations and
  repositories simultaneously
- **πŸ“Š Session Monitoring**: Real-time session timer and status tracking with
  desktop notifications
- **πŸ”§ Systemd User Service Integration**: Runs as a background daemon with
  automatic startup
- **πŸš€ High Performance**: Written in Rust for minimal resource usage and
  maximum reliability

## Installation

### Option 1: Cargo Install (Recommended)

```bash
# Install from crates.io
cargo install claude-code-toolkit

# Ensure ~/.cargo/bin is in your PATH
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
```

### Option 2: From Source

```bash
# Clone the repository
git clone https://github.com/deepbrainspace/goodiebag
cd goodiebag/packages/claude-code-toolkit

# Build and install
cargo install --path .
```

**Important**: The binary must remain in a stable location for the daemon
service to work. If you move the binary after installing the service, run
`claude-code-toolkit service install` again.

## Prerequisites

- **Rust 2024 Edition** (rustc 1.80+)
- **GitHub CLI** (`gh`) installed and authenticated
- **GitHub Personal Access Token** with appropriate permissions (see setup
  below)
- **Claude Code** installed and authenticated
- **Linux/macOS** with systemd (for daemon functionality)

### GitHub Setup

#### 1. Install GitHub CLI

```bash
# Ubuntu/Debian
sudo apt install gh

# macOS
brew install gh

# Or download from https://cli.github.com/
```

#### 2. Create GitHub Personal Access Token

1. Go to
   [GitHub Settings > Developer Settings > Personal Access Tokens > Fine-grained tokens]https://github.com/settings/personal-access-tokens/new
2. Create a new token with these permissions:
   - **Repository access**: Select specific repositories OR all repositories
     (depending on your needs)
   - **Repository permissions**:
     - `Secrets: Write` (required for updating repository secrets)
     - `Metadata: Read` (required for basic repository access)
   - **Organization permissions** (if syncing to organizations):
     - `Organization secrets: Write` (required for updating organization
       secrets)
     - `Members: Read` (required for organization access)

#### 3. Authenticate GitHub CLI

```bash
# Login using your PAT
gh auth login

# Or set token directly
export GITHUB_TOKEN="your_github_pat_here"
gh auth login --with-token <<< "$GITHUB_TOKEN"

# Verify authentication
gh auth status
```

## Quick Start

1. **Install and Configure**:

```bash
# Add GitHub organization
claude-code-toolkit org add your-org-name

# Add GitHub repository
claude-code-toolkit repo add owner/repository

# Install and start daemon
claude-code-toolkit service install
```

2. **Check Status**:

```bash
claude-code-toolkit status
```

3. **Real-time Session Timer**:

```bash
claude-code-toolkit timer
```

## Commands

### Session Management

- `claude-code-toolkit status` - Show comprehensive session and sync status
- `claude-code-toolkit timer` - Real-time session timer with progress bar

### Organization Management

- `claude-code-toolkit org add <name> [--secret-name NAME]` - Add GitHub
  organization
- `claude-code-toolkit org remove <name>` - Remove organization
- `claude-code-toolkit org list` - List configured organizations with
  availability

### Repository Management

- `claude-code-toolkit repo add <owner/repo> [--secret-name NAME]` - Add
  repository
- `claude-code-toolkit repo remove <owner/repo>` - Remove repository
- `claude-code-toolkit repo list` - List configured repositories

### Sync Operations

- `claude-code-toolkit sync now` - Force immediate credential sync
- `claude-code-toolkit sync status` - Show detailed sync status for all targets
- `claude-code-toolkit sync logs [--lines N]` - View daemon logs

### Service Management

- `claude-code-toolkit service install` - Install and start systemd user daemon
- `claude-code-toolkit service uninstall [--keep-config]` - Uninstall daemon
- `claude-code-toolkit service start/stop/restart` - Control daemon
- `claude-code-toolkit service enable/disable` - Control auto-start on login

### Configuration

- `claude-code-toolkit configure` - Interactive configuration wizard _(coming
  soon)_

## Configuration

### Command-Line Configuration

You can configure targets using the CLI commands:

```bash
# Add organizations
claude-code-toolkit org add my-org --secret-name CLAUDE_TOKEN
claude-code-toolkit org add another-org --secret-name CUSTOM_CLAUDE_TOKEN

# Add repositories
claude-code-toolkit repo add owner/repo --secret-name CLAUDE_CODE_TOKEN
claude-code-toolkit repo add owner/special-repo --secret-name CUSTOM_TOKEN

# List current configuration
claude-code-toolkit org list
claude-code-toolkit repo list
```

### Direct YAML Configuration

**Alternative**: You can directly edit the configuration file at
`~/.goodiebag/claude-code/config.yml`:

```yaml
daemon:
  log_level: info # debug, info, warn, error
  sync_delay_after_expiry: 60 # seconds to wait after token expiry

github:
  organizations:
    - name: deepbrainspace
      secret_name: CLAUDE_CODE_TOKEN # Custom secret name (optional)
    - name: another-org
      secret_name: CLAUDE_ACCESS_TOKEN
    - name: simple-org # Uses default secret name

  repositories:
    - repo: user/special-repo
      secret_name: CUSTOM_CLAUDE_TOKEN
    - repo: owner/another-repo # Uses default secret name

notifications:
  session_warnings: [30, 15, 5] # Warning times (minutes before expiry)
  sync_failures: true # Notify on sync failures
```

**Configuration Notes**:

- If `secret_name` is omitted, defaults to `CLAUDE_CODE_TOKEN`
- Restart the daemon after editing YAML: `claude-code-toolkit service restart`
- Validate configuration: `claude-code-toolkit status`
- The CLI commands automatically update the YAML file

## Daemon Installation Details

The `claude-code-toolkit service install` command:

1. **Creates Systemd Service**: Installs
   `~/.config/systemd/user/claude-code-sync.service`
2. **References Current Binary**: Uses the exact path of the currently running
   binary (no copying)
3. **User Service**: Runs as a user service (no root privileges required)
4. **Auto-Start**: Enables automatic startup on user login
5. **Security Sandboxing**: Runs with restricted file system access

**Service Location**: `~/.config/systemd/user/claude-code-sync.service`
**Service Command**: `{binary_path} daemon` **Service Type**: User service
(systemctl --user)

### Manual Service Management

```bash
# View service status
systemctl --user status claude-code-sync

# Control service directly
systemctl --user start/stop/restart claude-code-sync

# View logs
journalctl --user -u claude-code-sync -f

# Remove service manually
systemctl --user stop claude-code-sync
systemctl --user disable claude-code-sync
rm ~/.config/systemd/user/claude-code-sync.service
systemctl --user daemon-reload
```

## How It Works

1. **Credential Monitoring**: Daemon monitors `~/.claude/.credentials.json` for
   changes
2. **Smart Timing**: When token expires, waits 60 seconds for Claude Code to
   refresh it
3. **Automatic Sync**: Detects new token and syncs to all configured GitHub
   targets
4. **Startup Recovery**: Performs reconciliation check on startup to catch
   missed syncs
5. **Status Tracking**: Maintains detailed sync status and error information per
   target

## Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Claude Code    │───▢│  claude-code     │───▢│  GitHub Secrets β”‚
β”‚  Credentials    β”‚    β”‚  Daemon          β”‚    β”‚  (Orgs & Repos) β”‚
β”‚  ~/.claude/     β”‚    β”‚  (Systemd)       β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚
                               β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚  Configuration   β”‚
                       β”‚  ~/.goodiebag/   β”‚
                       β”‚  claude-code/    β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

## Development

### Building

```bash
# Check code
cargo check

# Run tests
cargo test

# Build optimized binary
cargo build --release

# Run with NX
nx build claude-code-toolkit
nx test claude-code-toolkit
nx lint claude-code-toolkit
```

### Testing

The project includes comprehensive test coverage:

- **Unit Tests**: Core functionality testing
- **Integration Tests**: End-to-end workflow testing
- **Property Tests**: Edge case validation

```bash
# Run all tests
cargo test

# Run tests with coverage
cargo test --all-features

# Run specific test module
cargo test config::tests
```

### Code Quality

```bash
# Lint with clippy
cargo clippy -- -D warnings

# Format code
cargo fmt

# Check formatting
cargo fmt --check
```

## Troubleshooting

### Check Daemon Status

```bash
claude-code-toolkit status
systemctl --user status claude-code-sync
```

### View Detailed Logs

```bash
claude-code-toolkit sync logs --lines 100
journalctl --user -u claude-code-sync -f
```

### Manual Sync

```bash
claude-code-toolkit sync now
```

### Reset Configuration

```bash
claude-code-toolkit service uninstall
rm -rf ~/.goodiebag/claude-code
claude-code-toolkit service install
```

## Performance

- **Binary Size**: ~3.5MB (optimized)
- **Memory Usage**: ~5-10MB runtime
- **CPU Usage**: Near-zero when idle
- **Startup Time**: <100ms
- **Sync Time**: ~2-5 seconds per target

## Security

- **Credential Security**: Read-only access to local Claude credentials
- **GitHub Authentication**: Uses authenticated `gh` CLI for all operations
- **Audit Trail**: All operations logged with timestamps and outcomes
- **Systemd Sandboxing**: Runs with minimal file system permissions
- **No Network Storage**: All data stored locally in user directories

## Contributing

1. Fork the repository
2. Create a feature branch
3. Add tests for new functionality
4. Ensure all tests pass
5. Submit a pull request

## License

MIT License - see [LICENSE](LICENSE) for details.

## Support

- **Issues**:
  [GitHub Issues]https://github.com/deepbrainspace/goodiebag/issues
- **Documentation**: This README and inline code documentation
- **Community**: Discussions in the repository