Skip to content

koriyoshi2041/cc-learning-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CC Learning Hooks

Automatically generate beginner-friendly learning notes from your Claude Code sessions.

Every time you use Claude Code, this tool silently logs every operation (file edits, searches, commands, etc.). When the session ends, it uses Claude to analyze the log and produce educational notes explaining what happened, why, and what concepts were involved.

How it works

┌─────────────────────────────────────────────────────┐
│  Claude Code Session                                │
│                                                     │
│  You: "fix the auth bug"                            │
│  CC: reads files, edits code, runs tests...         │
│                                                     │
│  ┌──────────────────────────────┐                   │
│  │ PostToolUse Hook (silent)    │                   │
│  │ Logs every action to         │                   │
│  │ /tmp/cc-learning/session.md  │                   │
│  └──────────────────────────────┘                   │
│                                                     │
│  Session ends ──►  Stop Hook fires                  │
│                    │                                │
│                    ▼                                │
│              claude -p (haiku)                       │
│              analyzes the log                        │
│                    │                                │
│                    ▼                                │
│       ~/Desktop/CC-Learning-Notes/                  │
│       2025-03-15_1430_session_a1b2c3d4.md          │
└─────────────────────────────────────────────────────┘

Example output

# Learning Notes

## What happened in this session?
The user asked Claude Code to fix a failing test in a Node.js project.
Claude read the test file, identified an off-by-one error in a loop,
fixed it, and re-ran the tests to confirm they pass.

## Key Operations Breakdown

### Reading and understanding the code (Steps 1-3)
- **What**: Read the test file and the source file it tests
- **Why**: Before fixing a bug, you need to understand what the code does
- **Concepts**: Unit testing — automated checks that verify your code works...

### Fixing the bug (Steps 4-5)
- **What**: Changed `i <= array.length` to `i < array.length`
- **Why**: Arrays are 0-indexed, so the last valid index is length-1...

## Concepts Explained

### Off-by-one error
- **What it is**: A bug where a loop runs one time too many or too few
- **Analogy**: Like counting floors in a building — if there are 10 floors
  numbered 1-10, and you try to visit floor 11, you'll hit the roof
- **Why it matters**: One of the most common bugs in programming...

Install

git clone https://github.com/koriyoshi2041/cc-learning-hooks.git
cd cc-learning-hooks
./install.sh

Options

# Chinese notes
./install.sh --lang zh

# Custom output directory
./install.sh --output-dir ~/my-learning-notes

# Both
./install.sh --lang zh --output-dir ~/Documents/CC-Notes

Uninstall

./install.sh --uninstall

Requirements

  • Claude Code (CLI)
  • Node.js (v16+)
  • Python 3 (for JSON parsing in hooks)

Configuration

You can override defaults via environment variables in your shell profile:

Variable Default Description
CC_LEARNING_LOG_DIR /tmp/cc-learning Where temp session logs are stored
CC_LEARNING_OUTPUT_DIR ~/Desktop/CC-Learning-Notes Where learning notes are saved
CC_LEARNING_MODEL haiku Claude model for note generation
CC_LEARNING_LANGUAGE en Language: en or zh
CC_LEARNING_MAX_STEPS 40 Max steps to include in prompt

How the hooks work

PostToolUse: Action Logger (log-action.js)

Runs after every tool use (file reads, edits, bash commands, searches, etc.). Receives the tool name and input as JSON on stdin, formats it as a readable markdown entry, and appends it to a per-session log file.

Stop: Notes Generator (generate-learning-notes.sh)

Runs when a Claude Code session ends. Reads the session log, truncates it to the last N steps (to fit within model context), and spawns a background claude -p process to generate learning notes. The background process avoids the hook timeout limit.

Troubleshooting

Notes are empty (0 bytes)

  • Check ~/Desktop/CC-Learning-Notes/.last-error.log for error details
  • The most common cause: the claude CLI isn't in your PATH when hooks run

Notes never appear

  • Verify the hooks are installed: cat ~/.claude/settings.json | grep cc-learning
  • Check if temp logs exist: ls /tmp/cc-learning/
  • The background process may take 30-60 seconds after session end

Notes quality is poor

  • Try using a better model: set CC_LEARNING_MODEL=sonnet (costs more)
  • Reduce CC_LEARNING_MAX_STEPS if sessions are very long

License

MIT

About

Automatically generate beginner-friendly learning notes from your Claude Code sessions. Logs every action, explains what happened and why.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors