-
Notifications
You must be signed in to change notification settings - Fork 43
Learn
snip learn mines your agent session history for CLI error-correction patterns: a command that
failed, followed by a corrected version of the same command that succeeded. It turns those pairs into
rules your agent can read, so it stops repeating the same mistake.
Where Gain Dashboard measures tokens saved on output, snip learn targets the other waste: the
round-trips burned re-running a command until it works.
snip learnreads session files only. It never runs a command, and it works in both the full and the-tags litebuild (no SQLite involved).
snip learnScans the current project's sessions over the last 30 days:
snip learn - CLI error pattern analysis
Scanned: 14 sessions, 26 errors with corrections
Common patterns:
git (15 occurrences)
Error: internal/config/config_test.go:1985:6: undefined: reflect -> fixed by /usr/bin/git add internal/config/config.go ...
Error: FAIL -> fixed by /usr/bin/git add internal/cli/cli.go internal/cli/cli_test.g...
go (3 occurrences)
Error: FAIL -> fixed by go test -run TestConfigShowsMergedConfig ./internal/cli/ -v ...
Use --generate to create .claude/rules/cli-corrections.md
Patterns are grouped by base command and sorted by occurrence count, so the noisiest habit shows up first.
| Flag | Description |
|---|---|
--since N |
Scan the last N days (default 30) |
--all |
Scan every project, not just the current working directory |
--generate |
Write the detected patterns to .claude/rules/cli-corrections.md
|
snip learn --since 7 # last week only
snip learn --all # every project in the sessions directory
snip learn --generate # emit the rules file--generate writes a project-relative .claude/rules/cli-corrections.md (it lives with the repo, not
in CLAUDE_CONFIG_DIR), which Claude Code picks up as project context:
# CLI Corrections (auto-generated by snip learn)
## Common patterns detected in your coding sessions
### go failures
- When `go` fails with: FAIL
- Fix: `go test -run TestConfigShowsMergedConfig ./internal/cli/ -v`The file is overwritten on each run. Review it before committing: the detection is heuristic (see below), so prune the noise and keep the corrections that are genuinely worth teaching the agent.
-
Read sessions. Every
.jsonlunder the project's session directory, including nestedsubagents/files. Entries older than the--sincecutoff are skipped. -
Extract Bash commands.
tool_useentries namedBashare paired with theirtool_resultbytool_use_id, keeping session order. -
Drop what never ran. A rejected or interrupted tool call carries
is_error, but nothing executed: such entries are removed entirely, so they are neither a failure nor a candidate fix. -
Flag failures. The
is_errorflag decides when the result carries one, which is nearly always. The marker heuristic (command not found,undefined:,ENOENT,exit status,build failed, ...) is only the fallback for results without the flag, so a command that merely prints an error string is no longer counted as a failure. -
Find the correction. Within the next 5 commands, the first one with the same base command that
succeeded is recorded as the fix. Base command extraction reuses the hook's shell parser and walks past
shell scaffolding, so
/usr/bin/git,env FOO=1 git ...,git ... | grepandcd /path && git ...all normalize togit, andSCRATCH=/tmp/x && python3 ...reportspython3. - Aggregate. Identical failing commands are merged with a count, grouped by base command.
The detection is still a heuristic, and it optimizes for recall:
-
The 5-command window is arbitrary. An unrelated later invocation of the same tool can be picked as
the "fix"; identical error and fix commands are reported as
retrying the same command. - No confidence score. A pattern seen once and a pattern seen twenty times differ only by their count.
- Bash tool only. Commands run outside the agent's Bash tool are invisible.
-
Results without an
is_errorflag fall back to the marker heuristic, which cannot tell a failure from a command that prints the wordFAIL. -
Credentials are copied verbatim. A failing command carrying an inline secret (
PGPASSWORD=..., a connection string) appears as-is in the report and in the generated file.
Treat the report as a shortlist to review, not as ground truth, and always read the generated rules file before committing it.
Filtering out shell scaffolding and trusting the
is_errorflag landed in v0.25.1. On an earlier binary the same sessions producecdand path-fragment groups, and successful commands whose output quotes an error marker are reported as failures.
snip learn reads from CLAUDE_CONFIG_DIR/projects/ (default ~/.claude/projects/), the same source as
snip discover. The current project directory is resolved by mapping the working directory path to
Claude Code's naming scheme (every non-alphanumeric character becomes a dash). See Configuration.
- Gain Dashboard - token savings on filtered output
-
Configuration -
CLAUDE_CONFIG_DIRand other environment variables -
Architecture - where
internal/learn/sits in the pipeline