# Chat Commands

Simplified command for chatting with LLM agents.

## Basic Usage


```bash
tdx chat <message> [options]
```

## Options

| Option | Description | Default |
|  --- | --- | --- |
| `--agent <name>` | Chat with specific agent (requires `--new`) | default agent |
| `--new` | Start a new chat session | - |


## Examples


```bash
# Simple chat (uses default agent)
tdx chat "Show me the top customers by revenue"

# Continue previous conversation (default behavior)
tdx chat "What about last quarter?"

# Start a new conversation
tdx chat --new "Tell me about data modeling best practices"

# Start new chat with specific agent (--agent requires --new)
tdx chat --new "Analyze churn" --agent "MyProject/Data Analyst"

# Set default agent for all new chats
tdx use agent "MyProject/My Agent"
tdx chat --new "Question 1"
tdx chat "Question 2"  # Continues the chat started above

# Verbose mode shows chat session ID
tdx chat "Hello" --verbose
```

## How It Works

- **Default behavior**: Continues last chat session automatically
- **Session persistence**: Last chat ID saved to `.cache/tdx/last_chat_id`
- **--new flag**: Starts a fresh chat session
- **--agent**: Use specific agent for new chat (requires `--new`, use "Project/Agent" format)
- **Default agent**: Use `tdx use agent <name>` to set a default agent for new chats


### Agent Selection Priority

When starting a new chat, the agent is selected in this order:

1. **`--agent` flag**: Explicitly specified agent (highest priority)
2. **Session agent**: Set via `tdx use agent "Project/Agent"` or `tdx use agent "AgentName"` (uses current llm_project)
3. **Cached default agent**: Previously used default agent
4. **Default haiku agent**: Auto-created default agent with claude-4.5-haiku


### Setting Default Agent


```bash
# Set both project and agent at once
tdx use agent "MyProject/MyAgent"

# Or set project first, then agent name only
tdx use llm_project "MyProject"
tdx use agent "MyAgent"

# Now new chats use this agent automatically
tdx chat --new "Question 1"
tdx chat "Question 2"  # Continues chat with same agent

# Override with --agent for a specific new chat
tdx chat --new "Question 3" --agent "OtherProject/OtherAgent"
```

## Interactive Chat Selector

The `tdx chats` command provides an interactive interface for browsing and resuming chat sessions.

### Usage


```bash
tdx chats [options]
```

### Options

| Option | Description |
|  --- | --- |
| `--last` | Show the most recent chat session |


### Examples


```bash
# Open interactive chat selector
tdx chats

# Show the most recent chat session
tdx chats --last
```

The interactive selector allows you to:

- Browse all your chat sessions
- View chat history
- Resume conversations


## Related Commands

- [LLM Commands](/treasure-code/commands/llm) - Manage projects, agents, and chat history