Skip to content

binpash/try-claude-plugin

Repository files navigation

Try Integration Plugin for Claude Code

A Claude Code plugin that integrates the try tool to provide sandboxed execution of Bash commands with commit/rollback capabilities. All file-modifying commands run in an isolated overlay filesystem, with changes reviewable before committing to your live system.

Features

  • Automatic Sandboxing: All state-modifying Bash commands automatically run through try
  • Session-Based: Single persistent sandbox per Claude Code session
  • Safe Experimentation: Inspect, commit, or rollback changes at session end
  • Manual Controls: /try-commit and /try-status skills for mid-session management
  • Transparent: Minimal changes to your workflow - Claude handles the wrapping

How It Works

The plugin uses Claude Code's hook system and agent configuration to:

  1. SessionStart Hook: Creates a unique sandbox directory when your session begins
  2. System Prompt: Instructs Claude to wrap state-modifying commands with try -n -D <sandbox>
  3. SessionEnd Hook: Prompts you to commit, discard, or inspect accumulated changes

All file modifications are isolated in an overlay filesystem using Linux namespaces and overlayfs. Nothing touches your live system until you explicitly commit.

Prerequisites

  • Linux: Kernel 5.11+ (for overlayfs in user namespaces)
  • Claude Code: Version 2.0.0 or later
  • try tool: Must be installed first

Installation

Step 1: Install try

mkdir -p ~/.local/bin
curl -o ~/.local/bin/try https://raw.githubusercontent.com/binpash/try/main/try
chmod +x ~/.local/bin/try

# Verify installation
try -v

For other installation methods, see the try installation guide.

Step 2: Install the Plugin

Option A: Automated Installation

# Clone the repository
git clone https://github.com/binpash/try-claude-plugin.git
cd try-claude-plugin

# Run the installer
./install.sh

Option B: Manual Installation

  1. Clone the repository:

    git clone https://github.com/binpash/try-claude-plugin.git
  2. Copy hooks:

    mkdir -p ~/.claude/hooks/try-integration
    cp try-claude-plugin/hooks/* ~/.claude/hooks/try-integration/
    chmod +x ~/.claude/hooks/try-integration/*.sh
  3. Copy skills:

    mkdir -p ~/.claude/skills/try-commit ~/.claude/skills/try-status
    cp -r try-claude-plugin/skills/try-commit/* ~/.claude/skills/try-commit/
    cp -r try-claude-plugin/skills/try-status/* ~/.claude/skills/try-status/
    chmod +x ~/.claude/skills/try-commit/*.sh ~/.claude/skills/try-status/*.sh
  4. Update settings:

    # Merge the content from settings.template.json into ~/.claude/settings.json
    # Replace {{PLUGIN_PATH}} with the actual path to hooks

Step 3: Verify Installation

Start a new Claude Code session. You should see:

Try sandbox initialized at: ~/.claude/try-sessions/<session-id>

Usage

During a Session

Claude automatically wraps state-modifying commands:

User: "Create a test file with 'Hello World'"

Claude runs:

try -n -D "~/.claude/try-sessions/<session-id>" "echo 'Hello World' > test.txt"

The file is created in the sandbox overlay, not your live filesystem.

Check Sandbox Status

/try-status

Shows:

  • Sandbox location
  • Pending changes (files added, modified, deleted)

Commit Changes Mid-Session

/try-commit

Prompts to commit accumulated changes and reinitializes a fresh sandbox.

End of Session

When you end your Claude Code session, you'll see:

============================================
  Try Sandbox Session Summary
============================================

Changes detected in the following files:

/home/user/test.txt (added)
/home/user/.config/app/config.json (modified)

============================================

What would you like to do with these changes?
  1) Commit to live filesystem
  2) Discard all changes
  3) Keep sandbox for later inspection

Choice [1/2/3]:
  • Option 1: Apply all changes to your live system
  • Option 2: Discard everything, sandbox is deleted
  • Option 3: Preserve sandbox for manual inspection/commit later

Architecture

Session Start
     ↓
[SessionStart Hook]
     ↓
Initialize Sandbox: ~/.claude/try-sessions/<session-id>
     ↓
[System Prompt Active]
Claude wraps commands: try -n -D <sandbox> "<command>"
     ↓
All changes accumulate in overlay
     ↓
[SessionEnd Hook]
     ↓
Prompt: Commit / Discard / Keep
     ↓
Session End

Configuration

The plugin can be configured in ~/.claude/settings.json:

Customize Sandbox Location

{
  "agents": {
    "main": {
      "systemPromptAppend": "...change ~/.claude/try-sessions to your preferred path..."
    }
  }
}

Adjust Timeouts

{
  "hooks": {
    "SessionEnd": [
      {
        "hooks": [
          {
            "timeout": 300
          }
        ]
      }
    ]
  }
}

Limitations

What This Achieves ✓

  • Automatic sandboxing of Bash commands
  • Session-scoped change tracking
  • User control over commits
  • Mid-session status checks and commits

What This Doesn't Achieve ✗

  • Not enforced at system level: Relies on Claude following system prompt instructions (very high compliance but not guaranteed)
  • Other tools bypass sandbox: Write, Edit, NotebookEdit tools don't use Bash, so they bypass try
  • Network not sandboxed: try limitation - network calls are not isolated
  • UID/GID restrictions: Commands requiring different user permissions will fail (try limitation)
  • Not security-focused: Primary benefit is safety (undo mistakes), not security (prevent attacks)

Troubleshooting

Sandbox Not Created

  • Check if SessionStart hook executed: Look for "Initializing try sandbox..." message
  • Verify hook is executable: ls -l ~/.claude/hooks/try-integration/session-start.sh
  • Check Claude Code logs for errors

Claude Not Wrapping Commands

  • Verify ~/.claude/settings.json has the systemPromptAppend configuration
  • Start a fresh session (system prompt applies at session start)
  • Manually remind Claude: "Remember to use try for this command"

SessionEnd Hook Not Running

  • If session crashes, hook won't run - check for orphaned sandboxes in ~/.claude/try-sessions/
  • Verify timeout is sufficient (default: 120 seconds)

Orphaned Sandboxes

If sessions crash, sandboxes may remain:

# List orphaned sandboxes
ls -lah ~/.claude/try-sessions/

# Manually commit a specific sandbox
try commit ~/.claude/try-sessions/<session-id>

# Or delete old sandboxes
rm -rf ~/.claude/try-sessions/<old-session-id>

Skills Reference

/try-status

Shows current sandbox status and pending changes.

Output:

=== Try Sandbox Status ===

Sandbox Location: /home/user/.claude/try-sessions/abc123

Changes detected in the following files:

/home/user/test.txt (added)
/home/user/config.json (modified)

/try-commit

Manually commits accumulated changes from the sandbox.

Flow:

  1. Shows summary of pending changes
  2. Prompts for confirmation
  3. Applies changes to live system
  4. Clears sandbox and initializes fresh one

Development

Plugin Structure

try-claude-plugin/
├── .claude-plugin/
│   └── marketplace.json      # Plugin metadata
├── hooks/
│   ├── session-start.sh      # Initialize sandbox
│   └── session-end.sh        # Handle commit/discard
├── skills/
│   ├── try-commit/
│   │   ├── SKILL.md
│   │   └── try-commit.sh
│   └── try-status/
│       ├── SKILL.md
│       └── try-status.sh
├── README.md
├── LICENSE
├── CHANGELOG.md
├── settings.template.json    # Settings template
└── install.sh               # Installation script

Testing

  1. Install the plugin
  2. Start a new Claude Code session
  3. Ask Claude to create/modify files
  4. Verify files don't exist in live filesystem
  5. Run /try-status - should show pending changes
  6. End session and test commit/discard options

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

Related Projects

  • try - The underlying sandboxing tool
  • PaSh - Shell script parallelization project

License

MIT License - see LICENSE file for details.

Copyright (c) 2025 The PaSh Authors.

Acknowledgments

  • Built on the excellent try tool from the PaSh project
  • Designed for Claude Code by Anthropic

Support

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages