|
| 1 | +# Dynamic Project Switching |
| 2 | + |
| 3 | +CTX allows you to manage multiple projects and seamlessly switch between them. |
| 4 | + |
| 5 | +> **Note**: After switching projects, you may need to restart MCP clients (like Claude) to ensure they |
| 6 | +> recognize the new context. |
| 7 | +
|
| 8 | +**This feature is especially valuable for developers who:** |
| 9 | + |
| 10 | +- Work on multiple projects simultaneously |
| 11 | +- Need to provide context from different codebases to AI assistants |
| 12 | +- Want to maintain separate configurations for different projects |
| 13 | + |
| 14 | +## Using Dynamic Project Switching |
| 15 | + |
| 16 | +With Project Switching, you can start the MCP server without specifying a project path: |
| 17 | + |
| 18 | +```bash |
| 19 | +ctx server |
| 20 | +``` |
| 21 | + |
| 22 | +When the `-c` option is omitted, CTX will use the globally registered projects configuration. This means: |
| 23 | + |
| 24 | +1. The server starts with the currently active project (if one is set) |
| 25 | +2. You can switch between registered projects using console commands |
| 26 | +3. AI assistants like Claude will always have access to the current project context |
| 27 | + |
| 28 | +## Project Management Commands |
| 29 | + |
| 30 | +CTX provides several commands for managing your projects: |
| 31 | + |
| 32 | +## Adding a Project (`project:add`) |
| 33 | + |
| 34 | +Register a new project with the system: |
| 35 | + |
| 36 | +```bash |
| 37 | +ctx project:add <path> [--name=<alias>] [--config-file=<path>] [--env-file=<path>] |
| 38 | +``` |
| 39 | + |
| 40 | +**Example:** |
| 41 | + |
| 42 | +The easiest way to add a project is to run the command from the project directory: |
| 43 | + |
| 44 | +```bash |
| 45 | +ctx project:add . --name=my-backend |
| 46 | +``` |
| 47 | + |
| 48 | +If you want to specify environment variables for the project, you can do so with the `--env-file` option: |
| 49 | + |
| 50 | +```bash |
| 51 | +ctx project:add . --name=my-backend --env-file=.env.dev |
| 52 | +``` |
| 53 | + |
| 54 | +**Arguments:** |
| 55 | + |
| 56 | +- `path`: Path to the project directory. Use `.` for current directory. |
| 57 | + |
| 58 | +**Options:** |
| 59 | + |
| 60 | +- `--name`: Alias name for the project (optional) |
| 61 | +- `--config-file` or `-c`: Path to custom configuration file within the project (optional) |
| 62 | +- `--env-file` or `-e`: Path to .env file within the project (optional) |
| 63 | + |
| 64 | +## Switching Between Projects (`project`) |
| 65 | + |
| 66 | +Switch to a different registered project: |
| 67 | + |
| 68 | +```bash |
| 69 | +ctx project [<path_or_alias>] |
| 70 | +``` |
| 71 | + |
| 72 | +**Arguments:** |
| 73 | + |
| 74 | +- `path_or_alias`: Path or alias to the project (optional). If omitted, displays an interactive selection menu. |
| 75 | + |
| 76 | +**Example:** |
| 77 | + |
| 78 | +Switch to a project using its alias: |
| 79 | + |
| 80 | +```bash |
| 81 | +ctx project my-backend |
| 82 | +``` |
| 83 | + |
| 84 | +or switch to a project using its path: |
| 85 | + |
| 86 | +```bash |
| 87 | +ctx project . |
| 88 | +``` |
| 89 | + |
| 90 | +or you can omit the argument to see a list of all registered projects: |
| 91 | + |
| 92 | +```bash |
| 93 | +ctx project |
| 94 | +``` |
| 95 | + |
| 96 | +### Listing Projects (`project:list` or `projects`) |
| 97 | + |
| 98 | +View all registered projects: |
| 99 | + |
| 100 | +```bash |
| 101 | +ctx project:list |
| 102 | +``` |
| 103 | + |
| 104 | +**Example output:** |
| 105 | + |
| 106 | +``` |
| 107 | +┌─────────────────────────────┬────────────────────┬──────────┬─────────────────┬─────────────────┬─────────┐ |
| 108 | +│ Path │ Config File │ Env File │ Aliases │ Added │ Current │ |
| 109 | +├─────────────────────────────┼────────────────────┼──────────┼─────────────────┼─────────────────┼─────────┤ |
| 110 | +│ /home/user/projects/my-app │ │ │ my-app │ 2025-05-01 10:15│ │ |
| 111 | +├─────────────────────────────┼────────────────────┼──────────┼─────────────────┼─────────────────┼─────────┤ |
| 112 | +│ /home/user/projects/backend │ custom-context.yaml│ .env.dev │ my-backend, │ 2025-05-01 14:30│ active │ |
| 113 | +│ │ │ │ backend │ │ │ |
| 114 | +├─────────────────────────────┼────────────────────┼──────────┼─────────────────┼─────────────────┼─────────┤ |
| 115 | +│ /home/user/projects/frontend│ │ │ my-ui │ 2025-05-02 09:45│ │ |
| 116 | +└─────────────────────────────┴────────────────────┴──────────┴─────────────────┴─────────────────┴─────────┘ |
| 117 | +``` |
| 118 | + |
| 119 | +## Configuring MCP Server for Project Switching |
| 120 | + |
| 121 | +In your Claude app configuration, set up the MCP Server without specifying a project path: |
| 122 | + |
| 123 | +### Linux Configuration |
| 124 | + |
| 125 | +```json |
| 126 | +{ |
| 127 | + "mcpServers": { |
| 128 | + "ctx": { |
| 129 | + "command": "ctx", |
| 130 | + "args": [ |
| 131 | + "server" |
| 132 | + ] |
| 133 | + } |
| 134 | + } |
| 135 | +} |
| 136 | +``` |
| 137 | + |
| 138 | +### Windows Configuration |
| 139 | + |
| 140 | +```json |
| 141 | +{ |
| 142 | + "mcpServers": { |
| 143 | + "ctx": { |
| 144 | + "command": "C:\\ctx.exe", |
| 145 | + "args": [ |
| 146 | + "server" |
| 147 | + ] |
| 148 | + } |
| 149 | + } |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +### Windows with WSL Configuration |
| 154 | + |
| 155 | +```json |
| 156 | +{ |
| 157 | + "mcpServers": { |
| 158 | + "ctx": { |
| 159 | + "command": "bash.exe", |
| 160 | + "args": [ |
| 161 | + "-c", |
| 162 | + "ctx server" |
| 163 | + ] |
| 164 | + } |
| 165 | + } |
| 166 | +} |
| 167 | +``` |
| 168 | + |
| 169 | +This configuration allows the MCP server to automatically use the currently active project from your project registry |
| 170 | +without requiring a specific path at startup time. |
0 commit comments