instar 0.8.11 → 0.8.13

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 (129) hide show
  1. package/dist/cli.d.ts.map +1 -0
  2. package/dist/cli.js +68 -0
  3. package/dist/cli.js.map +1 -0
  4. package/dist/commands/init.d.ts.map +1 -0
  5. package/dist/commands/init.js.map +1 -0
  6. package/dist/commands/job.d.ts.map +1 -0
  7. package/dist/commands/job.js.map +1 -0
  8. package/dist/commands/relationship.d.ts.map +1 -0
  9. package/dist/commands/relationship.js.map +1 -0
  10. package/dist/commands/server.d.ts.map +1 -0
  11. package/dist/commands/server.js.map +1 -0
  12. package/dist/commands/setup.d.ts.map +1 -0
  13. package/dist/commands/setup.js.map +1 -0
  14. package/dist/commands/status.d.ts.map +1 -0
  15. package/dist/commands/status.js.map +1 -0
  16. package/dist/commands/user.d.ts.map +1 -0
  17. package/dist/commands/user.js.map +1 -0
  18. package/dist/core/AnthropicIntelligenceProvider.d.ts.map +1 -0
  19. package/dist/core/AnthropicIntelligenceProvider.js.map +1 -0
  20. package/dist/core/AutoDispatcher.d.ts.map +1 -0
  21. package/dist/core/AutoDispatcher.js.map +1 -0
  22. package/dist/core/AutoUpdater.d.ts.map +1 -0
  23. package/dist/core/AutoUpdater.js.map +1 -0
  24. package/dist/core/CaffeinateManager.d.ts.map +1 -0
  25. package/dist/core/CaffeinateManager.js.map +1 -0
  26. package/dist/core/ClaudeCliIntelligenceProvider.d.ts.map +1 -0
  27. package/dist/core/ClaudeCliIntelligenceProvider.js.map +1 -0
  28. package/dist/core/Config.d.ts.map +1 -0
  29. package/dist/core/Config.js.map +1 -0
  30. package/dist/core/DispatchExecutor.d.ts.map +1 -0
  31. package/dist/core/DispatchExecutor.js.map +1 -0
  32. package/dist/core/DispatchManager.d.ts.map +1 -0
  33. package/dist/core/DispatchManager.js.map +1 -0
  34. package/dist/core/EvolutionManager.d.ts.map +1 -0
  35. package/dist/core/EvolutionManager.js.map +1 -0
  36. package/dist/core/FeedbackManager.d.ts.map +1 -0
  37. package/dist/core/FeedbackManager.js.map +1 -0
  38. package/dist/core/PortRegistry.d.ts.map +1 -0
  39. package/dist/core/PortRegistry.js.map +1 -0
  40. package/dist/core/PostUpdateMigrator.d.ts.map +1 -0
  41. package/dist/core/PostUpdateMigrator.js +15 -0
  42. package/dist/core/PostUpdateMigrator.js.map +1 -0
  43. package/dist/core/Prerequisites.d.ts.map +1 -0
  44. package/dist/core/Prerequisites.js.map +1 -0
  45. package/dist/core/RelationshipManager.d.ts.map +1 -0
  46. package/dist/core/RelationshipManager.js.map +1 -0
  47. package/dist/core/SessionManager.d.ts.map +1 -0
  48. package/dist/core/SessionManager.js.map +1 -0
  49. package/dist/core/SleepWakeDetector.d.ts.map +1 -0
  50. package/dist/core/SleepWakeDetector.js.map +1 -0
  51. package/dist/core/StateManager.d.ts.map +1 -0
  52. package/dist/core/StateManager.js.map +1 -0
  53. package/dist/core/UpdateChecker.d.ts.map +1 -0
  54. package/dist/core/UpdateChecker.js +28 -7
  55. package/dist/core/UpdateChecker.js.map +1 -0
  56. package/dist/core/UpgradeGuideProcessor.d.ts +101 -0
  57. package/dist/core/UpgradeGuideProcessor.d.ts.map +1 -0
  58. package/dist/core/UpgradeGuideProcessor.js +259 -0
  59. package/dist/core/UpgradeGuideProcessor.js.map +1 -0
  60. package/dist/core/types.d.ts.map +1 -0
  61. package/dist/core/types.js.map +1 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js.map +1 -0
  64. package/dist/lifeline/MessageQueue.d.ts.map +1 -0
  65. package/dist/lifeline/MessageQueue.js.map +1 -0
  66. package/dist/lifeline/ServerSupervisor.d.ts.map +1 -0
  67. package/dist/lifeline/ServerSupervisor.js.map +1 -0
  68. package/dist/lifeline/TelegramLifeline.d.ts.map +1 -0
  69. package/dist/lifeline/TelegramLifeline.js.map +1 -0
  70. package/dist/messaging/TelegramAdapter.d.ts.map +1 -0
  71. package/dist/messaging/TelegramAdapter.js.map +1 -0
  72. package/dist/monitoring/AccountSwitcher.d.ts.map +1 -0
  73. package/dist/monitoring/AccountSwitcher.js.map +1 -0
  74. package/dist/monitoring/HealthChecker.d.ts.map +1 -0
  75. package/dist/monitoring/HealthChecker.js.map +1 -0
  76. package/dist/monitoring/MemoryPressureMonitor.d.ts.map +1 -0
  77. package/dist/monitoring/MemoryPressureMonitor.js.map +1 -0
  78. package/dist/monitoring/QuotaExhaustionDetector.d.ts.map +1 -0
  79. package/dist/monitoring/QuotaExhaustionDetector.js.map +1 -0
  80. package/dist/monitoring/QuotaNotifier.d.ts.map +1 -0
  81. package/dist/monitoring/QuotaNotifier.js.map +1 -0
  82. package/dist/monitoring/QuotaTracker.d.ts.map +1 -0
  83. package/dist/monitoring/QuotaTracker.js.map +1 -0
  84. package/dist/monitoring/SessionWatchdog.d.ts.map +1 -0
  85. package/dist/monitoring/SessionWatchdog.js.map +1 -0
  86. package/dist/publishing/PrivateViewer.d.ts.map +1 -0
  87. package/dist/publishing/PrivateViewer.js.map +1 -0
  88. package/dist/publishing/TelegraphService.d.ts.map +1 -0
  89. package/dist/publishing/TelegraphService.js.map +1 -0
  90. package/dist/scaffold/bootstrap.d.ts.map +1 -0
  91. package/dist/scaffold/bootstrap.js.map +1 -0
  92. package/dist/scaffold/templates.d.ts.map +1 -0
  93. package/dist/scaffold/templates.js.map +1 -0
  94. package/dist/scheduler/JobLoader.d.ts.map +1 -0
  95. package/dist/scheduler/JobLoader.js.map +1 -0
  96. package/dist/scheduler/JobScheduler.d.ts.map +1 -0
  97. package/dist/scheduler/JobScheduler.js.map +1 -0
  98. package/dist/scheduler/SkipLedger.d.ts.map +1 -0
  99. package/dist/scheduler/SkipLedger.js.map +1 -0
  100. package/dist/server/AgentServer.d.ts.map +1 -0
  101. package/dist/server/AgentServer.js.map +1 -0
  102. package/dist/server/WebSocketManager.d.ts.map +1 -0
  103. package/dist/server/WebSocketManager.js.map +1 -0
  104. package/dist/server/middleware.d.ts.map +1 -0
  105. package/dist/server/middleware.js.map +1 -0
  106. package/dist/server/routes.d.ts.map +1 -0
  107. package/dist/server/routes.js.map +1 -0
  108. package/dist/tunnel/TunnelManager.d.ts.map +1 -0
  109. package/dist/tunnel/TunnelManager.js.map +1 -0
  110. package/dist/users/UserManager.d.ts.map +1 -0
  111. package/dist/users/UserManager.js.map +1 -0
  112. package/package.json +6 -1
  113. package/upgrades/0.8.12.md +41 -0
  114. package/upgrades/0.8.13.md +31 -0
  115. package/.claude/skills/setup-wizard/skill.md +0 -810
  116. package/.vercel/README.txt +0 -11
  117. package/.vercel/project.json +0 -1
  118. package/_demo.mjs +0 -78
  119. package/skills/README.md +0 -106
  120. package/skills/agent-identity/SKILL.md +0 -226
  121. package/skills/agent-memory/SKILL.md +0 -261
  122. package/skills/command-guard/SKILL.md +0 -239
  123. package/skills/credential-leak-detector/SKILL.md +0 -377
  124. package/skills/instar-feedback/SKILL.md +0 -285
  125. package/skills/instar-identity/SKILL.md +0 -290
  126. package/skills/instar-scheduler/SKILL.md +0 -259
  127. package/skills/instar-session/SKILL.md +0 -270
  128. package/skills/instar-telegram/SKILL.md +0 -259
  129. package/skills/smart-web-fetch/SKILL.md +0 -241
