Odin-claude-plugin srgn-cli
Practical guide for building safe, syntax-aware srgn CLI commands for source-code search and transformation. Use when users ask for srgn commands, scoped refactors (comments/docstrings/imports/functions), multi-file rewrites with --glob, custom tree-sitter query usage, or CI-style checks with --fail-any/--fail-none.
install
source · Clone the upstream repo
git clone https://github.com/OutlineDriven/odin-claude-plugin
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/OutlineDriven/odin-claude-plugin "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/srgn-cli" ~/.claude/skills/outlinedriven-odin-claude-plugin-srgn-cli && rm -rf "$T"
manifest:
skills/srgn-cli/SKILL.mdsource content
srgn CLI
Overview
Use this skill to convert user intent into precise
srgn commands with safe defaults.
Focus on CLI workflows for search, transformation, scoped migrations, and lint-like checks.
Workflow Decision Tree
- Classify the request.
- Search only: no content changes expected.
- Transform in stream: stdin/stdout pipeline usage.
- Transform files: in-place updates over globs.
- Identify scope strategy.
- Regex scope only.
- Language scope only.
- Combined language + regex scope.
- Custom tree-sitter query scope.
- Identify action strategy.
- Replacement (positional replacement argument after
).-- - Composable actions (
,--upper
,--lower
,--titlecase
,--normalize
,--symbols
).--german - Standalone actions (
,-d
).-s
- Replacement (positional replacement argument after
- Apply safety controls.
- Prefer
for file operations.--dry-run - Keep globs quoted.
- Add
when missing files should fail CI.--fail-no-files
- Prefer
- Choose output mode.
- Human-readable (default tty).
- Machine-readable (
).--stdout-detection force-pipe
- Validate behavior.
- Confirm expected match count.
- Confirm no out-of-scope edits.
- Re-run with stricter scope if needed.
Safety Protocol
- Default to non-destructive behavior first.
- Prefer stdin-based or search-mode examples before in-place rewrites.
- For file edits, require preview path.
- Use
first.--dry-run - Then run the same command without
only after confirmation.--dry-run
- Use
- Protect shell parsing boundaries.
- Quote regex.
- Quote globs:
.--glob '**/*.py' - Use
before replacement values.--
accepts exactly one pattern (cannot repeat).--glob- Glob syntax:
,*
,?
,[...]
only. No**
brace expansion.{a,b} - For multiple files: broader glob +
, or per-file via--dry-run
(CWD only—no [path] arg):fdfd -e <ext> --strip-cwd-prefix -x srgn --glob '{}' --stdin-detection force-unreadable [OPTIONS] [PATTERN]
- Glob syntax:
- Use the narrowest scope that solves the task.
- Prefer language scope + anchored regex over broad regex-only replacement.
- Treat
and-d
as high-risk operations.-s- Always provide explicit scope for them.
Command Construction Template
Use this template when building commands:
srgn [LANGUAGE_SCOPE_FLAGS...] [GLOBAL_FLAGS...] [ACTION_FLAGS...] [SCOPE_REGEX] -- [REPLACEMENT]
Build incrementally:
- Scope first.
- Example:
--python 'imports'
- Example:
- Regex filter second.
- Example:
'^old_pkg'
- Example:
- Action third.
- Replacement:
-- 'new_pkg' - Or composable flag:
--upper
- Replacement:
- File mode flags fourth (if needed).
--glob '**/*.py' --dry-run
- CI behavior last.
or--fail-any--fail-none
High-Value Task Recipes
- Rename module imports in Python only:
srgn --python 'imports' '^old_pkg' --glob '**/*.py' --dry-run -- 'new_pkg'
- Convert
calls to logging in Python call-sites only:print
srgn --python 'function-calls' '^print$' --glob '**/*.py' --dry-run -- 'logging.info'
- Rename Rust
prefixes without touching strings/comments:use
srgn --rust 'uses' '^good_company' --glob '**/*.rs' --dry-run -- 'better_company'
- Remove C# comments only:
srgn --csharp 'comments' -d '.*'
- Search for Rust
language keyword usage only:unsafe
srgn --rust 'unsafe'
- Fail CI if undesirable pattern appears in Python docstrings:
srgn --python 'doc-strings' --fail-any 'param.+type'
- Force machine-readable output for downstream parsers:
srgn --python 'strings' --stdout-detection force-pipe '(foo|bar)'
- Preview multi-file changes with deterministic ordering:
srgn --typescript 'imports' '^legacy-lib' --glob 'src/**/*.ts' --sorted --dry-run -- 'modern-lib'
For broader, categorized examples, load
references/cli-cookbook.md.
Failure and Debug Playbook
- No matches when matches are expected.
- Verify language scope and prepared query name.
- Remove regex temporarily to test scope alone.
- Add
to inspect exact matched columns.--stdout-detection force-pipe
- Too many matches.
- Anchor regex (
) where possible.^...$ - Narrow from generic language scope to a specific prepared query.
- Anchor regex (
- Wrong files targeted.
- Confirm
pattern and shell quoting.--glob - Add
in CI to catch empty globs.--fail-no-files
- Confirm
used multiple times.--glob
is a single-value argument; cannot repeat.--glob- Broader glob +
, or per-file (CWD only—no [path] arg):--dry-runfd -e <ext> --strip-cwd-prefix -x srgn --glob '{}' --stdin-detection force-unreadable [OPTIONS] [PATTERN]
- Unclear behavior across multiple language scopes.
- Default is intersection (left-to-right narrowing).
- Use
for OR behavior.-j
- Special characters misinterpreted as regex.
- Use
when literal matching is intended.--literal-string
- Use
Reference Loading Guide
Load reference files based on request type:
references/cli-cookbook.md- Load for routine command construction and practical recipes.
references/language-scopes.md- Load for prepared query selection by language.
references/advanced-patterns.md- Load for custom queries, capture substitutions, join semantics, and CI failure modes.
references/deepwiki-recursive-notes.md- Load for complete DeepWiki-derived background and architecture context.
Intent-to-Command Map
Use this map to respond quickly:
- "Rename imports safely"
- Use language import scope + anchored regex +
.--glob ... --dry-run
- Use language import scope + anchored regex +
- "Update function calls only"
- Use language call-site scope (for example
) + exact name regex.--python 'function-calls'
- Use language call-site scope (for example
- "Only comments/docstrings"
- Use prepared comment/docstring scopes, add
only when OR semantics are required.-j
- Use prepared comment/docstring scopes, add
- "CI should fail if pattern appears"
- Use scoped search +
.--fail-any
- Use scoped search +
- "CI should fail if required pattern is missing"
- Use scoped search +
.--fail-none
- Use scoped search +
- "I need parseable output"
- Use
.--stdout-detection force-pipe
- Use
- "Regex escaping is painful"
- Use
and explicit replacement via--literal-string
.--
- Use
Execution Checklist
Before returning a final command, verify:
- Scope is minimal and syntax-aware where possible.
- Replacement argument is after
(if replacement is used).-- - Globs are quoted.
is present for file edits unless user requested direct apply.--dry-run- Join semantics are explicit when multiple language scopes are used (
vs default intersect).-j - Failure flags align with user intent (
,--fail-any
,--fail-none
).--fail-no-files - Output mode is explicit if user needs machine parsing.