spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic ยท github.com/anthropics

claude-code / plugins / plugin-dev / skills / hook-development / examples / load-context.sh
55 lines ยท 1.7 KBRaw
1#!/bin/bash
2# Example SessionStart hook for loading project context
3# This script detects project type and sets environment variables
4
5set -euo pipefail
6
7# Navigate to project directory
8cd "$CLAUDE_PROJECT_DIR" || exit 1
9
10echo "Loading project context..."
11
12# Detect project type and set environment
13if [ -f "package.json" ]; then
14 echo "๐Ÿ“ฆ Node.js project detected"
15 echo "export PROJECT_TYPE=nodejs" >> "$CLAUDE_ENV_FILE"
16
17 # Check if TypeScript
18 if [ -f "tsconfig.json" ]; then
19 echo "export USES_TYPESCRIPT=true" >> "$CLAUDE_ENV_FILE"
20 fi
21
22elif [ -f "Cargo.toml" ]; then
23 echo "๐Ÿฆ€ Rust project detected"
24 echo "export PROJECT_TYPE=rust" >> "$CLAUDE_ENV_FILE"
25
26elif [ -f "go.mod" ]; then
27 echo "๐Ÿน Go project detected"
28 echo "export PROJECT_TYPE=go" >> "$CLAUDE_ENV_FILE"
29
30elif [ -f "pyproject.toml" ] || [ -f "setup.py" ]; then
31 echo "๐Ÿ Python project detected"
32 echo "export PROJECT_TYPE=python" >> "$CLAUDE_ENV_FILE"
33
34elif [ -f "pom.xml" ]; then
35 echo "โ˜• Java (Maven) project detected"
36 echo "export PROJECT_TYPE=java" >> "$CLAUDE_ENV_FILE"
37 echo "export BUILD_SYSTEM=maven" >> "$CLAUDE_ENV_FILE"
38
39elif [ -f "build.gradle" ] || [ -f "build.gradle.kts" ]; then
40 echo "โ˜• Java/Kotlin (Gradle) project detected"
41 echo "export PROJECT_TYPE=java" >> "$CLAUDE_ENV_FILE"
42 echo "export BUILD_SYSTEM=gradle" >> "$CLAUDE_ENV_FILE"
43
44else
45 echo "โ“ Unknown project type"
46 echo "export PROJECT_TYPE=unknown" >> "$CLAUDE_ENV_FILE"
47fi
48
49# Check for CI configuration
50if [ -f ".github/workflows" ] || [ -f ".gitlab-ci.yml" ] || [ -f ".circleci/config.yml" ]; then
51 echo "export HAS_CI=true" >> "$CLAUDE_ENV_FILE"
52fi
53
54echo "Project context loaded successfully"
55exit 0