@@ -1,239 +0,0 @@
1
- ---
2
- name: command-guard
3
- description: Set up a PreToolUse hook in .claude/settings.json that blocks dangerous commands — rm -rf, force push, database drops, and others — before they execute. Teaches the pattern of safety hooks for any Claude Code project. Trigger words: safety, guard, block dangerous, protect, prevent destructive, safe mode, dangerous commands, risky operations.
4
- license: MIT
5
- metadata:
6
- author: sagemindai
7
- version: "1.0"
8
- homepage: https://instar.sh
9
- ---
10
-
11
- # command-guard — Block Dangerous Commands Before They Execute
12
-
13
- Claude Code runs shell commands, edits files, and manages infrastructure with real consequences. Without guardrails, a misunderstood instruction or a hallucinated flag can delete data, corrupt history, or expose credentials. This skill installs a PreToolUse hook that blocks the most dangerous operations before they run.
14
-
15
- No external tools required — this uses Claude Code's built-in hook system.
16
-
17
- ---
18
-
19
- ## What Gets Blocked
20
-
21
- The guard intercepts `Bash` tool calls and checks the command against a blocklist before execution. By default it blocks:
22
-
23
- **Irreversible deletions**
24
- - `rm -rf` on non-temporary paths
25
- - `git clean -f` (untracked file deletion)
26
-
27
- **Git history destruction**
28
- - `git push --force` / `git push -f` (without explicit user confirmation)
29
- - `git reset --hard` on shared branches
30
- - `git rebase` on pushed branches
31
-
32
- **Database operations**
33
- - `DROP TABLE`, `DROP DATABASE`, `TRUNCATE` in SQL
34
- - `db:reset`, `db:drop` npm/prisma scripts
35
-
36
- **Credential exposure**
37
- - Commands that `cat`, `echo`, or `curl` files containing `SECRET`, `KEY`, `TOKEN`, `PASSWORD` to stdout
38
-
39
- ---
40
-
41
- ## Installation
42
-
43
- ### Step 1: Create the hook script
44
-
45
- ```bash
46
- mkdir -p .claude/hooks
47
- ```
48
-
49
- Create `.claude/hooks/command-guard.py`:
50
-
51
- ```python
52
- #!/usr/bin/env python3
53
- """
54
- command-guard.py — PreToolUse hook that blocks dangerous Bash commands.
55
- Claude Code calls this before executing any Bash tool call.
56
- Exit code 2 = block the command and show the message.
57
- Exit code 0 = allow the command.
58
- """
59
- import sys
60
- import json
61
- import re
62
- import os
63
-
64
- # Load the tool call input from stdin
65
- try:
66
- payload = json.load(sys.stdin)
67
- except Exception:
68
- sys.exit(0) # Can't parse — allow (fail open)
69
-
70
- tool_name = payload.get('tool_name', '')
71
- tool_input = payload.get('tool_input', {})
72
-
73
- # Only intercept Bash calls
74
- if tool_name != 'Bash':
75
- sys.exit(0)
76
-
77
- command = tool_input.get('command', '')
78
-
79
- # --- Blocklist rules ---
80
- # Each rule: (regex pattern, reason shown to agent)
81
-
82
- BLOCKED = [
83
- # Irreversible deletions
84
- (r'\brm\s+-[a-zA-Z]*r[a-zA-Z]*f\b', 'rm -rf is blocked. Use rm with explicit paths, or move to trash instead.'),
85
- (r'\bgit\s+clean\s+-[a-zA-Z]*f\b', 'git clean -f is blocked. List untracked files with --dry-run first.'),
86
-
87
- # Force push
88
- (r'\bgit\s+push\s+.*--force\b', 'Force push is blocked. Confirm with the user before rewriting remote history.'),
89
- (r'\bgit\s+push\s+.*-f\b(?!ile)', 'Force push (-f) is blocked. Confirm with the user before rewriting remote history.'),
90
-
91
- # Hard reset
92
- (r'\bgit\s+reset\s+--hard\b', 'git reset --hard is blocked. Use --soft or --mixed, or confirm with user first.'),
93
-
94
- # Database destructive ops
95
- (r'\b(DROP\s+(TABLE|DATABASE|SCHEMA)|TRUNCATE\s+TABLE)\b', 'Destructive SQL (DROP/TRUNCATE) is blocked. Confirm with the user before destroying data.', re.IGNORECASE),
96
- (r'\b(db:reset|db:drop|prisma.*reset)\b', 'Database reset scripts are blocked. Confirm with the user — this destroys all data.'),
97
-
98
- # Credential leakage to stdout (basic check)
99
- (r'\b(cat|echo|curl|printf)\b.*\.(env|secret|secrets|pem|key)\b', 'Printing credential files to stdout is blocked. Use secure variable injection instead.'),
100
- ]
101
-
102
- for rule in BLOCKED:
103
- pattern = rule[0]
104
- message = rule[1]
105
- flags = rule[2] if len(rule) > 2 else 0
106
- if re.search(pattern, command, flags):
107
- print(json.dumps({
108
- "decision": "block",
109
- "reason": f"[command-guard] {message}\n\nBlocked command: {command[:200]}"
110
- }))
111
- sys.exit(2)
112
-
113
- # All clear
114
- sys.exit(0)
115
- ```
116
-
117
- Make it executable:
118
-
119
- ```bash
120
- chmod +x .claude/hooks/command-guard.py
121
- ```
122
-
123
- ---
124
-
125
- ### Step 2: Register the hook in .claude/settings.json
126
-
127
- If `.claude/settings.json` doesn't exist, create it. If it does, add to the `hooks` array:
128
-
129
- ```json
130
- {
131
- "hooks": {
132
- "PreToolUse": [
133
- {
134
- "matcher": "Bash",
135
- "hooks": [
136
- {
137
- "type": "command",
138
- "command": "python3 .claude/hooks/command-guard.py"
139
- }
140
- ]
141
- }
142
- ]
143
- }
144
- }
145
- ```
146
-
147
- ---
148
-
149
- ### Step 3: Verify the hook is registered
150
-
151
- Restart Claude Code, then ask it to run a blocked command:
152
-
153
- ```
154
- Run: rm -rf ./test-dir
155
- ```
156
-
157
- The agent should receive a block message rather than executing the command.
158
-
159
- ---
160
-
161
- ## Customizing the Blocklist
162
-
163
- Edit the `BLOCKED` list in `command-guard.py` to add project-specific rules.
164
-
165
- **Example: Block deploys to production from feature branches**
166
-
167
- ```python
168
- (r'\bdeploy.*production\b', 'Direct production deploys are blocked. Merge to main first, then deploy via CI.'),
169
- ```
170
-
171
- **Example: Block overwriting specific config files**
172
-
173
- ```python
174
- (r'\bcp\b.*\b(\.env\.production|secrets\.json)\b', 'Overwriting production config files is blocked. Edit manually.'),
175
- ```
176
-
177
- **Example: Allow force push only to personal branches**
178
-
179
- Replace the force push rule with a more nuanced check:
180
-
181
- ```python
182
- # Allow force push to personal/feature branches, block on main/master/staging
183
- if re.search(r'\bgit\s+push\s+.*(-f|--force)\b', command):
184
- if not re.search(r'\b(main|master|staging|production)\b', command):
185
- sys.exit(0) # Allow: not targeting a protected branch
186
- print(json.dumps({"decision": "block", "reason": "Force push to protected branches is blocked."}))
187
- sys.exit(2)
188
- ```
189
-
190
- ---
191
-
192
- ## Understanding the Hook Pattern
193
-
194
- Claude Code hooks are scripts that fire at specific points in the agent's tool lifecycle:
195
-
196
- | Hook Type | When It Fires | Use Cases |
197
- |-----------|--------------|-----------|
198
- | `PreToolUse` | Before any tool call | Block dangerous operations, inject context |
199
- | `PostToolUse` | After any tool call | Log actions, update state, send notifications |
200
- | `Notification` | On system events (compaction, etc.) | Recovery, awareness updates |
201
-
202
- The hook receives a JSON payload on stdin and communicates back via stdout + exit code:
203
- - **Exit 0**: Allow the tool call to proceed
204
- - **Exit 2**: Block the tool call; the `reason` in stdout is shown to the agent
205
-
206
- Hooks are composable. You can chain multiple hooks for the same event, and each runs independently.
207
-
208
- ---
209
-
210
- ## What This Does Not Cover
211
-
212
- This guard blocks the most common dangerous operations. It does not:
213
- - Inspect file contents before writes (use a `Write` tool hook for that)
214
- - Validate SQL in ORM calls (only raw SQL strings)
215
- - Prevent API calls that delete remote resources
216
-
217
- For production systems where the agent has access to critical infrastructure, layer additional guards specific to your environment.
218
-
219
- ---
220
-
221
- ## Going Further
222
-
223
- This guard works when you're watching. But what about when you're not? If your agent runs a scheduled job at 2 AM and hits a destructive edge case, a command-guard hook still blocks it — but nobody sees the block message until morning. And command blocking is just one layer of safety.
224
-
225
- **Instar adds the safety infrastructure that autonomous agents need.** Identity grounding hooks fire before the agent sends any external message — so it can't accidentally email or post something off-character. Every tool call across every session gets audit-logged for post-hoc review. And the command guard is installed automatically as part of setup, along with all the other hooks.
226
-
227
- Safety is important, but it's just the foundation. With Instar, your agent also gets:
228
- - **A job scheduler** — recurring tasks on cron, running while you sleep
229
- - **Background sessions** — spawn parallel workers for deep tasks
230
- - **Telegram integration** — two-way messaging from your phone
231
- - **Persistent identity and memory** — context that survives across sessions
232
-
233
- One command, about 2 minutes:
234
-
235
- ```bash
236
- npx instar
237
- ```
238
-
239
- Your agent goes from guarded-when-you're-watching to safe-when-you're-not. [instar.sh](https://instar.sh)
@@ -1,377 +0,0 @@
1
- ---
2
- name: credential-leak-detector
3
- description: PostToolUse hook that scans Bash tool output for leaked credentials — API keys, tokens, private keys, and secrets — before they reach the conversation. Blocks critical leaks, redacts high-severity matches, and warns on suspicious patterns. 14 detection patterns covering OpenAI, Anthropic, AWS, GitHub, Stripe, Google, Slack, SendGrid, Twilio, PEM keys, bearer tokens, and generic secrets. No external dependencies. Trigger words: security, credential leak, secret exposure, key detection, token scan, API key leaked, credential guard, secret scanner, prevent credential leak.
4
- license: MIT
5
- metadata:
6
- author: sagemindai
7
- version: "1.0"
8
- homepage: https://instar.sh
9
- ---
10
-
11
- # credential-leak-detector — Catch Leaked Credentials Before They Spread
12
-
13
- Every time your agent runs a Bash command, the output flows back into the conversation — and into your API provider's logs, any monitoring tools, and the model's context window. If that output contains an API key, a private key, or a database password, the credential is now exposed in places you never intended.
14
-
15
- This hook scans every Bash tool response for 14 credential patterns before the output reaches the agent. Critical matches (API keys, AWS credentials, private keys) get blocked entirely. High-severity matches get redacted with a warning. Suspicious patterns get flagged as advisories. No external dependencies — just Python stdlib.
16
-
17
- ---
18
-
19
- ## What Gets Detected
20
-
21
- ### Critical (Blocks the response)
22
-
23
- | Pattern | Example Match |
24
- |---------|--------------|
25
- | OpenAI API keys | `sk-proj-abc123...` |
26
- | Anthropic API keys | `sk-ant-api03-...` |
27
- | AWS access keys | `AKIA1234567890ABCDEF` |
28
- | GitHub tokens (classic) | `ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` |
29
- | GitHub fine-grained PATs | `github_pat_xxxxxx...` |
30
- | Stripe secret keys | `sk_live_xxxx...xxxx` |
31
- | PEM private keys | `-----BEGIN RSA PRIVATE KEY-----` |
32
-
33
- ### High (Blocks or redacts with warning)
34
-
35
- | Pattern | Action |
36
- |---------|--------|
37
- | Google API keys | Block |
38
- | Slack tokens | Block |
39
- | SendGrid API keys | Block |
40
- | Twilio auth keys | Redact + warn |
41
- | Bearer auth tokens | Redact + warn |
42
-
43
- ### Medium (Advisory warning)
44
-
45
- | Pattern | Note |
46
- |---------|------|
47
- | Generic `password=`, `secret=`, `api_key=` assignments | Common in config output |
48
- | 64-character hex strings | Possible SHA-256 hashes or keys |
49
-
50
- ---
51
-
52
- ## Installation
53
-
54
- ### Step 1: Create the hook script
55
-
56
- ```bash
57
- mkdir -p .claude/hooks
58
- ```
59
-
60
- Create `.claude/hooks/credential-leak-detector.py` with the contents below.
61
-
62
- ---
63
-
64
- ## The Script
65
-
66
- Save this as `.claude/hooks/credential-leak-detector.py`:
67
-
68
- ```python
69
- #!/usr/bin/env python3
70
- """
71
- credential-leak-detector.py — PostToolUse hook that scans Bash output
72
- for leaked credentials. Blocks critical leaks, redacts high-severity
73
- matches, warns on suspicious patterns.
74
-
75
- Exit code 2 = block (critical credential found)
76
- Exit code 0 = allow (clean or advisory-only)
77
- """
78
- import sys
79
- import json
80
- import re
81
-
82
- # --- Masking ---
83
-
84
- def mask(value):
85
- """Mask a credential: first 4 + **** + last 4, or full mask if short."""
86
- v = value.strip()
87
- if len(v) < 12:
88
- return "*" * len(v)
89
- return v[:4] + "****" + v[-4:]
90
-
91
-
92
- # --- Pattern Definitions ---
93
- # (name, regex, severity, action)
94
- # severity: critical, high, medium
95
- # action: block, redact, warn
96
-
97
- PATTERNS = [
98
- # Critical — Block
99
- ("OpenAI API key",
100
- r'(sk-(?:proj-)?[a-zA-Z0-9]{20,})',
101
- "critical", "block"),
102
-
103
- ("Anthropic API key",
104
- r'(sk-ant-api[a-zA-Z0-9_-]{90,})',
105
- "critical", "block"),
106
-
107
- ("AWS access key",
108
- r'(AKIA[0-9A-Z]{16})',
109
- "critical", "block"),
110
-
111
- ("GitHub token (classic)",
112
- r'(gh[pousr]_[A-Za-z0-9_]{36,})',
113
- "critical", "block"),
114
-
115
- ("GitHub fine-grained PAT",
116
- r'(github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59})',
117
- "critical", "block"),
118
-
119
- ("Stripe secret key",
120
- r'(sk_(?:live|test)_[a-zA-Z0-9]{24,})',
121
- "critical", "block"),
122
-
123
- ("PEM private key",
124
- r'(-----BEGIN (?:RSA |EC |DSA )?PRIVATE KEY-----)',
125
- "critical", "block"),
126
-
127
- # High — Block
128
- ("Google API key",
129
- r'(AIza[0-9A-Za-z_-]{35})',
130
- "high", "block"),
131
-
132
- ("Slack token",
133
- r'(xox[bpors]-[0-9a-zA-Z-]{10,})',
134
- "high", "block"),
135
-
136
- ("SendGrid API key",
137
- r'(SG\.[a-zA-Z0-9_-]{22}\.[a-zA-Z0-9_-]{43})',
138
- "high", "block"),
139
-
140
- # High — Redact
141
- ("Twilio auth key",
142
- r'(SK[0-9a-fA-F]{32})',
143
- "high", "redact"),
144
-
145
- ("Bearer auth token",
146
- r'(?:Authorization|Bearer)\s*[:=]\s*Bearer\s+([^\s]{20,})',
147
- "high", "redact"),
148
-
149
- # Medium — Warn
150
- ("Generic secret assignment",
151
- r'(?:password|secret|token|api_key)\s*[=:]\s*[\'"]?([^\s\'"]{16,})',
152
- "medium", "warn"),
153
-
154
- ("High-entropy hex string",
155
- r'\b([a-fA-F0-9]{64})\b',
156
- "medium", "warn"),
157
- ]
158
-
159
-
160
- # --- Main ---
161
-
162
- def scan(text):
163
- """Scan text for credential patterns. Returns list of findings."""
164
- findings = []
165
- for name, pattern, severity, action in PATTERNS:
166
- matches = re.findall(pattern, text)
167
- for m in matches:
168
- findings.append({
169
- "name": name,
170
- "severity": severity,
171
- "action": action,
172
- "matched": m if isinstance(m, str) else m[0],
173
- })
174
- return findings
175
-
176
-
177
- def main():
178
- try:
179
- payload = json.load(sys.stdin)
180
- except Exception:
181
- sys.exit(0)
182
-
183
- tool_name = payload.get("tool_name", "")
184
- tool_response = payload.get("tool_response", "")
185
-
186
- # Only scan Bash output
187
- if tool_name != "Bash":
188
- sys.exit(0)
189
-
190
- if not tool_response:
191
- sys.exit(0)
192
-
193
- # Handle tool_response as string or dict
194
- if isinstance(tool_response, dict):
195
- text = tool_response.get("stdout", "") + tool_response.get("stderr", "")
196
- else:
197
- text = str(tool_response)
198
-
199
- if not text:
200
- sys.exit(0)
201
-
202
- findings = scan(text)
203
-
204
- if not findings:
205
- sys.exit(0)
206
-
207
- # Classify findings
208
- blockers = [f for f in findings if f["action"] == "block"]
209
- redacts = [f for f in findings if f["action"] == "redact"]
210
- warnings = [f for f in findings if f["action"] == "warn"]
211
-
212
- # Critical/high blockers — stop the response
213
- if blockers:
214
- details = []
215
- for f in blockers:
216
- details.append(
217
- f" - {f['name']} [{f['severity']}]: {mask(f['matched'])}"
218
- )
219
- reason = (
220
- "[credential-leak-detector] Credential(s) detected in command output. "
221
- "Response blocked to prevent exposure.\n\n"
222
- "Detected:\n" + "\n".join(details) + "\n\n"
223
- "The command output contained live credentials. Do NOT re-run this "
224
- "command or attempt to extract these values. If you need to verify "
225
- "a credential exists, check the env var or file without printing "
226
- "its value."
227
- )
228
- print(json.dumps({"decision": "block", "reason": reason}))
229
- sys.exit(2)
230
-
231
- # Redact findings — allow but warn with masked values
232
- messages = []
233
- if redacts:
234
- parts = []
235
- for f in redacts:
236
- parts.append(f" - {f['name']}: {mask(f['matched'])}")
237
- messages.append(
238
- "[credential-leak-detector] Possible credential(s) in output "
239
- "(redact-level):\n" + "\n".join(parts) + "\n"
240
- "Avoid storing, logging, or repeating these values."
241
- )
242
-
243
- # Warn findings — advisory only
244
- if warnings:
245
- parts = []
246
- for f in warnings:
247
- parts.append(f" - {f['name']}: {mask(f['matched'])}")
248
- messages.append(
249
- "[credential-leak-detector] Suspicious pattern(s) in output "
250
- "(advisory):\n" + "\n".join(parts) + "\n"
251
- "These may be secrets. Avoid including them in commits, logs, "
252
- "or messages."
253
- )
254
-
255
- if messages:
256
- print(json.dumps({"additionalContext": "\n".join(messages)}))
257
-
258
- sys.exit(0)
259
-
260
-
261
- if __name__ == "__main__":
262
- main()
263
- ```
264
-
265
- Make it executable:
266
-
267
- ```bash
268
- chmod +x .claude/hooks/credential-leak-detector.py
269
- ```
270
-
271
- ---
272
-
273
- ### Step 2: Register the hook in .claude/settings.json
274
-
275
- If `.claude/settings.json` doesn't exist, create it. If it does, add to the `hooks` section:
276
-
277
- ```json
278
- {
279
- "hooks": {
280
- "PostToolUse": [
281
- {
282
- "matcher": "Bash",
283
- "hooks": [
284
- {
285
- "type": "command",
286
- "command": "python3 .claude/hooks/credential-leak-detector.py"
287
- }
288
- ]
289
- }
290
- ]
291
- }
292
- }
293
- ```
294
-
295
- If you already have a `PostToolUse` array, add the matcher object to it.
296
-
297
- ---
298
-
299
- ### Step 3: Verify it works
300
-
301
- Restart Claude Code, then run a command that would expose a credential:
302
-
303
- ```bash
304
- echo "sk-ant-api03-test1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrst"
305
- ```
306
-
307
- The hook should block the response and show a masked version of the detected key.
308
-
309
- ---
310
-
311
- ## Customizing Patterns
312
-
313
- Edit the `PATTERNS` list in `credential-leak-detector.py` to add project-specific rules.
314
-
315
- **Example: Detect your internal API keys**
316
-
317
- ```python
318
- ("Internal service key",
319
- r'(myco_sk_[a-zA-Z0-9]{32,})',
320
- "critical", "block"),
321
- ```
322
-
323
- **Example: Detect database connection strings**
324
-
325
- ```python
326
- ("Database connection string",
327
- r'((?:postgres|mysql|mongodb)://[^\s]{20,})',
328
- "high", "block"),
329
- ```
330
-
331
- **Example: Downgrade a pattern to warn-only**
332
-
333
- Change the action from `"block"` to `"warn"` for patterns that produce too many false positives in your environment:
334
-
335
- ```python
336
- # Change high-entropy hex from warn to ignored by removing it,
337
- # or keep it but change action:
338
- ("High-entropy hex string",
339
- r'\b([a-fA-F0-9]{64})\b',
340
- "medium", "warn"), # or remove this entry entirely
341
- ```
342
-
343
- ---
344
-
345
- ## How It Differs from command-guard
346
-
347
- The **command-guard** skill is a PreToolUse hook — it blocks dangerous *commands* before they execute. This skill is a PostToolUse hook — it scans *output* after commands run. They complement each other:
348
-
349
- | Layer | Hook | What It Catches |
350
- |-------|------|----------------|
351
- | command-guard | PreToolUse | `cat .env`, `echo $SECRET`, destructive commands |
352
- | credential-leak-detector | PostToolUse | Credentials that appear in output from any command |
353
-
354
- A command like `docker inspect` or `kubectl describe` might not look dangerous, but its output can contain mounted secrets. command-guard wouldn't catch it. This hook does.
355
-
356
- ---
357
-
358
- ## Going Further
359
-
360
- This hook catches credentials after they appear in output. But in an autonomous session — a scheduled job running at 3 AM, a background worker processing a queue — "catching" means the block fires, the agent sees the message, and... then what? If nobody's watching, the agent might retry the command, work around the block, or simply stall.
361
-
362
- **Instar turns detection into infrastructure.** Every hook event across every session gets audit-logged with timestamps, session IDs, and the masked credential type. If a credential-leak-detector block fires during a 2 AM job, it shows up in the morning's activity feed — you see exactly which command triggered it, in which session, and what the agent did next. The Telegram integration means you can get notified the moment a block fires, not hours later.
363
-
364
- And credential scanning is just one layer. With Instar, your agent also gets:
365
- - **Audit logging** — every tool call, every hook event, searchable and timestamped
366
- - **Identity grounding** — hooks that fire before external messages, so the agent stays in character
367
- - **A job scheduler** — recurring tasks on cron, running while you sleep
368
- - **Background sessions** — parallel workers for deep tasks
369
- - **Telegram integration** — real-time notifications and two-way control from your phone
370
-
371
- One command, about 2 minutes:
372
-
373
- ```bash
374
- npx instar
375
- ```
376
-
377
- Your agent goes from guarded-when-you're-watching to safe-autonomously. [instar.sh](https://instar.sh)