# cmd_new_session_exec

- **Language:** C
- **Kind:** function
- **Source:** https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L68
- **Page:** https://libtmux.org/en/tmux/latest/reference/c-function-cmd-new-session-c-cmd_new_session_exec/

tmux command: [`has-session`](/en/tmux/latest/manual/has-session/)

tmux command: [`new-session`](/en/tmux/latest/manual/new-session/)

```c
static enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmdq_item *)
```

## Parameters

- `self` (`struct cmd *`)
- `item` (`struct cmdq_item *`)

## Paths through the source

Arrows name source relationships, not a runtime execution order.

### Create a session and its first pane

[`cmd_new_session_exec`](/en/tmux/latest/reference/c-function-cmd-new-session-c-cmd_new_session_exec/) — calls → [`spawn_window`](/en/tmux/latest/reference/c-function-spawn_window/) — calls → [`spawn_pane`](/en/tmux/latest/reference/c-function-spawn_pane/) — calls → [`window_add_pane`](/en/tmux/latest/reference/c-function-window_add_pane/) — calls → [`window_pane_create`](/en/tmux/latest/reference/c-function-window-c-window_pane_create/)

## Calls

- [`args_count`](/en/tmux/latest/reference/c-function-args_count/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L83)
- [`args_first_value`](/en/tmux/latest/reference/c-function-args_first_value/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L284)
- [`args_get`](/en/tmux/latest/reference/c-function-args_get/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L143)
- [`args_has`](/en/tmux/latest/reference/c-function-args_has/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L97)
- [`args_next_value`](/en/tmux/latest/reference/c-function-args_next_value/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L287)
- [`args_to_vector`](/en/tmux/latest/reference/c-function-args_to_vector/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L298)
- [`cfg_show_causes`](/en/tmux/latest/reference/c-function-cfg_show_causes/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L365)
- [`check_name`](/en/tmux/latest/reference/c-function-check_name/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L104)
- [`clean_name`](/en/tmux/latest/reference/c-function-clean_name/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L109)
- [`cmd_attach_session`](/en/tmux/latest/reference/c-function-cmd_attach_session/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L128)
- [`cmd_find_from_session`](/en/tmux/latest/reference/c-function-cmd_find_from_session/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L359)
- [`cmd_free_argv`](/en/tmux/latest/reference/c-function-cmd_free_argv/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L368)
- [`cmd_get_args`](/en/tmux/latest/reference/c-function-cmd_get_args/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L70)
- [`cmd_get_entry`](/en/tmux/latest/reference/c-function-cmd_get_entry/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L89)
- [`cmdq_error`](/en/tmux/latest/reference/c-function-cmdq_error/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L98)
- [`cmdq_get_client`](/en/tmux/latest/reference/c-function-cmdq_get_client/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L73)
- [`cmdq_get_current`](/en/tmux/latest/reference/c-function-cmdq_get_current/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L71)
- [`cmdq_get_target`](/en/tmux/latest/reference/c-function-cmdq_get_target/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L72)
- [`cmdq_insert_hook`](/en/tmux/latest/reference/c-function-cmdq_insert_hook/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L362)
- [`cmdq_print`](/en/tmux/latest/reference/c-function-cmdq_print/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L352)
- [`environ_create`](/en/tmux/latest/reference/c-function-environ_create/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L281)
- [`environ_put`](/en/tmux/latest/reference/c-function-environ_put/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L286)
- [`environ_update`](/en/tmux/latest/reference/c-function-environ_update/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L283)
- [`fatal`](/en/tmux/latest/reference/c-function-fatal/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L201)
- [`format_single`](/en/tmux/latest/reference/c-function-format_single/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L103)
- [`notify_session`](/en/tmux/latest/reference/c-function-notify_session/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L328)
- [`options_create`](/en/tmux/latest/reference/c-function-options_create/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L273)
- [`options_get_string`](/en/tmux/latest/reference/c-function-options_get_string/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L256)
- [`options_set_string`](/en/tmux/latest/reference/c-function-options_set_string/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L279)
- [`proc_send`](/en/tmux/latest/reference/c-function-proc_send/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L339)
- [`server_client_check_nested`](/en/tmux/latest/reference/c-function-server_client_check_nested/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L195)
- [`server_client_open`](/en/tmux/latest/reference/c-function-server_client_open/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L208)
- [`server_client_set_flags`](/en/tmux/latest/reference/c-function-server_client_set_flags/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L336)
- [`server_client_set_key_table`](/en/tmux/latest/reference/c-function-server_client_set_key_table/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L344)
- [`server_client_set_session`](/en/tmux/latest/reference/c-function-server_client_set_session/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L342)
- [`session_create`](/en/tmux/latest/reference/c-function-session_create/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L289)
- [`session_destroy`](/en/tmux/latest/reference/c-function-session_destroy/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L306)
- [`session_find`](/en/tmux/latest/reference/c-function-session_find/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L124)
- [`session_group_add`](/en/tmux/latest/reference/c-function-session_group_add/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L320)
- [`session_group_contains`](/en/tmux/latest/reference/c-function-session_group_contains/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L149)
- [`session_group_find`](/en/tmux/latest/reference/c-function-session_group_find/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L147)
- [`session_group_new`](/en/tmux/latest/reference/c-function-session_group_new/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L319)
- [`session_group_synchronize_to`](/en/tmux/latest/reference/c-function-session_group_synchronize_to/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L325)
- [`session_select`](/en/tmux/latest/reference/c-function-session_select/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L326)
- [`spawn_window`](/en/tmux/latest/reference/c-function-spawn_window/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L305)
- [`strtonum`](/en/tmux/latest/reference/c-function-strtonum/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L224)
- [`xstrdup`](/en/tmux/latest/reference/c-function-xstrdup/) (function) [Call site](https://github.com/tmux/tmux/blob/e476c1230b958df0cb12977517d24b3dc931375b/cmd-new-session.c#L151)

## Other function references

- [`cmdq_get_flags`](/en/tmux/latest/reference/c-function-cmdq_get_flags/) (function)
- [`options_get_number`](/en/tmux/latest/reference/c-function-options_get_number/) (function)
- [`server_client_get_cwd`](/en/tmux/latest/reference/c-function-server_client_get_cwd/) (function)

## Referenced by

- [`cmd_has_session_entry`](/en/tmux/latest/reference/c-variable-cmd_has_session_entry/) (attribute)
- [`cmd_new_session_entry`](/en/tmux/latest/reference/c-variable-cmd_new_session_entry/) (attribute)

## Referenced declarations

- [`spawn_context.argc`](/en/tmux/latest/reference/c-struct-spawn_context-argc/) (attribute)
- [`spawn_context.argv`](/en/tmux/latest/reference/c-struct-spawn_context-argv/) (attribute)
- [`cfg_finished`](/en/tmux/latest/reference/c-variable-cfg_finished/) (attribute)
- [`CLIENT_ATTACHED`](/en/tmux/latest/reference/c-define-tmux-h-client_attached/) (constant)
- [`CLIENT_CONTROL`](/en/tmux/latest/reference/c-define-tmux-h-client_control/) (constant)
- [`cmd`](/en/tmux/latest/reference/c-struct-cmd/) (struct)
- [`cmd_has_session_entry`](/en/tmux/latest/reference/c-variable-cmd_has_session_entry/) (attribute)
- [`CMD_RETURN_ERROR`](/en/tmux/latest/reference/c-enum-cmd_retval-cmd_return_error/) (constant)
- [`CMD_RETURN_NORMAL`](/en/tmux/latest/reference/c-enum-cmd_retval-cmd_return_normal/) (constant)
- [`cmd_retval`](/en/tmux/latest/reference/c-enum-cmd_retval/) (enum)
- [`cmdq_item`](/en/tmux/latest/reference/c-struct-cmdq_item/) (struct)
- [`CMDQ_STATE_REPEAT`](/en/tmux/latest/reference/c-define-tmux-h-cmdq_state_repeat/) (constant)
- [`cmd_find_state.current`](/en/tmux/latest/reference/c-struct-cmd_find_state-current/) (attribute)
- [`session.curw`](/en/tmux/latest/reference/c-struct-session-curw/) (attribute)
- [`spawn_context.cwd`](/en/tmux/latest/reference/c-struct-spawn_context-cwd/) (attribute)
- [`client.environ`](/en/tmux/latest/reference/c-struct-client-environ/) (attribute)
- [`client.fd`](/en/tmux/latest/reference/c-struct-client-fd/) (attribute)
- [`client.flags`](/en/tmux/latest/reference/c-struct-client-flags/) (attribute)
- [`spawn_context.flags`](/en/tmux/latest/reference/c-struct-spawn_context-flags/) (attribute)
- [`global_s_options`](/en/tmux/latest/reference/c-variable-global_s_options/) (attribute)
- [`spawn_context.idx`](/en/tmux/latest/reference/c-struct-spawn_context-idx/) (attribute)
- [`spawn_context.item`](/en/tmux/latest/reference/c-struct-spawn_context-item/) (attribute)
- [`client.last_session`](/en/tmux/latest/reference/c-struct-client-last_session/) (attribute)
- [`MSG_READY`](/en/tmux/latest/reference/c-enum-msgtype-msg_ready/) (constant)
- [`session_group.name`](/en/tmux/latest/reference/c-struct-session_group-name/) (attribute)
- [`session.name`](/en/tmux/latest/reference/c-struct-session-name/) (attribute)
- [`spawn_context.name`](/en/tmux/latest/reference/c-struct-spawn_context-name/) (attribute)
- [`NEW_SESSION_TEMPLATE`](/en/tmux/latest/reference/c-define-cmd-new-session-c-new_session_template/) (constant)
- [`client.peer`](/en/tmux/latest/reference/c-struct-client-peer/) (attribute)
- [`cmd_find_state.s`](/en/tmux/latest/reference/c-struct-cmd_find_state-s/) (attribute)
- [`spawn_context.s`](/en/tmux/latest/reference/c-struct-spawn_context-s/) (attribute)
- [`client.session`](/en/tmux/latest/reference/c-struct-client-session/) (attribute)
- [`tty.sx`](/en/tmux/latest/reference/c-struct-tty-sx/) (attribute)
- [`tty.sy`](/en/tmux/latest/reference/c-struct-tty-sy/) (attribute)
- [`spawn_context.tc`](/en/tmux/latest/reference/c-struct-spawn_context-tc/) (attribute)
- [`client.tty`](/en/tmux/latest/reference/c-struct-client-tty/) (attribute)
- [`session.windows`](/en/tmux/latest/reference/c-struct-session-windows/) (attribute)
