Skip to main content
Glama
LukeLamb

claude-sessions-mcp

new_session

Destructive

Create a new detached tmux session with a unique name, optional initial command, and working directory. Fails if the session name already exists.

Instructions

Start a new detached tmux session. Always starts a shell (so the session survives after the initial command finishes). If command is given, it is sent to the shell as keystrokes + Enter, so aliases, venvs, and functions work as expected. Errors if the session name already exists.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesSession name (unique). Cannot contain ".", ":", "|", or whitespace.
commandNoOptional initial command to run inside the shell (e.g. "cd /path && python train.py").
cwdNoOptional starting working directory for the session.

Implementation Reference

  • The handler function for the 'new_session' tool. It validates the session name, checks for existing session, creates a new detached tmux session (optionally with a cwd), and optionally sends a command via send-keys. Returns session info or an error.
    async function newSession(args) {
      const missing = requireTmux();
      if (missing) return errorResult(missing);
      const bad = validSessionName(args.name);
      if (bad) return errorResult(bad);
    
      // Check for an existing session first — tmux would error with "duplicate
      // session" but the error text varies across versions; our own check is
      // clearer for the caller.
      const existing = await run(BIN.tmux, ['has-session', '-t', `=${args.name}`]);
      if (existing.code === 0) {
        return errorResult(`session "${args.name}" already exists. Use kill_session first or pick a different name.`);
      }
    
      // Always start a shell (no explicit command arg) so the session survives
      // after the initial command finishes. If `command` is provided, send it as
      // keystrokes so it runs inside the shell — respecting aliases, venvs,
      // functions, etc.
      const createArgs = ['new-session', '-d', '-s', args.name];
      if (args.cwd && typeof args.cwd === 'string') {
        createArgs.push('-c', args.cwd);
      }
      const created = await run(BIN.tmux, createArgs);
      if (created.code !== 0) {
        return errorResult(`tmux new-session failed: ${created.stderr || created.stdout}`);
      }
    
      if (args.command && typeof args.command === 'string' && args.command.trim()) {
        const r = await run(BIN.tmux, ['send-keys', '-t', `=${args.name}:`, args.command, 'Enter']);
        if (r.code !== 0) {
          return errorResult(`session created, but send-keys failed: ${r.stderr || r.stdout}`);
        }
      }
    
      return textResult({
        name: args.name,
        cwd: args.cwd || null,
        command: args.command || null,
        status: 'running',
        hint: `Use capture_pane name="${args.name}" to check output; tmux attach -t "${args.name}" from a real terminal to watch live.`,
      });
    }
  • The tool schema/registration entry for 'new_session' in the TOOLS array. Defines name, description, annotations, and inputSchema (properties: name, command, cwd; required: name).
    {
      name: 'new_session',
      description: 'Start a new detached tmux session. Always starts a shell (so the session survives after the initial command finishes). If `command` is given, it is sent to the shell as keystrokes + Enter, so aliases, venvs, and functions work as expected. Errors if the session name already exists.',
      annotations: { title: 'Start tmux session', readOnlyHint: false, destructiveHint: true, openWorldHint: true },
      inputSchema: {
        type: 'object',
        properties: {
          name: { type: 'string', description: 'Session name (unique). Cannot contain ".", ":", "|", or whitespace.' },
          command: { type: 'string', description: 'Optional initial command to run inside the shell (e.g. "cd /path && python train.py").' },
          cwd: { type: 'string', description: 'Optional starting working directory for the session.' },
        },
        required: ['name'],
        additionalProperties: false,
      },
    },
  • server.js:326-334 (registration)
    The HANDLERS map that registers the 'new_session' tool name to the newSession handler function, used for dispatch in tools/call.
    const HANDLERS = {
      list_sessions: listSessions,
      has_session: hasSession,
      list_windows: listWindows,
      capture_pane: capturePane,
      new_session: newSession,
      send_keys: sendKeys,
      kill_session: killSession,
    };
  • The validSessionName helper function used by new_session to validate the session name (no '.', ':', '|', or whitespace, max 100 chars).
    function validSessionName(name) {
      if (typeof name !== 'string' || !name.length) return 'name is required (non-empty string)';
      if (name.length > 100) return 'name too long (max 100)';
      if (/[.:\s|]/.test(name)) return "name cannot contain '.', ':', '|', or whitespace";
      return null;
    }
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Adds significant behavioral details beyond annotations: detached, always starts shell, command sent as keystrokes enabling aliases, errors on duplicate name. No contradictions.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three sentences with no waste. First sentence states purpose, second explains key behavior, third clarifies command detail and error condition. Front-loaded and efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers purpose, behavior, error conditions, and parameter semantics. No output schema needed. Complete for a creation tool with 3 parameters.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline is 3. Description adds key nuance: command is sent as keystrokes + Enter, preserving aliases and venvs. This raises the score.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool starts a new detached tmux session, which is a specific verb + resource. It distinguishes from siblings like 'kill_session' by focusing on creation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Describes when to use (to start a session) and conditions: always starts a shell, errors if name exists. No explicit comparison to alternatives, but context is clear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/LukeLamb/claude-sessions-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server