mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-13 16:14:31 +00:00
fix(hooks): enable image-read blocking by default for third-party profiles
Match WebSearch hook pattern: - ENABLED by default for settings/cliproxy profiles - DISABLED for native Claude accounts (account/default) - User can override via config: hooks.block_image_read.enabled: false This ensures CCS CLI users get context protection out-of-the-box while native Claude subscription users are unaffected.
This commit is contained in:
1 parent
38eb74043c
commit
9f3edc5daf
2 files changed
+47
-17
No files matched your search
@@ -7,6 +7,11 @@
|
||||
*
|
||||
* This is a PreToolUse hook that runs BEFORE the tool is executed.
|
||||
*
|
||||
* Behavior (matches WebSearch pattern):
|
||||
* - ENABLED by default for third-party profiles (settings, cliproxy)
|
||||
* - DISABLED for native Claude accounts (account, default profiles)
|
||||
* - User can override via config: hooks.block_image_read.enabled: false
|
||||
*
|
||||
* Usage:
|
||||
* Configured in ~/.claude/settings.json:
|
||||
* {
|
||||
@@ -22,10 +27,11 @@
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Environment Variables:
|
||||
* CCS_BLOCK_IMAGE_READ=1 - Enable blocking (required)
|
||||
* CCS_BLOCK_IMAGE_READ=0 - Disable blocking (allow all reads)
|
||||
* CCS_DEBUG=1 - Enable debug output
|
||||
* Environment Variables (set by CCS):
|
||||
* CCS_BLOCK_IMAGE_READ=1 - Enable blocking (default for third-party)
|
||||
* CCS_BLOCK_IMAGE_READ=0 - Disable blocking
|
||||
* CCS_PROFILE_TYPE - Profile type (account, default, settings, cliproxy)
|
||||
* CCS_DEBUG=1 - Enable debug output
|
||||
*
|
||||
* Exit codes:
|
||||
* 0 - Allow tool (pass-through)
|
||||
@@ -53,11 +59,28 @@ process.stdin.on('error', () => {
|
||||
});
|
||||
|
||||
/**
|
||||
* Check if blocking is enabled via environment variable
|
||||
* Check if hook should skip (for native Claude accounts).
|
||||
* Matches WebSearch hook pattern.
|
||||
*/
|
||||
function isBlockingEnabled() {
|
||||
// Must be explicitly enabled
|
||||
return process.env.CCS_BLOCK_IMAGE_READ === '1';
|
||||
function shouldSkipHook() {
|
||||
// Account/default profiles use native Claude - don't block
|
||||
const profileType = process.env.CCS_PROFILE_TYPE;
|
||||
if (profileType === 'account' || profileType === 'default') {
|
||||
if (process.env.CCS_DEBUG) {
|
||||
console.error(`[CCS Hook] Skipping image block for profile type: ${profileType}`);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Explicit disable via config
|
||||
if (process.env.CCS_BLOCK_IMAGE_READ === '0') {
|
||||
if (process.env.CCS_DEBUG) {
|
||||
console.error('[CCS Hook] Image read blocking disabled by config');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,11 +88,8 @@ function isBlockingEnabled() {
|
||||
*/
|
||||
function processHook() {
|
||||
try {
|
||||
// Skip if blocking not enabled
|
||||
if (!isBlockingEnabled()) {
|
||||
if (process.env.CCS_DEBUG) {
|
||||
console.error('[CCS Hook] Image read blocking disabled (CCS_BLOCK_IMAGE_READ != 1)');
|
||||
}
|
||||
// Skip for native accounts or explicit disable
|
||||
if (shouldSkipHook()) {
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user