Initial commit: AI conversation impact methodology and toolkit
CC0-licensed methodology for estimating the environmental and social costs of AI conversations (20+ categories), plus a reusable toolkit for automated impact tracking in Claude Code sessions.
This commit is contained in:
commit
0543a43816
27 changed files with 2439 additions and 0 deletions
83
impact-toolkit/install.sh
Executable file
83
impact-toolkit/install.sh
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# install.sh — Install the impact tracking toolkit for Claude Code.
|
||||
#
|
||||
# Copies hook scripts and configures the PreCompact hook in your
|
||||
# Claude Code settings. Safe to run multiple times (idempotent).
|
||||
#
|
||||
# Usage: ./install.sh [--user | --project]
|
||||
# --user Install to user-level settings (~/.claude/settings.json)
|
||||
# --project Install to project-level settings (.claude/settings.json)
|
||||
# Default: --project
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
SCOPE="${1:---project}"
|
||||
|
||||
# Check dependencies
|
||||
if ! command -v jq &>/dev/null; then
|
||||
echo "Error: jq is required but not installed."
|
||||
echo "Install it with: apt install jq / brew install jq / etc."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v python3 &>/dev/null; then
|
||||
echo "Error: python3 is required for token extraction."
|
||||
echo "Install Python 3 or ensure it is on your PATH."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Determine target directories
|
||||
if [ "$SCOPE" = "--user" ]; then
|
||||
SETTINGS_DIR="$HOME/.claude"
|
||||
HOOKS_DIR="$SETTINGS_DIR/hooks"
|
||||
echo "Installing to user-level settings ($SETTINGS_DIR)"
|
||||
else
|
||||
# Project-level: use current working directory
|
||||
SETTINGS_DIR="$(pwd)/.claude"
|
||||
HOOKS_DIR="$SETTINGS_DIR/hooks"
|
||||
echo "Installing to project-level settings ($SETTINGS_DIR)"
|
||||
fi
|
||||
|
||||
# Create directories
|
||||
mkdir -p "$HOOKS_DIR"
|
||||
mkdir -p "$SETTINGS_DIR/impact"
|
||||
|
||||
# Copy hook scripts
|
||||
cp "$SCRIPT_DIR/hooks/pre-compact-snapshot.sh" "$HOOKS_DIR/"
|
||||
cp "$SCRIPT_DIR/hooks/show-impact.sh" "$HOOKS_DIR/"
|
||||
chmod +x "$HOOKS_DIR/pre-compact-snapshot.sh"
|
||||
chmod +x "$HOOKS_DIR/show-impact.sh"
|
||||
|
||||
echo "Copied hook scripts to $HOOKS_DIR"
|
||||
|
||||
# Configure settings.json
|
||||
SETTINGS_FILE="$SETTINGS_DIR/settings.json"
|
||||
HOOK_CMD="$HOOKS_DIR/pre-compact-snapshot.sh"
|
||||
|
||||
if [ -f "$SETTINGS_FILE" ]; then
|
||||
# Check if PreCompact hook already configured
|
||||
if jq -e '.hooks.PreCompact' "$SETTINGS_FILE" &>/dev/null; then
|
||||
echo "PreCompact hook already configured in $SETTINGS_FILE — skipping."
|
||||
else
|
||||
# Add hooks to existing settings
|
||||
jq --arg cmd "$HOOK_CMD" \
|
||||
'.hooks.PreCompact = [{"hooks": [{"type": "command", "command": $cmd}]}]' \
|
||||
"$SETTINGS_FILE" > "${SETTINGS_FILE}.tmp" && mv "${SETTINGS_FILE}.tmp" "$SETTINGS_FILE"
|
||||
echo "Added PreCompact hook to $SETTINGS_FILE"
|
||||
fi
|
||||
else
|
||||
# Create new settings file
|
||||
jq -n --arg cmd "$HOOK_CMD" \
|
||||
'{"hooks": {"PreCompact": [{"hooks": [{"type": "command", "command": $cmd}]}]}}' \
|
||||
> "$SETTINGS_FILE"
|
||||
echo "Created $SETTINGS_FILE with PreCompact hook"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Installation complete."
|
||||
echo "Impact metrics will be logged to $SETTINGS_DIR/impact/impact-log.jsonl"
|
||||
echo "on each context compaction."
|
||||
echo ""
|
||||
echo "To view accumulated impact: $HOOKS_DIR/show-impact.sh"
|
||||
Loading…
Add table
Add a link
Reference in a new issue