Skip to content
gitkbPublic

About

Claude Code agent toolkit: guard, score, and more

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

Repository files navigation

agent

Claude Code agent toolkit: guard, score, and more.

A standalone CLI for Claude Code agent integration. Provides deterministic command guards, session scoring, and other agent utilities.

Installation

cargo install --git https://github.com/gitkb/agent

Or build from source:

cargo build --release

Commands

agent guard

Evaluate a command for destructive patterns. Designed to run as a Claude Code PreToolUse hook.

# Test directly
echo '{"tool_input":{"command":"git push --force"}}' | agent guard
# Output: JSON with permissionDecision: "deny" and reason

echo '{"tool_input":{"command":"git status"}}' | agent guard
# Output: (silent = allowed)

Claude Code hook configuration (.claude/settings.json):

{
  "hooks": {
    "PreToolUse": [
      {
        "hooks": [
          {
            "command": "agent guard",
            "timeout": 5,
            "type": "command"
          }
        ],
        "matcher": "Bash"
      }
    ]
  }
}

What it refuses. The guard splits the command line the way a shell does (quotes, ;, &&, |, &, newlines, $(…), backticks, heredocs, ((…)) and $((…)) as opaque arithmetic, case outside $(…), function bodies), unwraps sudo, doas, env (and the words of env -S), nohup, nice, time, timeout, setsid, stdbuf, command, exec, sh -c (also bash, zsh, dash, ksh), eval, find -exec, meta [options] exec and meta [options] git, skips git's global options (git -C dir, -c k=v, --git-dir), and reads options the way git and getopt do: -Df is -D -f, an option's value is not read as flags (-ekeep, -o x), and any unique prefix of a long option counts (--ha is --hard). An option that makes a command safe (--dry-run, --staged) counts only spelled in full or as its letter, and not after its --no-…. When a shell, eval or source appears anywhere in a command, or it runs ., every heredoc and here-string in it is judged as a script, wherever it is piped. So every spelling of these is refused:

Rule id What it blocks Safe alternative
meta.git.force_push git push with -f/--force (even next to --force-with-lease), a +refspec, --mirror, --delete or :branch --force-with-lease on its own
meta.git.reset_hard git reset --hard git stash or commit first; git reflog
meta.git.clean_force git clean with both -f and -d git clean -nd (dry run)
meta.git.checkout_dot git checkout . (any pathspec meaning everything), checkout -f, restore . (except --staged alone), switch -f Specific files
meta.git.branch_force_delete git branch -D, or -d with -f git branch -d
meta.git.stash_drop, meta.git.stash_clear git stash drop / clear git stash list first
meta.rm.dangerous_paths rm -r (with or without -f) of ., .., /, ~, $HOME, *, .*; of .meta, .meta.yaml or .meta.yml; of a path with a .git part (.git/*), where a dot-glob such as .* or .g* counts as both; of a folder holding .git, looked up on disk from the hook's cwd and from every folder a cd or pushd anywhere in the command names (from the cwd or from another such folder; relative paths are not looked up when the payload has no cwd); any rm -r in a command whose cd names a folder it can't know (cd "$DIR", cd $(…), cd -, a glob); find with any argument that has a .git part, in any case (find .git, -iname .GIT), and -delete or -exec rm -r {} Specific paths

Text that only mentions a command (echo "git push --force", a commit message) is not refused. Hook input it cannot read, a Bash call without a command string, a broken policy file and git -c alias.… are refused. So is a command it does not model exactly, with "cannot parse this command": an unclosed quote or heredoc; substitutions, sh -c or find -exec nested deeper than 4 levels; case inside $(…); a quote, backslash, backtick, $(, << or newline inside ((…)) or $((…)) (so $((1<<2)) too); an option it does not know for one of the wrappers above, or a lone - (env - cmd); an env -S string with a quote, a backslash or a leading -, or a second -S; a shell option starting with + (bash +o posix -c …). Because a heredoc is judged as a script whenever a shell appears, one that is not valid shell (prose with an apostrophe) is refused in such a command.

What it can't see. It judges the text of the command, so it is a safety net, not a sandbox. It does not see: values of variables ($cmd, git reset $flag, CDPATH) or strings eval builds at run time; other interpreters (python -c, node -e) and scripts; git aliases stored in config or set through GIT_CONFIG_*; xargs, git submodule foreach, and find -delete on anything but .git; .git deeper than one level below an rm -r target (rm -rf services with services/api/.git); brace expansion in an rm path (rm -rf {.git,x}); symlinks (rm -rf link); a folder changed by env -C, sudo -D/-R or git -C before an rm; stdin that is not a heredoc or here-string (printf … | sh); and the Write, Edit and MCP tools. If the hook's stdout is closed, the deny it writes is lost and the call goes ahead (Rust's standard library treats writing to a closed stdout as success, and the crate forbids unsafe); Claude Code always connects a pipe.

agent score

Score Claude Code sessions for agent effectiveness.

# Score most recent session
agent score

# Score specific session
agent score --session abc123

# Score last 5 sessions
agent score --recent 5

# JSON output
agent score --json

Metrics:

  • Meta-command ratio (using meta git vs bare git)
  • Workspace discovery (running meta context early)
  • Cross-repo awareness (status checks before commits)
  • Guard effectiveness (blocked vs allowed destructive commands)

Configuration

Guard rules

The built-in rules are in the binary. ~/.claude/agent-guard.toml and then the project's .claude/agent-guard.toml change them by id; they never replace them. This file turns one built-in off and adds one rule:

schema_version = "2"

[[rules]]                       # turn a built-in off
id = "meta.git.checkout_dot"
enabled = false

[[rules]]                       # add one
id = "custom.no_tf_destroy"
deny = '^terraform destroy\b'
message = "Run terraform destroy yourself."
  • A built-in id may set only enabled and message.
  • A new id needs deny, a regex matched against each command's words after unwrapping (sudo git -C x push is matched as git push), and message.

A file that exists but cannot be read, is not schema_version = "2" (a schema 1.0 [[patterns]] file must be rewritten as above), has an unknown key, a bad regex, a deny on a built-in id, a repeated id, or a new id without deny and message denies every Bash command, with a reason naming the file, until it is fixed or removed.

Development

# Run tests
cargo test

# Run integration tests (requires bats)
bats tests/

# Build
cargo build

License

MIT

About

Claude Code agent toolkit: guard, score, and more

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages