Use this guide to configure a Claude Code SessionStart hook and review staged or branch changes with the CodeGraph CLI. When the hook recognizes the current repository, it shows the project and code property graph (CPG) status at startup.
This setup is for the CodeGraph source repository. The packaged CodeGraph plugin for Codex and the OpenCode integration have separate setup guides.
What appears at startup
The hook identifies a project from the session’s working directory. For a recognized project, the startup context shows its name, language, domain, and CPG availability. When the configured CPG is available, the context can also show method and file counts and notes about the parsed scope.
Configure the startup hook
Set the command path to your local CodeGraph repository. This example registers only SessionStart:
{
"hooks": {
"SessionStart": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "python \"<absolute-repository-path>/.claude/hooks/session_context.py\"",
"timeout": 10
}
]
}
]
}
}
Replace <absolute-repository-path> with the full path to your local repository. On Windows, use forward slashes or escape backslashes in the JSON string. Save the object in .claude/settings.json. If that file already contains hooks, add the SessionStart entry and keep the existing settings. Make sure python starts the CodeGraph project environment.
The matcher value is a string. Claude Code interprets hook timeout values in seconds, so 10 means ten seconds. See the Claude Code hooks reference for the settings schema and event inputs.
Check the JSON and start a new Claude Code session from the repository:
python -m json.tool .claude/settings.json
In the new session, check the startup context for the selected project and CPG status.
Review changed files with CodeGraph CLI
Run the commands in PowerShell from the CodeGraph source repository root with the project Python environment. Replace <cpg.duckdb> with the path to the CPG for the project under review. Keep the quotation marks when the path contains spaces.
Before reviewing new changes, update the graph using the project import guide. Then review staged changes:
python -m src.cli review --db "<cpg.duckdb>" --staged --format json
To compare the current branch with a base branch, run:
python -m src.cli review --db "<cpg.duckdb>" --base-ref origin/main --format json
Use the Code review guide to interpret the report and choose the right review scope.
Remove the project registration
Remove the SessionStart entry from .claude/settings.json in your local CodeGraph repository. Remove other event entries only if you added them for this integration. Keep settings for other tools separate.